diff --git a/packages/bruno-schema/src/index.js b/packages/bruno-schema/src/index.js index ad25aaad..ed092d5d 100644 --- a/packages/bruno-schema/src/index.js +++ b/packages/bruno-schema/src/index.js @@ -1,4 +1,3 @@ -const { workspaceSchema } = require("./workspaces"); const { collectionSchema, itemSchema, environmentSchema, environmentsSchema } = require("./collections"); module.exports = { @@ -6,5 +5,4 @@ module.exports = { environmentSchema, environmentsSchema, collectionSchema, - workspaceSchema }; \ No newline at end of file diff --git a/packages/bruno-schema/src/workspaces/index.js b/packages/bruno-schema/src/workspaces/index.js deleted file mode 100644 index cd289b87..00000000 --- a/packages/bruno-schema/src/workspaces/index.js +++ /dev/null @@ -1,19 +0,0 @@ -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'), - collections: Yup.array().of(collectionsSchema) -}).noUnknown(true).strict(); - -module.exports = { - workspaceSchema -}; \ No newline at end of file diff --git a/packages/bruno-schema/src/workspaces/index.spec.js b/packages/bruno-schema/src/workspaces/index.spec.js deleted file mode 100644 index c2577c10..00000000 --- a/packages/bruno-schema/src/workspaces/index.spec.js +++ /dev/null @@ -1,111 +0,0 @@ -const { expect } = require('@jest/globals'); -const { uuid, validationErrorWithMessages } = require("../utils/testUtils"); -const randomstring = require("randomstring"); -const { workspaceSchema } = require("./index"); - -describe('Workspace Schema Validation', () => { - it('workspace schema must validate successfully', async () => { - const workspace = { - uid: uuid(), - name: 'My workspace' - }; - - const isValid = await workspaceSchema.validate(workspace); - expect(isValid).toBeTruthy(); - }); - - it('workspace schema must throw error upon invalid uuid length', async () => { - const workspace = { - uid: uuid() + 'junk', - name: 'My workspace' - }; - - return Promise.all([ - expect(workspaceSchema.validate(workspace)).rejects.toEqual( - validationErrorWithMessages('uid must be 21 characters in length') - ) - ]); - }); - - it('workspace schema must throw error upon invalid uuid character', async () => { - const workspace = { - uid: uuid(), - name: 'My workspace' - }; - - workspace.uid = '$' + workspace.uid.substring(1, workspace.uid.length); - - return Promise.all([ - expect(workspaceSchema.validate(workspace)).rejects.toEqual( - validationErrorWithMessages('uid must be alphanumeric') - ) - ]); - }); - - it('workspace schema must throw error when name is empty', async () => { - const workspace = { - uid: uuid() - }; - - return Promise.all([ - expect(workspaceSchema.validate(workspace)).rejects.toEqual( - validationErrorWithMessages('name is required') - ) - ]); - }); - - it('workspace schema must throw error when name has more than 50 characters', async () => { - const workspace = { - uid: uuid(), - name: randomstring.generate({ - length: 51, - charset: 'alphabetic' - }) - }; - - return Promise.all([ - expect(workspaceSchema.validate(workspace)).rejects.toEqual( - validationErrorWithMessages('name must be 50 characters or less') - ) - ]); - }); - - it('workspace schema must throw error when unknown key is present', async () => { - const workspace = { - uid: uuid(), - name: 'My Workspace', - foo: 'bar' - }; - - return Promise.all([ - expect(workspaceSchema.validate(workspace)).rejects.toEqual( - validationErrorWithMessages('this field has unspecified keys: foo') - ) - ]); - }); - - 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') - ) - ]); - }); -});