Files
Verso/services/web/test/acceptance/src/ModelTests.mjs
T
Jakob Ackermann 425e7b1e5b [web] enable mongo notablescan in CI (#29501)
* [monorepo] record ERROR/FATAL log messages in junit report

* [web] put SaaS specific code behind feature flag

* [web] use split test cache for getting user assignments

The unit tests needed updating as they did not replicate any of the
 mongo filtering. The acceptance tests cover this logic.

* [web] make better use of existing indexes

* [web] avoid col-scan in tests of notifications module

* [web] remove cleanup of empty feedbacks collection

* [web] add assertion for reason of rejected request in launchpad test

* [web] add missing indexes

* [web] enable mongo notablescan

* [web] make emailNotifications tests compatible with notablescan

GitOrigin-RevId: b888f2feeb3a0e915f068ae1c4ea23ec17821221
2026-01-13 09:06:38 +00:00

88 lines
2.7 KiB
JavaScript

import { expect } from 'chai'
import { User } from '../../../app/src/models/User.mjs'
import { Subscription } from '../../../app/src/models/Subscription.mjs'
import Features from '../../../app/src/infrastructure/Features.mjs'
describe('mongoose', function () {
describe('User', function () {
const email = 'wombat@potato.net'
it('allows the creation of a user', async function () {
await expect(User.create({ email })).to.be.fulfilled
await expect(User.findOne({ email }, { _id: 1 })).to.eventually.exist
})
it('does not allow the creation of multiple users with the same email', async function () {
await expect(User.create({ email })).to.be.fulfilled
await expect(User.create({ email })).to.be.rejected
await expect(User.countDocuments({ email })).to.eventually.equal(1)
})
it('formats assignedAt as Date', async function () {
await expect(
User.create({
email,
splitTests: {
'some-test': [
{
variantName: 'control',
versionNumber: 1,
phase: 'release',
assignedAt: '2021-09-24T11:53:18.313Z',
},
{
variantName: 'control',
versionNumber: 2,
phase: 'release',
assignedAt: new Date(),
},
],
},
})
).to.be.fulfilled
const user = await User.findOne({ email }, { splitTests: 1 })
expect(user.splitTests['some-test'][0].assignedAt).to.be.a('date')
expect(user.splitTests['some-test'][1].assignedAt).to.be.a('date')
})
})
describe('Subscription', function () {
let user
beforeEach(async function () {
if (!Features.hasFeature('saas')) {
this.skip()
}
user = await User.create({ email: 'wombat@potato.net' })
})
it('allows the creation of a subscription', async function () {
await expect(
Subscription.create({
admin_id: user._id,
manager_ids: [user._id],
salesforce_id: 'a0a0a00000AAA0AAAA',
})
).to.be.fulfilled
await expect(Subscription.findOne({ admin_id: user._id })).to.eventually
.exist
})
it('does not allow the creation of a subscription without a manager', async function () {
await expect(Subscription.create({ admin_id: user._id })).to.be.rejected
})
it('does not allow the creation of a subscription with an invalid salesforce_id', async function () {
await expect(
Subscription.create({
admin_id: user._id,
manager_ids: [user._id],
salesforce_id: 'a00aaaAAa0000a',
})
).to.be.rejected
})
})
})