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 - -