Add new fields to mongoose subscription schema

GitOrigin-RevId: 6b28d7464482a8d5729709f99893b333c3d7f9c2
This commit is contained in:
andrew rumble 2024-05-30 16:21:44 +01:00 committed by Copybot
parent 8c6c67564f
commit 3311066363
3 changed files with 36 additions and 2 deletions

View file

@ -56,6 +56,24 @@ const SubscriptionSchema = new Schema(
type: Date,
},
},
v1_id: {
type: Number,
required: false,
min: 1,
},
salesforce_id: {
type: String,
required: false,
validate: {
validator: function (salesforceId) {
return (
salesforceId == null ||
salesforceId === '' ||
salesforceId.match(/^(?:[A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/)
)
},
},
},
ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
},
{ minimize: false }

View file

@ -47,7 +47,7 @@ describe('mongoose', function () {
})
})
describe('Subsription', function () {
describe('Subscription', function () {
let user
beforeEach(async function () {
@ -56,7 +56,11 @@ describe('mongoose', function () {
it('allows the creation of a subscription', async function () {
await expect(
Subscription.create({ admin_id: user._id, manager_ids: [user._id] })
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
@ -65,5 +69,15 @@ describe('mongoose', function () {
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
})
})
})

View file

@ -11,4 +11,6 @@ export type Subscription = {
customAccount: boolean
ssoConfig: SSOConfig
managedUsersEnabled: boolean
v1_id: number
salesforce_id: string
}