Skip to content

Commit

Permalink
Merge a6d6107 into cef4d25
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 24, 2017
2 parents cef4d25 + a6d6107 commit ee7a0e1
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion test/unit/sign-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('signIn without username', function (t) {
})
})

test('successful account.signIn(options)', function (t) {
test('sgnIn with username & password', function (t) {
t.plan(6)

var state = {
Expand Down Expand Up @@ -105,6 +105,63 @@ test('successful account.signIn(options)', function (t) {
.catch(t.error)
})

test('signIn with token', function (t) {
t.plan(6)

var state = {
hook: hookMock,
ready: Promise.resolve(),
url: 'http://example.com',
cacheKey: 'cacheKey123',
emitter: {
emit: simple.stub()
},
cache: {
set: simple.stub()
}
}

simple.mock(signIn.internals, 'request').resolveWith({
body: 'response body'
})
simple.mock(signIn.internals, 'serialise').returnWith('serialised')
simple.mock(signIn.internals, 'deserialise').returnWith({
id: 'Session123',
account: {
id: 'deserialise id',
username: 'deserialise username'
}
})

signIn(state, {
token: 'token123'
})

.then(function (accountProperties) {
t.deepEqual(signIn.internals.request.lastCall.arg, {
method: 'PUT',
url: 'http://example.com/session',
body: 'serialised'
})
t.deepEqual(signIn.internals.deserialise.lastCall.arg, 'response body')
t.deepEqual(state.cache.set.lastCall.arg, {
session: {
id: 'Session123'
},
id: 'deserialise id',
username: 'deserialise username'
})

t.assert(accountProperties, 'resolves with account object')
t.equal(accountProperties.id, 'deserialise id', 'resolves with account.id')
t.equal(accountProperties.username, 'deserialise username', 'resolves with account.username')

simple.restore()
})

.catch(t.error)
})

test('signIn with request error', function (t) {
t.plan(1)

Expand Down

0 comments on commit ee7a0e1

Please sign in to comment.