Skip to content

Commit

Permalink
[APITEST-766] Changed packages to an object
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-baradwaj committed Feb 15, 2024
1 parent ffa818c commit 805b014
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/collection-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
"script": {
"type": "text/javascript",
"exec": "console.log(\"hello\");",
"packages": [{ "id":"script-package-1", "name":"package1"}]
"packages": { "package1": {"id":"script-package-1"}}
}
},
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": "console.log(\"hello\");",
"packages": [{ "id":"script-package-1", "name":"package1"}]
"packages": { "package1": {"id":"script-package-1"}}
}
}
],
Expand Down
8 changes: 2 additions & 6 deletions lib/collection/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') && (

Expand Down
13 changes: 4 additions & 9 deletions test/unit/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Collection', function () {
id: 'my-script-1',
type: 'text/javascript',
exec: ['console.log("This doesn\'t matter");'],
packages: []
packages: {}
}
}]
},
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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: [{
Expand Down Expand Up @@ -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: [{
Expand Down
6 changes: 3 additions & 3 deletions test/unit/event-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' } }
}
}]);

Expand All @@ -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' } }
}
});

Expand Down
8 changes: 4 additions & 4 deletions test/unit/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Event', function () {
script: {
type: 'text/javascript',
exec: 'console.log("hello");',
packages: []
packages: {}
}
};

Expand Down Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('Event', function () {
expect(eventJSON.script).to.deep.include({
type: 'text/javascript',
exec: ['console.log("hello");'],
packages: []
packages: {}
});
});

Expand All @@ -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' } });
Expand Down
4 changes: 2 additions & 2 deletions test/unit/item-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [{
Expand Down
2 changes: 1 addition & 1 deletion test/unit/item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
});
});

Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 - -
Expand Down

0 comments on commit 805b014

Please sign in to comment.