Skip to content

Commit

Permalink
Merge pull request #419 from dnum-mi/feat/evolve-organization-model
Browse files Browse the repository at this point in the history
feat: 👽 add keys to source organizations
  • Loading branch information
clairenollet authored May 31, 2023
2 parents 98541f2 + 7036571 commit 01c1d51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/server/src/models/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const getOrganizationModel = () => Organization ?? (Organization = sequel
unique: true,
defaultValue: DataTypes.UUIDV4,
},
source: {
type: DataTypes.STRING(50),
},
name: {
type: DataTypes.STRING(50),
allowNull: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/schemas/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const organizationSchema = Joi.object({
id: Joi.string()
.uuid(),

source: Joi.string(),

name: Joi.string()
.min(2)
.max(10)
Expand Down
20 changes: 20 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,16 @@ describe('Schemas utils', () => {
})).toStrictEqual({})
})

it('Should validate a correct organization schema with external data', () => {
expect(schemaValidator(organizationSchema, {
id: faker.datatype.uuid(),
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 +85,16 @@ describe('Schemas utils', () => {
})).toStrictEqual({})
})

it('Should not validate an organization schema with wrong external data', () => {
expect(schemaValidator(organizationSchema, {
id: faker.datatype.uuid(),
source: faker.datatype.array(),
name: faker.word.noun(),
label: faker.company.name(),
active: faker.datatype.boolean(),
})).toStrictEqual({ source: '"source" 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 01c1d51

Please sign in to comment.