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

Commit 8757f71

Browse files
krolikowskidamianlukaszMycs
authored andcommitted
Chore: Mocha tests examples, Added getSublist for Record Module, Fixes (#13)
* init branch * installed mocha, created test folder structure * work * init mocha * fixed one test * Fixes, Added sublist for record (#12) * Chore: Two fixes in N/Search, Utils/Record (#11) * recordModule Added new fuction `insertLine` * Search-module Fixes * added sublistObjectMemeber * Clean
1 parent 3cd36b0 commit 8757f71

13 files changed

+356
-28
lines changed

Examples/1.0/exampleClientScript.js renamed to Examples/Jest/1.0/exampleClientScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require('../../index')({});
1+
require('../../../index')({});
22

33
/**
44
* Save Record Function

Examples/2.0/exampleClientScript.js renamed to Examples/Jest/2.0/exampleClientScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// Line below is required only becasue we are in the same repository as the library,
1313
// normally define is added to globally once you import our library and follow setup instructions
14-
const { define } = require('../../index')({});
14+
const { define } = require('../../../index')({});
1515

1616
// eslint-disable-next-line import/no-amd
1717
define(['N/ui/message'], (msg) => {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @NApiVersion 2.x
3+
* @NScriptType ClientScript
4+
*/
5+
6+
/**
7+
* This is an example of client script file.
8+
* In corresponding .test.js file you can find a way how to test it
9+
* of course with our ns-suitescript-mocks
10+
*/
11+
12+
// Line below is required only becasue we are in the same repository as the library,
13+
// normally define is added to globally once you import our library and follow setup instructions
14+
const { define } = require('../../../index')({});
15+
16+
// eslint-disable-next-line import/no-amd
17+
define(['N/ui/message'], (msg) => {
18+
/**
19+
* Page Init function to show message after form submit
20+
*
21+
* @param {N/context} context Module
22+
* @returns {boolean}
23+
*/
24+
function pageInit(context) {
25+
// eslint-disable-next-line prefer-destructuring
26+
const currentRecord = context.currentRecord;
27+
const myMsg = msg.create({
28+
title: 'Checkbox was checked',
29+
message: 'Checkbox was checked!',
30+
type: msg.Type.CONFIRMATION,
31+
});
32+
const showMessage = currentRecord.getValue({
33+
fieldId: 'messageonpost',
34+
});
35+
if (showMessage) {
36+
myMsg.show({
37+
duration: 5000,
38+
});
39+
}
40+
41+
return true;
42+
}
43+
// required for node
44+
if (typeof module !== 'undefined' && module.exports) {
45+
module.exports = {
46+
pageInit,
47+
message: msg,
48+
};
49+
}
50+
return {
51+
pageInit,
52+
};
53+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const assert = require('assert');
2+
const sinon = require('sinon');
3+
const fileUnderTest = require('./exampleClientScript');
4+
5+
const defaultValues = {
6+
tranid: '12121',
7+
custbody_mycs_ship_method: 23,
8+
shipstatus: 'B',
9+
custbodysps_packagedetails: 'test',
10+
};
11+
const fulfillmentRecord = nlapiCreateRecord('itemfulfillment', defaultValues);
12+
const context = {
13+
currentRecord: fulfillmentRecord,
14+
};
15+
16+
describe('exampleClientScript.js', () => {
17+
describe('pageInit', () => {
18+
it('should return true', () => {
19+
const result = fileUnderTest.pageInit(context);
20+
assert.deepEqual(result, true);
21+
});
22+
it('should call create message method', () => {
23+
// eslint-disable-next-line prefer-destructuring
24+
const message = fileUnderTest.message;
25+
const spyMessage = sinon.stub(message, 'create');
26+
fileUnderTest.pageInit(context);
27+
assert(spyMessage.called);
28+
assert(spyMessage.calledWithExactly({
29+
title: 'Checkbox was checked',
30+
message: 'Checkbox was checked!',
31+
type: 'confirmation',
32+
}));
33+
message.create.restore();
34+
});
35+
36+
it('should show not message if checkbox is not checked', () => {
37+
// eslint-disable-next-line prefer-destructuring
38+
const message = fileUnderTest.message;
39+
const createdMessage = message.create({
40+
message: 'Email with CSV was sent to your mailbox!',
41+
title: 'Email has been sent.',
42+
type: 'confirmation',
43+
});
44+
context.currentRecord.setFieldValue('messageonpost', false);
45+
const spyMesage = sinon.stub(message, 'create');
46+
const spyShow = sinon.spy(createdMessage, 'show');
47+
fileUnderTest.pageInit(context);
48+
assert(spyMesage.called);
49+
assert(spyShow.notCalled);
50+
});
51+
});
52+
});

N/search.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function createColumn(options) {
2525
function createFilter(options) { // eslint-disable-line no-unused-vars
2626
return `${options.name}${options.join ? `__${options.join}` : ''}`;
2727
}
28+
2829
/**
2930
* Return NetSuite ResultSet type.
3031
* @returns {object} resultset
@@ -104,23 +105,6 @@ function ResultSet() {
104105
};
105106
}
106107

107-
/**
108-
* NetSuite new column
109-
* @param {*} options
110-
* @returns {string}
111-
*/
112-
function createColumn(options) {
113-
return `${ options.name }${ options.join ? '__' + options.join : '' }`;
114-
}
115-
116-
/**
117-
* NetSuite new filter
118-
* @param {*} options
119-
* @returns {string}
120-
*/
121-
function createFilter(options) { // eslint-disable-line no-unused-vars
122-
return `${ options.name }${ options.join ? '__' + options.join : '' }`;
123-
}
124108
/**
125109
* NetSuite - constructor of search module.
126110
* @param {*} options_
@@ -163,11 +147,11 @@ module.exports = {
163147
lookupFields: (options) => {
164148
const result = {};
165149
if (Array.isArray(options.columns)) {
166-
options.columns.map((item, index) => {
167-
result[item] = [ { value: index, text: item } ];
150+
options.columns.forEach((item, index) => {
151+
result[item] = [{ value: index, text: item }];
168152
});
169153
} else if (typeof options.column === 'string') {
170-
result[options.column] = [ { value: Math.floor(Math.random() * 10000), text: options.column } ];
154+
result[options.column] = [{ value: Math.floor(Math.random() * 10000), text: options.column }];
171155
}
172156
return result;
173157
},

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Before pushing your code, make sure that the tests are passing (at the moment, w
5656

5757
## Authors 😎
5858

59-
* **Damian Królikowski** - *Mocks Creator* - [damiankrolikowskimycs](https://github.com/damiankrolikowskimycs)
59+
* **Damian Królikowski** - *Mocks Creator* - [krolikowskidamian](https://github.com/krolikowskidamian)
6060
* **Łukasz Kubasiewicz** - *Mocks Creator* - [lukaszMycs](https://github.com/lukaszmycs)
6161
* **Nicolas Ritouet** - *Automation setup, cleanup, documentation* - [nicolasritouet](https://github.com/nicolasritouet)
6262

Utils/record.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const sublistObj = require('./sublistObjectMembers.jsx');
2+
13
/**
24
* Return a Netsuite Record
35
*
@@ -45,6 +47,7 @@ function NsRecord(name, defaultValues = {}) {
4547
getLineItemValue: (sublist, field, index) => this.values[sublist][index - 1][field],
4648
getSublistText: options => this.values[options.sublistId][options.line][options.fieldId],
4749
getSublistValue: options => this.values[options.sublistId][options.line][options.fieldId],
50+
getSublists: sublistObj,
4851
getSubrecord: options => nlapiCreateRecord(options),
4952
getText: options => this.values[options.fieldId || options],
5053
getValue: options => this.values[options.fieldId || options],
@@ -68,7 +71,7 @@ function NsRecord(name, defaultValues = {}) {
6871
insertLineItem: (sublist, index) => {
6972
this.values[sublist].splice(index - 1, 0, {});
7073
},
71-
insertLine: options => {
74+
insertLine: (options) => {
7275
this.values[options.sublistId].splice(options.line, 0, {});
7376
},
7477
removeLine: (obj) => {

Utils/sublistObjectMembers.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Return a Netsuite Sublist Object
3+
*
4+
* @classDescription Record sublist bject
5+
* @constructor
6+
* @param {string} name
7+
* @param {object} defaultValues
8+
* @returns {nlobjRecord}
9+
*/
10+
function sublistObjectMembers(sublist, defaultValues = {}) {
11+
const id = sublist.sublistId || sublist;
12+
this.values = defaultValues;
13+
this.values.item = defaultValues.item || [];
14+
return {
15+
getColumn: () => id,
16+
id,
17+
isChanged: this.values.isChanged || false,
18+
isDisplay: this.values.isDisplay || false,
19+
type: this.values.defaultValues.type || 'nlobjRecord',
20+
};
21+
}
22+
23+
module.exports = sublistObjectMembers;

0 commit comments

Comments
 (0)