Closed matthewlanders closed 6 years ago
I would create a new file: test/integration/admin-account-session-test.js
. admin-sessions-test.js
is for testing sessions for admins themselves, while the issue at hand is about an admin creating a session for a normal user.
You can create a test that looks more or less like this
test('admin creates user session', function (t) {
// simulate signed in admin
store.setObject('account_admin', {
username: 'patmin',
session: {
id: 'abc4567'
}
})
var admin = new AccountAdmin({
url: 'http://localhost:3000'
})
admin.sessions.add({username: 'foo'})
.then(function (session) {
t.is(session.id, 'usersession123')
t.end()
})
})
And then you’d need to mock the requests
GET /accounts
for the initial fetch all requestPOST /accounts/{id}/sessions
for the session creation accountI would mock GET /accounts
to return only one account with username foo
and an id like user123
, so that you can then mock POST /accounts/123/sessions
which returns a session with usersession123
as its id, so the test above would succeed.
Does that all make sense?
Of course, loading all accounts with GET /accounts
and filtering locally is only a temporary solution, but we’ll get there, let’s do this first :)
test for hoodiehq/camp#11