ModelTests.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const { expect } = require('chai')
  2. const { User } = require('../../../app/src/models/User')
  3. const { Subscription } = require('../../../app/src/models/Subscription')
  4. describe('mongoose', function () {
  5. describe('User', function () {
  6. const email = 'wombat@potato.net'
  7. it('allows the creation of a user', async function () {
  8. await expect(User.create({ email: email })).to.be.fulfilled
  9. await expect(User.findOne({ email: email })).to.eventually.exist
  10. })
  11. it('does not allow the creation of multiple users with the same email', async function () {
  12. await expect(User.create({ email: email })).to.be.fulfilled
  13. await expect(User.create({ email: email })).to.be.rejected
  14. await expect(User.countDocuments({ email: email })).to.eventually.equal(1)
  15. })
  16. })
  17. describe('Subsription', function () {
  18. let user
  19. beforeEach(async function () {
  20. user = await User.create({ email: 'wombat@potato.net' })
  21. })
  22. it('allows the creation of a subscription', async function () {
  23. await expect(
  24. Subscription.create({ admin_id: user._id, manager_ids: [user._id] })
  25. ).to.be.fulfilled
  26. await expect(Subscription.findOne({ admin_id: user._id })).to.eventually
  27. .exist
  28. })
  29. it('does not allow the creation of a subscription without a manager', async function () {
  30. await expect(Subscription.create({ admin_id: user._id })).to.be.rejected
  31. })
  32. })
  33. })