feat: collections are stored as objects in workspaces

This commit is contained in:
Anoop M D
2022-10-15 13:50:58 +05:30
parent d546709b26
commit 91981a48e4
8 changed files with 68 additions and 21 deletions

View File

@ -1,13 +1,17 @@
const Yup = require('yup');
const { uidSchema } = require("../common");
const collectionsSchema = Yup.object({
uid: uidSchema,
}).noUnknown(true).strict();
const workspaceSchema = Yup.object({
uid: uidSchema,
name: Yup.string()
.min(1, 'name must be atleast 1 characters')
.max(50, 'name must be 50 characters or less')
.required('name is required'),
collectionUids: Yup.array().of(uidSchema)
collections: Yup.array().of(collectionsSchema)
}).noUnknown(true).strict();
module.exports = {

View File

@ -83,4 +83,29 @@ describe('Workspace Schema Validation', () => {
)
]);
});
it('workspace schema must validate successfully with collections', async () => {
const workspace = {
uid: uuid(),
name: 'My workspace' ,
collections: [{uid: uuid()}]
};
const isValid = await workspaceSchema.validate(workspace);
expect(isValid).toBeTruthy();
});
it('workspace schema throw an error when collections has an unknown property', async () => {
const workspace = {
uid: uuid(),
name: 'My workspace' ,
collections: [{uid: uuid(), foo: 'bar'}]
};
return Promise.all([
expect(workspaceSchema.validate(workspace)).rejects.toEqual(
validationErrorWithMessages('collections[0] field has unspecified keys: foo')
)
]);
});
});