bruno/packages/bruno-schema/src/collections/itemSchema.spec.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-10-14 21:45:56 +02:00
const { expect } = require('@jest/globals');
const { uuid, validationErrorWithMessages } = require('../utils/testUtils');
const { itemSchema } = require('./index');
2022-10-14 21:45:56 +02:00
describe('Item Schema Validation', () => {
it('item schema must validate successfully - simple items', async () => {
const item = {
uid: uuid(),
name: 'A Folder',
type: 'folder'
};
const isValid = await itemSchema.validate(item);
expect(isValid).toBeTruthy();
});
it('item schema must throw an error if name is missing', async () => {
const item = {
uid: uuid(),
type: 'folder'
};
return Promise.all([
expect(itemSchema.validate(item)).rejects.toEqual(validationErrorWithMessages('name is required'))
2022-10-14 21:45:56 +02:00
]);
});
it('item schema must throw an error if name is empty', async () => {
const item = {
uid: uuid(),
name: '',
type: 'folder'
};
return Promise.all([
expect(itemSchema.validate(item)).rejects.toEqual(
2023-10-07 21:54:33 +02:00
validationErrorWithMessages('name must be at least 1 character')
2022-10-14 21:45:56 +02:00
)
]);
});
it('item schema must throw an error if request is not present when item-type is http-request', async () => {
2022-10-14 21:45:56 +02:00
const item = {
uid: uuid(),
name: 'Get Users',
type: 'http-request'
};
return Promise.all([
expect(itemSchema.validate(item)).rejects.toEqual(
validationErrorWithMessages('request is required when item-type is request')
)
]);
});
it('item schema must throw an error if request is not present when item-type is graphql-request', async () => {
const item = {
uid: uuid(),
name: 'Get Users',
type: 'graphql-request'
2022-10-14 21:45:56 +02:00
};
return Promise.all([
expect(itemSchema.validate(item)).rejects.toEqual(
validationErrorWithMessages('request is required when item-type is request')
)
]);
});
});