Просмотр исходного кода

Add new fields to mongoose subscription schema

GitOrigin-RevId: 6b28d7464482a8d5729709f99893b333c3d7f9c2
andrew rumble 2 лет назад
Родитель
Сommit
3311066363

+ 18 - 0
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 }

+ 16 - 2
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
+    })
   })
 })

+ 2 - 0
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
 }