mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05: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:
parent
1ad94859d5
commit
1425d96deb
2 changed files with 42 additions and 0 deletions
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue