From f18fa6bd8384882d870ee1bcec6fb7bdd7ff4e72 Mon Sep 17 00:00:00 2001 From: R Aditya Baradwaj Date: Mon, 12 Feb 2024 12:47:34 +0530 Subject: [PATCH 1/5] [APITEST-766] Added Packages to Collection Schema --- lib/collection/script.js | 6 ++++++ types/index.d.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/collection/script.js b/lib/collection/script.js index 8ec0f6775..224d57c14 100644 --- a/lib/collection/script.js +++ b/lib/collection/script.js @@ -62,6 +62,12 @@ _.assign(Script.prototype, /** @lends Script.prototype */ { * @type {string} */ this.type = options.type || 'text/javascript'; + + /** + * @arguments {Script.prototype} + * @type {Array} + */ + this.packages = options.packages || []; _.has(options, 'src') && ( /** diff --git a/types/index.d.ts b/types/index.d.ts index d4a3e7fb3..0924d181d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2158,15 +2158,18 @@ declare module "postman-collection" { * @param [options.type] - Script type * @param [options.src] - Script source url * @param [options.exec] - Script to execute + * @param [options.packages] - List of packages to be preloaded */ update(options?: { type?: string; src?: string; exec?: string[] | string; + packages?: Object[]; }): void; type: string; src: Url; exec: string[]; + packages: Object[]; /** * Check whether an object is an instance of ItemGroup. * @param obj - - From d4447f21bad6c0e0dd69c27ff13070e32366625d Mon Sep 17 00:00:00 2001 From: R Aditya Baradwaj Date: Mon, 12 Feb 2024 16:05:33 +0530 Subject: [PATCH 2/5] [APITEST-766] Fixed typos and minor issues --- lib/collection/script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/collection/script.js b/lib/collection/script.js index 224d57c14..d91a24e97 100644 --- a/lib/collection/script.js +++ b/lib/collection/script.js @@ -64,10 +64,11 @@ _.assign(Script.prototype, /** @lends Script.prototype */ { this.type = options.type || 'text/javascript'; /** - * @arguments {Script.prototype} - * @type {Array} + * @augments {Script.prototype} + * @type {Array<{ id: string, name: string}>} */ this.packages = options.packages || []; + _.has(options, 'src') && ( /** From d84f1ee1e11b9578ec7894558c426fc947937aa0 Mon Sep 17 00:00:00 2001 From: R Aditya Baradwaj Date: Thu, 15 Feb 2024 10:45:35 +0530 Subject: [PATCH 3/5] [APITEST-766] Added test changes for packages --- examples/collection-v2.json | 6 ++++-- lib/collection/script.js | 1 + test/unit/collection.test.js | 15 ++++++++++++--- test/unit/event-list.test.js | 12 ++++++++---- test/unit/event.test.js | 10 +++++++--- test/unit/item-group.test.js | 6 ++++-- test/unit/item.test.js | 3 ++- test/unit/script.test.js | 6 ++++-- 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/examples/collection-v2.json b/examples/collection-v2.json index 0186aa964..b8e405832 100644 --- a/examples/collection-v2.json +++ b/examples/collection-v2.json @@ -42,14 +42,16 @@ "id": "my-global-script-1", "script": { "type": "text/javascript", - "exec": "console.log(\"hello\");" + "exec": "console.log(\"hello\");", + "packages": [{ "id":"script-package-1", "name":"package1"}] } }, { "listen": "prerequest", "script": { "type": "text/javascript", - "exec": "console.log(\"hello\");" + "exec": "console.log(\"hello\");", + "packages": [{ "id":"script-package-1", "name":"package1"}] } } ], diff --git a/lib/collection/script.js b/lib/collection/script.js index d91a24e97..66c6f870d 100644 --- a/lib/collection/script.js +++ b/lib/collection/script.js @@ -49,6 +49,7 @@ _.assign(Script.prototype, /** @lends Script.prototype */ { * @param {String} [options.type] Script type * @param {String} [options.src] Script source url * @param {String[]|String} [options.exec] Script to execute + * @param {Object[]} [options.packages] Packages required by the script */ update: function (options) { // no splitting is being done here, as string scripts are split right before assignment below anyway diff --git a/test/unit/collection.test.js b/test/unit/collection.test.js index c413dad2a..9da69b6af 100644 --- a/test/unit/collection.test.js +++ b/test/unit/collection.test.js @@ -25,7 +25,8 @@ describe('Collection', function () { script: { id: 'my-script-1', type: 'text/javascript', - exec: ['console.log("This doesn\'t matter");'] + exec: ['console.log("This doesn\'t matter");'], + packages: [] } }] }, @@ -178,7 +179,8 @@ describe('Collection', function () { script: { id: 'test-script-1', type: 'text/javascript', - exec: ['console.log("Random");'] + exec: ['console.log("Random");'], + packages: [] } }); expect(collectionJSON.event[1]).to.have.property('listen', 'prerequest'); @@ -218,6 +220,12 @@ describe('Collection', function () { type: 'text/javascript', exec: [ 'console.log("bcoz I am batman!");' + ], + packages: [ + { + id: 'my-package-1', + name: 'superman', + } ] } }], @@ -280,7 +288,8 @@ describe('Collection', function () { type: 'text/javascript', exec: [ 'console.log("bcoz I am batman!");' - ] + ], + packages: [{ id: 'my-package-1', name: 'superman' }] } }], item: [{ diff --git a/test/unit/event-list.test.js b/test/unit/event-list.test.js index abe404a63..54c015f72 100644 --- a/test/unit/event-list.test.js +++ b/test/unit/event-list.test.js @@ -10,7 +10,8 @@ describe('EventList', function () { id: 'my-global-script-1', script: { type: 'text/javascript', - exec: 'console.log("hello");' + exec: 'console.log("hello");', + packages: [{ id: 'script-package-1', name: 'package1'}] } }]; @@ -35,7 +36,8 @@ describe('EventList', function () { script: { id: 'test-script-1', type: 'text/javascript', - exec: 'console.log("hello");' + exec: 'console.log("hello");', + packages: [{ id: 'script-package-1', name: 'package1'}] } }]), eventListJSON; @@ -46,7 +48,8 @@ describe('EventList', function () { script: { id: 'test-script-1', type: 'text/javascript', - exec: ['console.log("hello");'] + exec: ['console.log("hello");'], + packages: [{ id: 'script-package-1', name: 'package1'}] } }]); @@ -63,7 +66,8 @@ describe('EventList', function () { script: { id: 'test-script-1', type: 'text/javascript', - exec: ['console.log("hello");'] + exec: ['console.log("hello");'], + packages: [{ id: 'script-package-1', name: 'package1'}] } }); diff --git a/test/unit/event.test.js b/test/unit/event.test.js index b830ae1c3..28b6d01d2 100644 --- a/test/unit/event.test.js +++ b/test/unit/event.test.js @@ -11,7 +11,8 @@ describe('Event', function () { id: 'my-global-script-1', script: { type: 'text/javascript', - exec: 'console.log("hello");' + exec: 'console.log("hello");', + packages: [] } }; @@ -52,6 +53,7 @@ describe('Event', function () { expect(postmanEvent).to.have.property('script').that.is.an('object'); expect(postmanEvent.script).to.have.property('type', 'text/javascript'); expect(postmanEvent.script).to.have.property('exec').that.is.an('array'); + expect(postmanEvent.script).to.have.property('packages').that.is.an('array'); }); }); @@ -120,7 +122,8 @@ describe('Event', function () { expect(eventJSON).to.have.property('script').that.has.property('id'); expect(eventJSON.script).to.deep.include({ type: 'text/javascript', - exec: ['console.log("hello");'] + exec: ['console.log("hello");'], + packages: [] }); }); @@ -132,7 +135,8 @@ describe('Event', function () { expect(beforeJSON).to.have.property('script').that.has.property('id'); expect(beforeJSON.script).to.deep.include({ type: 'text/javascript', - exec: ['console.log("hello");'] + exec: ['console.log("hello");'], + packages: [] }); event.update({ script: { id: 'my-new-script' } }); diff --git a/test/unit/item-group.test.js b/test/unit/item-group.test.js index ff7d9966f..8c50e19ac 100644 --- a/test/unit/item-group.test.js +++ b/test/unit/item-group.test.js @@ -27,7 +27,8 @@ describe('ItemGroup', function () { script: { id: 'my-script-1', type: 'text/javascript', - exec: ['console.log("This doesn\'t matter");'] + exec: ['console.log("This doesn\'t matter");'], + packages: [{ id: 'my-package-1', name: 'package1' }] } }], protocolProfileBehavior: { @@ -527,7 +528,8 @@ describe('ItemGroup', function () { script: { id: 'my-test-script', type: 'text/javascript', - exec: ['console.log("hello there!");'] + exec: ['console.log("hello there!");'], + packages: [{ id: 'my-package-1', name: 'package1' }] } }], item: [{ diff --git a/test/unit/item.test.js b/test/unit/item.test.js index ac5108ff1..14a786e33 100644 --- a/test/unit/item.test.js +++ b/test/unit/item.test.js @@ -18,7 +18,8 @@ describe('Item', function () { script: { id: 'my-script-1', type: 'text/javascript', - exec: ['console.log("This doesn\'t matter");'] + exec: ['console.log("This doesn\'t matter");'], + packages: [{ id: 'script-package-1', name: 'package1' }] } }], request: { diff --git a/test/unit/script.test.js b/test/unit/script.test.js index 85d05c8b4..abd666446 100644 --- a/test/unit/script.test.js +++ b/test/unit/script.test.js @@ -89,7 +89,8 @@ describe('Script', function () { expect(scriptJSON).to.have.property('id'); expect(scriptJSON).to.deep.include({ type: 'text/javascript', - exec: ['console.log("This is a line of test script code");'] + exec: ['console.log("This is a line of test script code");'], + packages: [] }); }); @@ -201,7 +202,8 @@ describe('Script', function () { expect(jsonified).to.deep.include({ type: rawScript.type, - exec: rawScript.exec.split('\n') + exec: rawScript.exec.split('\n'), + packages: rawScript.packages }); expect(jsonified.src).to.eql(rawScript.src); }); From ffa818c01f6dd41c76bbf2b6a93ec113017c22fd Mon Sep 17 00:00:00 2001 From: R Aditya Baradwaj Date: Thu, 15 Feb 2024 12:11:38 +0530 Subject: [PATCH 4/5] [APITEST-766] Added minor formatting fixes --- test/unit/collection.test.js | 2 +- test/unit/event-list.test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/collection.test.js b/test/unit/collection.test.js index 9da69b6af..3dac88e9c 100644 --- a/test/unit/collection.test.js +++ b/test/unit/collection.test.js @@ -224,7 +224,7 @@ describe('Collection', function () { packages: [ { id: 'my-package-1', - name: 'superman', + name: 'superman' } ] } diff --git a/test/unit/event-list.test.js b/test/unit/event-list.test.js index 54c015f72..dc8f1b258 100644 --- a/test/unit/event-list.test.js +++ b/test/unit/event-list.test.js @@ -11,7 +11,7 @@ describe('EventList', function () { script: { type: 'text/javascript', exec: 'console.log("hello");', - packages: [{ id: 'script-package-1', name: 'package1'}] + packages: [{ id: 'script-package-1', name: 'package1' }] } }]; @@ -37,7 +37,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: 'console.log("hello");', - packages: [{ id: 'script-package-1', name: 'package1'}] + packages: [{ id: 'script-package-1', name: 'package1' }] } }]), eventListJSON; @@ -49,7 +49,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: ['console.log("hello");'], - packages: [{ id: 'script-package-1', name: 'package1'}] + packages: [{ id: 'script-package-1', name: 'package1' }] } }]); @@ -67,7 +67,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: ['console.log("hello");'], - packages: [{ id: 'script-package-1', name: 'package1'}] + packages: [{ id: 'script-package-1', name: 'package1' }] } }); From 805b014d23ea5f1e3f4f5ed5522216b5426ca762 Mon Sep 17 00:00:00 2001 From: R Aditya Baradwaj Date: Thu, 15 Feb 2024 16:18:17 +0530 Subject: [PATCH 5/5] [APITEST-766] Changed packages to an object --- examples/collection-v2.json | 4 ++-- lib/collection/script.js | 8 ++------ test/unit/collection.test.js | 13 ++++--------- test/unit/event-list.test.js | 6 +++--- test/unit/event.test.js | 8 ++++---- test/unit/item-group.test.js | 4 ++-- test/unit/item.test.js | 2 +- test/unit/script.test.js | 2 +- types/index.d.ts | 6 +++--- 9 files changed, 22 insertions(+), 31 deletions(-) diff --git a/examples/collection-v2.json b/examples/collection-v2.json index b8e405832..13b655487 100644 --- a/examples/collection-v2.json +++ b/examples/collection-v2.json @@ -43,7 +43,7 @@ "script": { "type": "text/javascript", "exec": "console.log(\"hello\");", - "packages": [{ "id":"script-package-1", "name":"package1"}] + "packages": { "package1": {"id":"script-package-1"}} } }, { @@ -51,7 +51,7 @@ "script": { "type": "text/javascript", "exec": "console.log(\"hello\");", - "packages": [{ "id":"script-package-1", "name":"package1"}] + "packages": { "package1": {"id":"script-package-1"}} } } ], diff --git a/lib/collection/script.js b/lib/collection/script.js index 66c6f870d..12a64cb02 100644 --- a/lib/collection/script.js +++ b/lib/collection/script.js @@ -49,7 +49,7 @@ _.assign(Script.prototype, /** @lends Script.prototype */ { * @param {String} [options.type] Script type * @param {String} [options.src] Script source url * @param {String[]|String} [options.exec] Script to execute - * @param {Object[]} [options.packages] Packages required by the script + * @param {Object} [options.packages] Packages required by the script */ update: function (options) { // no splitting is being done here, as string scripts are split right before assignment below anyway @@ -64,11 +64,7 @@ _.assign(Script.prototype, /** @lends Script.prototype */ { */ this.type = options.type || 'text/javascript'; - /** - * @augments {Script.prototype} - * @type {Array<{ id: string, name: string}>} - */ - this.packages = options.packages || []; + this.packages = options.packages || {}; _.has(options, 'src') && ( diff --git a/test/unit/collection.test.js b/test/unit/collection.test.js index 3dac88e9c..ccecb3ff5 100644 --- a/test/unit/collection.test.js +++ b/test/unit/collection.test.js @@ -26,7 +26,7 @@ describe('Collection', function () { id: 'my-script-1', type: 'text/javascript', exec: ['console.log("This doesn\'t matter");'], - packages: [] + packages: {} } }] }, @@ -180,7 +180,7 @@ describe('Collection', function () { id: 'test-script-1', type: 'text/javascript', exec: ['console.log("Random");'], - packages: [] + packages: {} } }); expect(collectionJSON.event[1]).to.have.property('listen', 'prerequest'); @@ -221,12 +221,7 @@ describe('Collection', function () { exec: [ 'console.log("bcoz I am batman!");' ], - packages: [ - { - id: 'my-package-1', - name: 'superman' - } - ] + packages: { superman: { id: 'script-apckage-1' } } } }], item: [{ @@ -289,7 +284,7 @@ describe('Collection', function () { exec: [ 'console.log("bcoz I am batman!");' ], - packages: [{ id: 'my-package-1', name: 'superman' }] + packages: { superman: { id: 'script-apckage-1' } } } }], item: [{ diff --git a/test/unit/event-list.test.js b/test/unit/event-list.test.js index dc8f1b258..7126475c2 100644 --- a/test/unit/event-list.test.js +++ b/test/unit/event-list.test.js @@ -37,7 +37,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: 'console.log("hello");', - packages: [{ id: 'script-package-1', name: 'package1' }] + packages: { package1: { id: 'script-package-1' } } } }]), eventListJSON; @@ -49,7 +49,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: ['console.log("hello");'], - packages: [{ id: 'script-package-1', name: 'package1' }] + packages: { package1: { id: 'script-apckage-1' } } } }]); @@ -67,7 +67,7 @@ describe('EventList', function () { id: 'test-script-1', type: 'text/javascript', exec: ['console.log("hello");'], - packages: [{ id: 'script-package-1', name: 'package1' }] + packages: { package1: { id: 'script-apckage-1' } } } }); diff --git a/test/unit/event.test.js b/test/unit/event.test.js index 28b6d01d2..7fba46b01 100644 --- a/test/unit/event.test.js +++ b/test/unit/event.test.js @@ -12,7 +12,7 @@ describe('Event', function () { script: { type: 'text/javascript', exec: 'console.log("hello");', - packages: [] + packages: {} } }; @@ -53,7 +53,7 @@ describe('Event', function () { expect(postmanEvent).to.have.property('script').that.is.an('object'); expect(postmanEvent.script).to.have.property('type', 'text/javascript'); expect(postmanEvent.script).to.have.property('exec').that.is.an('array'); - expect(postmanEvent.script).to.have.property('packages').that.is.an('array'); + expect(postmanEvent.script).to.have.property('packages').that.is.an('object'); }); }); @@ -123,7 +123,7 @@ describe('Event', function () { expect(eventJSON.script).to.deep.include({ type: 'text/javascript', exec: ['console.log("hello");'], - packages: [] + packages: {} }); }); @@ -136,7 +136,7 @@ describe('Event', function () { expect(beforeJSON.script).to.deep.include({ type: 'text/javascript', exec: ['console.log("hello");'], - packages: [] + packages: {} }); event.update({ script: { id: 'my-new-script' } }); diff --git a/test/unit/item-group.test.js b/test/unit/item-group.test.js index 8c50e19ac..f8ef2ec1e 100644 --- a/test/unit/item-group.test.js +++ b/test/unit/item-group.test.js @@ -28,7 +28,7 @@ describe('ItemGroup', function () { id: 'my-script-1', type: 'text/javascript', exec: ['console.log("This doesn\'t matter");'], - packages: [{ id: 'my-package-1', name: 'package1' }] + packages: { package1: { id: 'script-apckage-1' } } } }], protocolProfileBehavior: { @@ -529,7 +529,7 @@ describe('ItemGroup', function () { id: 'my-test-script', type: 'text/javascript', exec: ['console.log("hello there!");'], - packages: [{ id: 'my-package-1', name: 'package1' }] + packages: { package1: { id: 'script-apckage-1' } } } }], item: [{ diff --git a/test/unit/item.test.js b/test/unit/item.test.js index 14a786e33..e1d9ea226 100644 --- a/test/unit/item.test.js +++ b/test/unit/item.test.js @@ -19,7 +19,7 @@ describe('Item', function () { id: 'my-script-1', type: 'text/javascript', exec: ['console.log("This doesn\'t matter");'], - packages: [{ id: 'script-package-1', name: 'package1' }] + packages: { package1: { id: 'script-apckage-1' } } } }], request: { diff --git a/test/unit/script.test.js b/test/unit/script.test.js index abd666446..157b94a61 100644 --- a/test/unit/script.test.js +++ b/test/unit/script.test.js @@ -90,7 +90,7 @@ describe('Script', function () { expect(scriptJSON).to.deep.include({ type: 'text/javascript', exec: ['console.log("This is a line of test script code");'], - packages: [] + packages: {} }); }); diff --git a/types/index.d.ts b/types/index.d.ts index 0924d181d..cc2373c26 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2158,18 +2158,18 @@ declare module "postman-collection" { * @param [options.type] - Script type * @param [options.src] - Script source url * @param [options.exec] - Script to execute - * @param [options.packages] - List of packages to be preloaded + * @param [options.packages] - packages to be preloaded */ update(options?: { type?: string; src?: string; exec?: string[] | string; - packages?: Object[]; + packages?: Object; }): void; type: string; src: Url; exec: string[]; - packages: Object[]; + packages: Object; /** * Check whether an object is an instance of ItemGroup. * @param obj - -