forked from extern/bruno
chore: deleted unused workspace schema
This commit is contained in:
parent
abc26e5c5a
commit
b88848f0dc
@ -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
|
||||
};
|
@ -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
|
||||
};
|
@ -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')
|
||||
)
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user