mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 22:59:01 +02:00
Merge pull request #5319 from overleaf/ta-split-test-assignment-date
Validate User's Split Tests Schema GitOrigin-RevId: 0e37a833696359838c7133cd7cd9411ec520993a
This commit is contained in:
@@ -169,5 +169,19 @@ const UserSchema = new Schema({
|
||||
analyticsId: { type: String },
|
||||
})
|
||||
|
||||
function formatSplitTestsSchema(next) {
|
||||
if (this.splitTests) {
|
||||
for (const splitTestKey of Object.keys(this.splitTests)) {
|
||||
for (const variantIndex in this.splitTests[splitTestKey]) {
|
||||
this.splitTests[splitTestKey][variantIndex].assignedAt = new Date(
|
||||
this.splitTests[splitTestKey][variantIndex].assignedAt
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
next()
|
||||
}
|
||||
UserSchema.pre('save', formatSplitTestsSchema)
|
||||
|
||||
exports.User = mongoose.model('User', UserSchema)
|
||||
exports.UserSchema = UserSchema
|
||||
|
||||
@@ -17,6 +17,34 @@ describe('mongoose', function () {
|
||||
await expect(User.create({ email: email })).to.be.rejected
|
||||
await expect(User.countDocuments({ email: 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 })
|
||||
expect(user.splitTests['some-test'][0].assignedAt).to.be.a('date')
|
||||
expect(user.splitTests['some-test'][1].assignedAt).to.be.a('date')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Subsription', function () {
|
||||
|
||||
Reference in New Issue
Block a user