Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept for account profiles. #98

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/sign-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ function signIn (state, options) {

.then(function () {
return internals.request({
url: state.url + '/session',
url: state.url + '/session' + query(options),
method: 'PUT',
body: internals.serialise('session', options)
})
})

.then(function (response) {
var data = internals.deserialise(response.body, {
include: 'account'
include: 'account.profile'
})

// admins don’t have an account
Expand All @@ -65,6 +65,10 @@ function signIn (state, options) {
state.account.id = data.account.id
}

if (options.include === 'account.profile') {
state.account.profile = data.account.profile || {}
}

internals.saveAccount({
cacheKey: state.cacheKey,
account: state.account
Expand All @@ -90,3 +94,11 @@ function signIn (state, options) {
})
})
}

function query (options) {
if (!options || options.include !== 'account.profile') {
return ''
}

return '?include=account.profile'
}
4 changes: 0 additions & 4 deletions lib/sign-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ function signUp (state, options) {
return Promise.reject(error)
}

if (options.profile) {
return Promise.reject(new Error('SignUp with profile data not yet implemented. Please see https://github.com/hoodiehq/hoodie-account-client/issues/11.'))
}

return internals.request({
url: state.url + '/session/account',
method: 'PUT',
Expand Down
14 changes: 9 additions & 5 deletions test/integration/events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var signInResponse = require('../fixtures/signin.json')
var updateResponse = require('../fixtures/update.json')
var options = {
username: signUpResponse.data.attributes.username,
password: 'secret'
password: 'secret',
include: 'account.profile'
}

test('events', function (t) {
Expand All @@ -24,7 +25,7 @@ test('events', function (t) {
nock(baseURL)
.put('/session/account')
.reply(201, signUpResponse)
.put('/session').thrice()
.put('/session?include=account.profile').thrice()
.reply(201, signInResponse)
.patch('/session/account')
.reply(201, updateResponse)
Expand Down Expand Up @@ -71,7 +72,8 @@ test('events', function (t) {
t.deepEqual(signInHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: {}
}, '"signin" event emitted with account object')

return account.update({username: updateResponse.data.attributes.username})
Expand All @@ -86,7 +88,8 @@ test('events', function (t) {
t.deepEqual(updateHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: {}
}, '"update" event emitted with account object')

return account.signOut()
Expand All @@ -96,7 +99,8 @@ test('events', function (t) {
t.deepEqual(signOutHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: {}
}, '"signout" event emitted with account object')

t.is(signUpHandler.callCount, 1, '"signup" event emitted once')
Expand Down
9 changes: 6 additions & 3 deletions test/integration/sign-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var signInResponse = clone(require('../fixtures/signin.json'))

var options = {
username: '[email protected]',
password: 'secret'
password: 'secret',
include: 'account.profile'
}

test('sign in', function (t) {
Expand Down Expand Up @@ -43,14 +44,16 @@ test('sign in', function (t) {
username: '[email protected]',
session: {
id: 'sessionid123'
}
},
profile: {}
}, 'stores account with id with session')
t.deepEqual(account.get(), {
id: 'abc4567',
username: '[email protected]',
session: {
id: 'sessionid123'
}
},
profile: {}
}, '.get() returns account with session')

return account.signOut()
Expand Down