From fe900b90c97dc9f426f2ffaa57cba2dbb2fa5fd3 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 16 Oct 2022 23:36:10 +0530 Subject: [PATCH] feat: version number in collection schema --- .../bruno-app/src/utils/collections/index.js | 3 ++ .../bruno-schema/src/collections/index.js | 1 + .../src/collections/index.spec.js | 6 +++ .../src/collections/requestSchema.spec.js | 46 ------------------- 4 files changed, 10 insertions(+), 46 deletions(-) diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index f5012672e..bf47700c1 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -237,6 +237,9 @@ export const transformCollectionToSaveToIdb = (collection, options = {}) => { const collectionToSave = {}; collectionToSave.name = collection.name; collectionToSave.uid = collection.uid; + + // todo: move this to the place where collection gets created + collectionToSave.version = '1'; collectionToSave.items = []; collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid; collectionToSave.environments = collection.environments || []; diff --git a/packages/bruno-schema/src/collections/index.js b/packages/bruno-schema/src/collections/index.js index 7d8ab3731..da680a6ab 100644 --- a/packages/bruno-schema/src/collections/index.js +++ b/packages/bruno-schema/src/collections/index.js @@ -64,6 +64,7 @@ const itemSchema = Yup.object({ }).noUnknown(true).strict(); const collectionSchema = Yup.object({ + version: Yup.string().oneOf(['1']).required('version is required'), uid: uidSchema, name: Yup.string() .min(1, 'name must be atleast 1 characters') diff --git a/packages/bruno-schema/src/collections/index.spec.js b/packages/bruno-schema/src/collections/index.spec.js index 5e5acda9f..ae9c5ca48 100644 --- a/packages/bruno-schema/src/collections/index.spec.js +++ b/packages/bruno-schema/src/collections/index.spec.js @@ -5,6 +5,7 @@ const { collectionSchema } = require("./index"); describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, no items', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection' }; @@ -15,6 +16,7 @@ describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, empty items', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection', items: [] @@ -26,6 +28,7 @@ describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, just a folder item', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection', items: [{ @@ -41,6 +44,7 @@ describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, just a request item', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection', items: [{ @@ -65,6 +69,7 @@ describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, folder inside folder', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection', items: [{ @@ -85,6 +90,7 @@ describe('Collection Schema Validation', () => { it('collection schema must validate successfully - simple collection, [folder] [request + folder]', async () => { const collection = { + version: '1', uid: uuid(), name: 'My Collection', items: [{ diff --git a/packages/bruno-schema/src/collections/requestSchema.spec.js b/packages/bruno-schema/src/collections/requestSchema.spec.js index b9bcda212..5c0ca92d3 100644 --- a/packages/bruno-schema/src/collections/requestSchema.spec.js +++ b/packages/bruno-schema/src/collections/requestSchema.spec.js @@ -35,50 +35,4 @@ describe('Request Schema Validation', () => { ) ]); }); - - it('request schema must throw an error of header name is missing', async () => { - const request = { - url: 'https://restcountries.com/v2/alpha/in', - method: 'GET', - headers: [{ - uid: uuid(), - value: 'Check', - description: '', - enabled: true - }], - params: [], - body: { - mode: 'none' - } - }; - - return Promise.all([ - expect(requestSchema.validate(request)).rejects.toEqual( - validationErrorWithMessages('headers[0].name must be defined') - ) - ]); - }); - - it('request schema must throw an error of param value is missing', async () => { - const request = { - url: 'https://restcountries.com/v2/alpha/in', - method: 'GET', - headers: [], - params: [{ - uid: uuid(), - name: 'customerId', - description: '', - enabled: true - }], - body: { - mode: 'none' - } - }; - - return Promise.all([ - expect(requestSchema.validate(request)).rejects.toEqual( - validationErrorWithMessages('params[0].value must be defined') - ) - ]); - }); }); \ No newline at end of file