Skip to content

Commit

Permalink
feat: 👽 add keys to source organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
clairenollet authored and this-is-tobi committed Jun 1, 2023
1 parent 6d66b75 commit 626c031
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/server/src/models/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/schemas/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions packages/shared/src/utils/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 626c031

Please sign in to comment.