Skip to content

Commit

Permalink
test: resolve .signIn() and .signOut() with .profile
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 25, 2016
1 parent 0c07796 commit 1577b27
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 19 deletions.
8 changes: 8 additions & 0 deletions test/fixtures/signin.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
}
}
}
},
{
"id": "abc4567-profile",
"type": "profile",
"attributes": {
"fullName": "Docs Chicken",
"favoriteClothing": "Hoodie"
}
}
]
}
2 changes: 1 addition & 1 deletion test/integration/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('account.signIn() with invalid credentials', function (t) {
})

nock('http://localhost:3000')
.put('/session')
.put('/session?include=account.profile')
.reply(401, sessionUnauthorizedResponse)

account.signIn({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/cachekey-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('new Account(options) defaults to "account" cacheKey', function (t) {
})

nock('http://localhost:3000')
.put('/session')
.put('/session?include=account.profile')
.reply(201, JSON.stringify(signInResponse))

return account.signIn({
Expand Down
8 changes: 5 additions & 3 deletions test/integration/destroy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('destroy account', function (t) {
})

nock(baseURL)
.put('/session')
.put('/session?include=account.profile')
.reply(201, signInResponse)
.delete('/session/account')
.reply(204)
Expand All @@ -46,13 +46,15 @@ test('destroy account', function (t) {
t.deepEqual(signOutHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: { favoriteClothing: 'Hoodie', fullName: 'Docs Chicken' }
}, '"signout" event emitted with account object')

t.deepEqual(destroyHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: { favoriteClothing: 'Hoodie', fullName: 'Docs Chicken' }
}, '"destroy" event emitted with account object')

t.is(signOutHandler.callCount, 1, '"signout" event emitted once')
Expand Down
11 changes: 7 additions & 4 deletions test/integration/events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 +71,8 @@ test('events', function (t) {
t.deepEqual(signInHandler.lastCall.arg, {
id: 'abc4567',
username: '[email protected]',
session: { id: 'sessionid123' }
session: { id: 'sessionid123' },
profile: { favoriteClothing: 'Hoodie', fullName: 'Docs Chicken' }
}, '"signin" event emitted with account object')

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

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

t.is(signUpHandler.callCount, 1, '"signup" event emitted once')
Expand Down
4 changes: 2 additions & 2 deletions test/integration/hooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sign in with pre & post hooks', function (t) {
t.plan(2)

nock(baseURL)
.put('/session')
.put('/session?include=account.profile')
.reply(201, signInResponse)

var callOrder = []
Expand Down Expand Up @@ -94,7 +94,7 @@ test('sign in with throw in post hook', function (t) {
t.plan(2)

nock(baseURL)
.put('/session')
.put('/session?include=account.profile')
.reply(201, signInResponse)

var account = new Account({
Expand Down
13 changes: 11 additions & 2 deletions test/integration/sign-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ var options = {

test('sign in', function (t) {
store.clear()
t.plan(11)
t.plan(12)

var account = new Account({
url: baseURL,
id: 'abc4567'
})

nock(baseURL)
.put('/session')
.put('/session?include=account.profile')
.reply(201, signInResponse)

.delete('/session')
Expand All @@ -43,13 +43,21 @@ test('sign in', function (t) {
username: '[email protected]',
session: {
id: 'sessionid123'
},
profile: {
fullName: 'Docs Chicken',
favoriteClothing: 'Hoodie'
}
}, 'stores account with id with session')
t.deepEqual(account.get(), {
id: 'abc4567',
username: '[email protected]',
session: {
id: 'sessionid123'
},
profile: {
fullName: 'Docs Chicken',
favoriteClothing: 'Hoodie'
}
}, '.get() returns account with session')

Expand All @@ -60,6 +68,7 @@ test('sign in', function (t) {
t.pass('signes out')

t.is(signOutResult.username, '[email protected]')
t.is(signOutResult.profile.fullName, 'Docs Chicken')

var storeAccount = store.getObject('account')

Expand Down
4 changes: 2 additions & 2 deletions test/integration/update-account-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('sign in and change username', function (t) {
})

nock(baseURL)
.put('/session', function (body) {
.put('/session?include=account.profile', function (body) {
return body.data.attributes.password === 'secret'
})
.reply(201, signInResponse)
Expand All @@ -40,7 +40,7 @@ test('sign in and change username', function (t) {
return true
})
.reply(200, updateResponse)
.put('/session', function (body) {
.put('/session?include=account.profile', function (body) {
return body.data.attributes.password === 'newsecret'
})
.thrice()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/update-profile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('sign in and change username', function (t) {
})

nock(baseURL)
.put('/session', function (body) {
.put('/session?include=account.profile', function (body) {
return body.data.attributes.password === 'secret'
})
.reply(201, signInResponse)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sign-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test('successful account.signIn(options)', function (t) {
.then(function (accountProperties) {
t.deepEqual(signIn.internals.request.lastCall.arg, {
method: 'PUT',
url: 'http://example.com/session',
url: 'http://example.com/session?include=account.profile',
body: 'serialised'
})
t.deepEqual(signIn.internals.deserialise.lastCall.arg, 'response body')
Expand Down
8 changes: 6 additions & 2 deletions test/unit/sign-out-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var test = require('tape')
var signOut = require('../../lib/sign-out')

test('signOut()', function (t) {
t.plan(3)
t.plan(4)

simple.mock(signOut.internals, 'request').resolveWith({
statusCode: 204,
Expand All @@ -19,7 +19,10 @@ test('signOut()', function (t) {
session: {
id: 'abc4567'
},
username: 'pat'
username: 'pat',
profile: {
foo: 'bar'
}
},
emitter: {
emit: simple.stub()
Expand All @@ -41,6 +44,7 @@ test('signOut()', function (t) {
})

t.is(state.account, undefined, 'unsets account')
t.is(result.profile.foo, 'bar', 'resolves with .profile')

simple.restore()
})
Expand Down

0 comments on commit 1577b27

Please sign in to comment.