Skip to content

Commit 805b014

Browse files
[APITEST-766] Changed packages to an object
1 parent ffa818c commit 805b014

File tree

9 files changed

+22
-31
lines changed

9 files changed

+22
-31
lines changed

examples/collection-v2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
"script": {
4444
"type": "text/javascript",
4545
"exec": "console.log(\"hello\");",
46-
"packages": [{ "id":"script-package-1", "name":"package1"}]
46+
"packages": { "package1": {"id":"script-package-1"}}
4747
}
4848
},
4949
{
5050
"listen": "prerequest",
5151
"script": {
5252
"type": "text/javascript",
5353
"exec": "console.log(\"hello\");",
54-
"packages": [{ "id":"script-package-1", "name":"package1"}]
54+
"packages": { "package1": {"id":"script-package-1"}}
5555
}
5656
}
5757
],

lib/collection/script.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ _.assign(Script.prototype, /** @lends Script.prototype */ {
4949
* @param {String} [options.type] Script type
5050
* @param {String} [options.src] Script source url
5151
* @param {String[]|String} [options.exec] Script to execute
52-
* @param {Object[]} [options.packages] Packages required by the script
52+
* @param {Object} [options.packages] Packages required by the script
5353
*/
5454
update: function (options) {
5555
// 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 */ {
6464
*/
6565
this.type = options.type || 'text/javascript';
6666

67-
/**
68-
* @augments {Script.prototype}
69-
* @type {Array<{ id: string, name: string}>}
70-
*/
71-
this.packages = options.packages || [];
67+
this.packages = options.packages || {};
7268

7369
_.has(options, 'src') && (
7470

test/unit/collection.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Collection', function () {
2626
id: 'my-script-1',
2727
type: 'text/javascript',
2828
exec: ['console.log("This doesn\'t matter");'],
29-
packages: []
29+
packages: {}
3030
}
3131
}]
3232
},
@@ -180,7 +180,7 @@ describe('Collection', function () {
180180
id: 'test-script-1',
181181
type: 'text/javascript',
182182
exec: ['console.log("Random");'],
183-
packages: []
183+
packages: {}
184184
}
185185
});
186186
expect(collectionJSON.event[1]).to.have.property('listen', 'prerequest');
@@ -221,12 +221,7 @@ describe('Collection', function () {
221221
exec: [
222222
'console.log("bcoz I am batman!");'
223223
],
224-
packages: [
225-
{
226-
id: 'my-package-1',
227-
name: 'superman'
228-
}
229-
]
224+
packages: { superman: { id: 'script-apckage-1' } }
230225
}
231226
}],
232227
item: [{
@@ -289,7 +284,7 @@ describe('Collection', function () {
289284
exec: [
290285
'console.log("bcoz I am batman!");'
291286
],
292-
packages: [{ id: 'my-package-1', name: 'superman' }]
287+
packages: { superman: { id: 'script-apckage-1' } }
293288
}
294289
}],
295290
item: [{

test/unit/event-list.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('EventList', function () {
3737
id: 'test-script-1',
3838
type: 'text/javascript',
3939
exec: 'console.log("hello");',
40-
packages: [{ id: 'script-package-1', name: 'package1' }]
40+
packages: { package1: { id: 'script-package-1' } }
4141
}
4242
}]),
4343
eventListJSON;
@@ -49,7 +49,7 @@ describe('EventList', function () {
4949
id: 'test-script-1',
5050
type: 'text/javascript',
5151
exec: ['console.log("hello");'],
52-
packages: [{ id: 'script-package-1', name: 'package1' }]
52+
packages: { package1: { id: 'script-apckage-1' } }
5353
}
5454
}]);
5555

@@ -67,7 +67,7 @@ describe('EventList', function () {
6767
id: 'test-script-1',
6868
type: 'text/javascript',
6969
exec: ['console.log("hello");'],
70-
packages: [{ id: 'script-package-1', name: 'package1' }]
70+
packages: { package1: { id: 'script-apckage-1' } }
7171
}
7272
});
7373

test/unit/event.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Event', function () {
1212
script: {
1313
type: 'text/javascript',
1414
exec: 'console.log("hello");',
15-
packages: []
15+
packages: {}
1616
}
1717
};
1818

@@ -53,7 +53,7 @@ describe('Event', function () {
5353
expect(postmanEvent).to.have.property('script').that.is.an('object');
5454
expect(postmanEvent.script).to.have.property('type', 'text/javascript');
5555
expect(postmanEvent.script).to.have.property('exec').that.is.an('array');
56-
expect(postmanEvent.script).to.have.property('packages').that.is.an('array');
56+
expect(postmanEvent.script).to.have.property('packages').that.is.an('object');
5757
});
5858
});
5959

@@ -123,7 +123,7 @@ describe('Event', function () {
123123
expect(eventJSON.script).to.deep.include({
124124
type: 'text/javascript',
125125
exec: ['console.log("hello");'],
126-
packages: []
126+
packages: {}
127127
});
128128
});
129129

@@ -136,7 +136,7 @@ describe('Event', function () {
136136
expect(beforeJSON.script).to.deep.include({
137137
type: 'text/javascript',
138138
exec: ['console.log("hello");'],
139-
packages: []
139+
packages: {}
140140
});
141141

142142
event.update({ script: { id: 'my-new-script' } });

test/unit/item-group.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('ItemGroup', function () {
2828
id: 'my-script-1',
2929
type: 'text/javascript',
3030
exec: ['console.log("This doesn\'t matter");'],
31-
packages: [{ id: 'my-package-1', name: 'package1' }]
31+
packages: { package1: { id: 'script-apckage-1' } }
3232
}
3333
}],
3434
protocolProfileBehavior: {
@@ -529,7 +529,7 @@ describe('ItemGroup', function () {
529529
id: 'my-test-script',
530530
type: 'text/javascript',
531531
exec: ['console.log("hello there!");'],
532-
packages: [{ id: 'my-package-1', name: 'package1' }]
532+
packages: { package1: { id: 'script-apckage-1' } }
533533
}
534534
}],
535535
item: [{

test/unit/item.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Item', function () {
1919
id: 'my-script-1',
2020
type: 'text/javascript',
2121
exec: ['console.log("This doesn\'t matter");'],
22-
packages: [{ id: 'script-package-1', name: 'package1' }]
22+
packages: { package1: { id: 'script-apckage-1' } }
2323
}
2424
}],
2525
request: {

test/unit/script.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('Script', function () {
9090
expect(scriptJSON).to.deep.include({
9191
type: 'text/javascript',
9292
exec: ['console.log("This is a line of test script code");'],
93-
packages: []
93+
packages: {}
9494
});
9595
});
9696

types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,18 +2158,18 @@ declare module "postman-collection" {
21582158
* @param [options.type] - Script type
21592159
* @param [options.src] - Script source url
21602160
* @param [options.exec] - Script to execute
2161-
* @param [options.packages] - List of packages to be preloaded
2161+
* @param [options.packages] - packages to be preloaded
21622162
*/
21632163
update(options?: {
21642164
type?: string;
21652165
src?: string;
21662166
exec?: string[] | string;
2167-
packages?: Object[];
2167+
packages?: Object;
21682168
}): void;
21692169
type: string;
21702170
src: Url;
21712171
exec: string[];
2172-
packages: Object[];
2172+
packages: Object;
21732173
/**
21742174
* Check whether an object is an instance of ItemGroup.
21752175
* @param obj - -

0 commit comments

Comments
 (0)