diff --git a/lib/sign-in.js b/lib/sign-in.js index d9816f5..c4407ac 100644 --- a/lib/sign-in.js +++ b/lib/sign-in.js @@ -30,7 +30,7 @@ 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) }) @@ -38,7 +38,7 @@ function signIn (state, options) { .then(function (response) { var data = internals.deserialise(response.body, { - include: 'account' + include: 'account.profile' }) // admins don’t have an account @@ -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 @@ -90,3 +94,11 @@ function signIn (state, options) { }) }) } + +function query (options) { + if (!options || options.include !== 'account.profile') { + return '' + } + + return '?include=account.profile' +} diff --git a/lib/sign-up.js b/lib/sign-up.js index 8842249..ceb64d1 100644 --- a/lib/sign-up.js +++ b/lib/sign-up.js @@ -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', diff --git a/test/integration/events-test.js b/test/integration/events-test.js index 2207fbf..6bbf682 100644 --- a/test/integration/events-test.js +++ b/test/integration/events-test.js @@ -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) { @@ -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) @@ -71,7 +72,8 @@ test('events', function (t) { t.deepEqual(signInHandler.lastCall.arg, { id: 'abc4567', username: 'chicken@docs.com', - session: { id: 'sessionid123' } + session: { id: 'sessionid123' }, + profile: {} }, '"signin" event emitted with account object') return account.update({username: updateResponse.data.attributes.username}) @@ -86,7 +88,8 @@ test('events', function (t) { t.deepEqual(updateHandler.lastCall.arg, { id: 'abc4567', username: 'newchicken@docs.com', - session: { id: 'sessionid123' } + session: { id: 'sessionid123' }, + profile: {} }, '"update" event emitted with account object') return account.signOut() @@ -96,7 +99,8 @@ test('events', function (t) { t.deepEqual(signOutHandler.lastCall.arg, { id: 'abc4567', username: 'newchicken@docs.com', - session: { id: 'sessionid123' } + session: { id: 'sessionid123' }, + profile: {} }, '"signout" event emitted with account object') t.is(signUpHandler.callCount, 1, '"signup" event emitted once') diff --git a/test/integration/sign-in-test.js b/test/integration/sign-in-test.js index 109cadb..de36bda 100644 --- a/test/integration/sign-in-test.js +++ b/test/integration/sign-in-test.js @@ -11,7 +11,8 @@ var signInResponse = clone(require('../fixtures/signin.json')) var options = { username: 'chicken@docs.com', - password: 'secret' + password: 'secret', + include: 'account.profile' } test('sign in', function (t) { @@ -43,14 +44,16 @@ test('sign in', function (t) { username: 'chicken@docs.com', session: { id: 'sessionid123' - } + }, + profile: {} }, 'stores account with id with session') t.deepEqual(account.get(), { id: 'abc4567', username: 'chicken@docs.com', session: { id: 'sessionid123' - } + }, + profile: {} }, '.get() returns account with session') return account.signOut()