From 626c03135571199c3a1f1e72e19132bc651288a3 Mon Sep 17 00:00:00 2001 From: Claire Nollet Date: Fri, 12 May 2023 18:27:36 +0200 Subject: [PATCH] feat: :alien: add keys to source organizations --- apps/server/src/models/organization.js | 7 +++++++ packages/shared/src/schemas/organization.js | 4 ++++ packages/shared/src/utils/schemas.spec.js | 22 +++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/apps/server/src/models/organization.js b/apps/server/src/models/organization.js index edf1f814d..70ae44530 100644 --- a/apps/server/src/models/organization.js +++ b/apps/server/src/models/organization.js @@ -10,6 +10,13 @@ export const getOrganizationModel = () => Organization ?? (Organization = sequel unique: true, defaultValue: DataTypes.UUIDV4, }, + contributorId: { + type: DataTypes.STRING(50), + unique: true, + }, + source: { + type: DataTypes.STRING(50), + }, name: { type: DataTypes.STRING(50), allowNull: false, diff --git a/packages/shared/src/schemas/organization.js b/packages/shared/src/schemas/organization.js index 971b7765f..939c6d9e1 100644 --- a/packages/shared/src/schemas/organization.js +++ b/packages/shared/src/schemas/organization.js @@ -4,6 +4,10 @@ export const organizationSchema = Joi.object({ id: Joi.string() .uuid(), + contributorId: Joi.string(), + + source: Joi.string(), + name: Joi.string() .min(2) .max(10) diff --git a/packages/shared/src/utils/schemas.spec.js b/packages/shared/src/utils/schemas.spec.js index 719613af9..6d7debf41 100644 --- a/packages/shared/src/utils/schemas.spec.js +++ b/packages/shared/src/utils/schemas.spec.js @@ -56,6 +56,17 @@ describe('Schemas utils', () => { })).toStrictEqual({}) }) + it('Should validate a correct organization schema with external data', () => { + expect(schemaValidator(organizationSchema, { + id: faker.datatype.uuid(), + contributorId: faker.word.noun(), + source: faker.word.noun(), + name: faker.word.noun(), + label: faker.company.name(), + active: faker.datatype.boolean(), + })).toStrictEqual({}) + }) + it('Should validate a correct project schema', () => { expect(schemaValidator(projectSchema, { id: faker.datatype.uuid(), @@ -75,6 +86,17 @@ describe('Schemas utils', () => { })).toStrictEqual({}) }) + it('Should not validate an organization schema with wrong external data', () => { + expect(schemaValidator(organizationSchema, { + id: faker.datatype.uuid(), + contributorId: faker.datatype.array(), + source: faker.word.noun(), + name: faker.word.noun(), + label: faker.company.name(), + active: faker.datatype.boolean(), + })).toStrictEqual({ contributorId: '"contributorId" must be a string' }) + }) + it('Should not validate schema and send specific error', () => { expect(schemaValidator(repoSchema, { id: faker.datatype.uuid(),