From 33110663631708580c797659b8d5d3f95a719c1d Mon Sep 17 00:00:00 2001 From: andrew rumble Date: Thu, 30 May 2024 16:21:44 +0100 Subject: [PATCH] Add new fields to mongoose subscription schema GitOrigin-RevId: 6b28d7464482a8d5729709f99893b333c3d7f9c2 --- services/web/app/src/models/Subscription.js | 18 ++++++++++++++++++ services/web/test/acceptance/src/ModelTests.js | 18 ++++++++++++++++-- services/web/types/admin/subscription.ts | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/models/Subscription.js b/services/web/app/src/models/Subscription.js index 51e73ac2a7..9f1a4aeab8 100644 --- a/services/web/app/src/models/Subscription.js +++ b/services/web/app/src/models/Subscription.js @@ -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 } diff --git a/services/web/test/acceptance/src/ModelTests.js b/services/web/test/acceptance/src/ModelTests.js index ac0c473fde..0f1e01e6a1 100644 --- a/services/web/test/acceptance/src/ModelTests.js +++ b/services/web/test/acceptance/src/ModelTests.js @@ -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 + }) }) }) diff --git a/services/web/types/admin/subscription.ts b/services/web/types/admin/subscription.ts index 16174951ef..bbcdd3b953 100644 --- a/services/web/types/admin/subscription.ts +++ b/services/web/types/admin/subscription.ts @@ -11,4 +11,6 @@ export type Subscription = { customAccount: boolean ssoConfig: SSOConfig managedUsersEnabled: boolean + v1_id: number + salesforce_id: string }