AuthenticationTests.js 990 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const { expect } = require('chai')
  2. const { ObjectId } = require('mongodb')
  3. const User = require('./helpers/User').promises
  4. describe('Authentication', function() {
  5. let user
  6. beforeEach('init vars', function() {
  7. user = new User()
  8. })
  9. describe('login', function() {
  10. beforeEach('doLogin', async function() {
  11. await user.login()
  12. })
  13. it('should log the user in', async function() {
  14. const {
  15. response: { statusCode }
  16. } = await user.doRequest('GET', '/project')
  17. expect(statusCode).to.equal(200)
  18. })
  19. it('should emit an user auditLog entry for the login', async function() {
  20. const {
  21. auditLog: [auditLogEntry]
  22. } = await user.get()
  23. expect(auditLogEntry).to.exist
  24. expect(auditLogEntry.timestamp).to.exist
  25. delete auditLogEntry.timestamp
  26. expect(auditLogEntry).to.deep.equal({
  27. operation: 'login',
  28. ipAddress: '127.0.0.1',
  29. initiatorId: ObjectId(user.id)
  30. })
  31. })
  32. })
  33. })