hoodiehq / hoodie-account-client

:dog: Account client API for the browser
https://hoodiehq.github.io/hoodie-account-client
Apache License 2.0
11 stars 24 forks source link

test: admin.sessions.add({username}) fails with "Not Found" #123

Closed matthewlanders closed 6 years ago

matthewlanders commented 7 years ago

test for hoodiehq/camp#11

gr2m commented 7 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

I 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 :)