Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 1004a3a

Browse files
author
Valerii Radko
authored
N/url enums (#26)
* add resolveDomain method to url module * update version * update resolveRecord method on url module * add unit test
1 parent fe40164 commit 1004a3a

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

N/url.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@
66
* @returns {N/url}
77
*/
88

9+
const record = require('./record');
10+
11+
const transactionPath = Object.freeze({
12+
[record.Type.PURCHASE_ORDER]: 'purchord',
13+
[record.Type.SALES_ORDER]: 'salesord',
14+
});
15+
916
module.exports = {
10-
resolveScript: obj => `https://system.eu2.netsuite.com/app/site/hosting/scriptlet.nl?script=${obj.scriptId}&deploy=${obj.deploymentId}`,
11-
resolveRecord: () => 'https://system.eu2.netsuite.com//app/accounting/transactions/salesord.nl',
17+
HostType: {
18+
APPLICATION: 'APPLICATION',
19+
CUSTOMER_CENTER: 'CUSTOMER_CENTER',
20+
FORM: 'FORM',
21+
RESTLET: 'RESTLET',
22+
SUITETALK: 'SUITETALK',
23+
},
24+
resolveDomain: () => 'system.eu2.netsuite.com',
25+
resolveRecord: ({ recordType, recordId }) => `/app/accounting/transactions/${transactionPath[recordType]}.nl?id=${recordId}`,
26+
resolveScript: ({ scriptId, deploymentId }) => `https://system.eu2.netsuite.com/app/site/hosting/scriptlet.nl?script=${scriptId}&deploy=${deploymentId}`,
1227
};

Tests/N/url.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
*
44
*/
55

6-
const fileUnderTest = require('../../N/url');
6+
const record = require('../../N/record');
7+
const url = require('../../N/url');
78

89
describe('Testing url module', () => {
910
it('Should return object with properies available in Netsuite\'s url module ', () => {
1011
const expected = {
12+
resolveDomain: expect.any(Function),
1113
resolveScript: expect.any(Function),
1214
resolveRecord: expect.any(Function),
1315
};
14-
expect(fileUnderTest).toMatchObject(expected);
16+
17+
expect(url).toMatchObject(expected);
18+
});
19+
20+
it('Should return transaction url', () => {
21+
const result = url.resolveRecord({ recordType: record.Type.SALES_ORDER, recordId: 1234567 });
22+
23+
expect(result).toBe('/app/accounting/transactions/salesord.nl?id=1234567');
1524
});
1625
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ns-suitescript-mocks",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "Collection of mocks that can be used to improve unit-tests for SuiteScript 2.0.",
55
"main": "index.js",
66
"author": "Damian Krolikowski",
@@ -51,4 +51,4 @@
5151
"collectCoverage": true,
5252
"testURL": "http://localhost"
5353
}
54-
}
54+
}

0 commit comments

Comments
 (0)