Skip to content

Commit 9abbbbb

Browse files
authored
🔀 pull request #4 from devnetkc/refactorTests
♻️ Refactors and adds more test coverage
2 parents 8ecd039 + ecc16be commit 9abbbbb

17 files changed

Lines changed: 168 additions & 92 deletions

.github/workflows/update-docs.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,35 @@
22

33
name: Update Documentation
44
on:
5-
push:
6-
branches:
7-
- main
8-
9-
env:
10-
FORCE_COLOR: 2
5+
pull_request:
6+
branches: [main]
117

128
jobs:
139
run:
1410
name: Generate Documentation README
1511
runs-on: ubuntu-latest
12+
env:
13+
COMMIT_USER: GitHub Actions
14+
COMMIT_EMAIL: actions@github.com
1615
steps:
1716
- name: Checkout repo
1817
uses: actions/checkout@v3
19-
18+
with:
19+
repository: ${{ github.event.pull_request.head.repo.full_name }}
20+
ref: ${{ github.event.pull_request.head.ref }}
2021
- name: Set up Node.js
2122
uses: actions/setup-node@v3
2223
with:
2324
node-version: 16
24-
cache: 'npm'
25-
26-
- name: Install dependencies
27-
run: npm install
28-
25+
- name: Clean install npm dependencies
26+
run: npm ci
2927
- name: Update documentation
3028
run: npm run docs
31-
3229
- name: Commit changes
3330
uses: EndBug/add-and-commit@v9
3431
with:
35-
author_name: GitHub Actions
36-
author_email: actions@github.com
37-
message: '📝 Generated Documentation'
38-
add: '.'
32+
author_name: ${{ env.COMMIT_USER }}
33+
author_email: ${{ env.COMMIT_EMAIL }}
34+
message: '📝 Updating Docs [ci skip]'
35+
# Configure for custom directories if required
36+
# add: '.' # default '.'

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ Azure yaml pipeline files are provided in [`.ci/workflows`](./.ci/workflows).
6363
- [`azure-pipelines-docs.yml`](./.ci/workflows/azure-pipelines-docs.yml) -- Generates documentation, commits,and pushes back to current PR/branch
6464
- [`azure-pipelines-build-deploy.yml`](./.ci/workflows/azure-pipelines-build-deploy.yml) -- Runs Jest tests, generates a change based deploy.xml, updates manifest dependencies, and uses SuiteCloud CLI to deploy projects
6565

66-
## 👥 Contributors
6766

68-
| Name | GitHub | Twitter |
69-
| ---------------- | --------------------------------------- | ----------------------------------------- |
70-
| **Ryan Valizan** | [devnetkc](https://github.com/devnetkc) | [@devnetkc](https://twitter.com/devnetkc) |
7167

7268
## 📝 Documentation
7369

@@ -137,6 +133,7 @@ Entry method for CS saveRecord function
137133
| Param | Type | Description |
138134
| --- | --- | --- |
139135
| scriptContext | <code>Object</code> | - Passed parameter for NetSuite CS saveRecord entry function |
136+
| scriptContext.currentRecord | <code>Object</code> | - Current record being saved |
140137

141138
<a name="module_aModule"></a>
142139

__tests__/CS/customModule_CS-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,42 @@ describe('customModule_CS.js', () => {
9292
expect(aModuleSpy).toHaveBeenCalledTimes(1);
9393
});
9494
});
95+
describe('test saveRecord', () => {
96+
const Record = new record.Record();
97+
describe('test errors', () => {
98+
const ErrorSpy = jest.spyOn(log, 'error');
99+
test('Should not throw any errors', () => {
100+
const ExecSaveRecord = customModule_CS.saveRecord({
101+
currentRecord: Record,
102+
});
103+
expect(
104+
jest.fn(() => {
105+
ExecSaveRecord;
106+
})
107+
).not.toThrow(Error);
108+
expect(ExecSaveRecord).toBeTruthy();
109+
expect(ErrorSpy).toHaveBeenCalledTimes(0);
110+
});
111+
test('Should catch errors', () => {
112+
const ExecSaveRecord = customModule_CS.saveRecord();
113+
expect(
114+
jest.fn(() => {
115+
ExecSaveRecord;
116+
})
117+
).not.toThrow(Error);
118+
expect(ExecSaveRecord).toBeTruthy();
119+
expect(ErrorSpy).toHaveBeenCalledTimes(1);
120+
});
121+
test("Doesn't allow save if no currentRecord property found", () => {
122+
const ExecSaveRecord = customModule_CS.saveRecord({});
123+
expect(
124+
jest.fn(() => {
125+
ExecSaveRecord;
126+
})
127+
).not.toThrow(Error);
128+
expect(ExecSaveRecord).toBeFalsy();
129+
expect(ErrorSpy).toHaveBeenCalledTimes(0);
130+
});
131+
});
132+
});
95133
});

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
5656
<br class="clear">
5757

5858
<footer>
59-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
59+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
6060
</footer>
6161

6262
<script> prettyPrint(); </script>

docs/module-aModule.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ <h5>Parameters:</h5>
258258

259259
<dt class="tag-source">Source:</dt>
260260
<dd class="tag-source"><ul class="dummy"><li>
261-
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line42">line 42</a>
261+
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line45">line 45</a>
262262
</li></ul></dd>
263263

264264

@@ -416,7 +416,7 @@ <h5>Parameters:</h5>
416416

417417
<dt class="tag-source">Source:</dt>
418418
<dd class="tag-source"><ul class="dummy"><li>
419-
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line43">line 43</a>
419+
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line46">line 46</a>
420420
</li></ul></dd>
421421

422422

@@ -571,7 +571,7 @@ <h5>Parameters:</h5>
571571

572572
<dt class="tag-source">Source:</dt>
573573
<dd class="tag-source"><ul class="dummy"><li>
574-
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line55">line 55</a>
574+
<a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html">src/FileCabinet/SuiteScripts/Modules/aModule.js</a>, <a href="src_FileCabinet_SuiteScripts_Modules_aModule.js.html#line58">line 58</a>
575575
</li></ul></dd>
576576

577577

@@ -645,7 +645,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
645645
<br class="clear">
646646

647647
<footer>
648-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
648+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
649649
</footer>
650650

651651
<script> prettyPrint(); </script>

docs/module-csExampleModule_CS.html

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ <h5>Parameters:</h5>
281281

282282
<dt class="tag-source">Source:</dt>
283283
<dd class="tag-source"><ul class="dummy"><li>
284-
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line47">line 47</a>
284+
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line50">line 50</a>
285285
</li></ul></dd>
286286

287287

@@ -488,7 +488,7 @@ <h6>Properties</h6>
488488

489489
<dt class="tag-source">Source:</dt>
490490
<dd class="tag-source"><ul class="dummy"><li>
491-
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line48">line 48</a>
491+
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line51">line 51</a>
492492
</li></ul></dd>
493493

494494

@@ -602,7 +602,56 @@ <h5>Parameters:</h5>
602602

603603

604604

605-
<td class="description last">- Passed parameter for NetSuite CS saveRecord entry function</td>
605+
<td class="description last">- Passed parameter for NetSuite CS saveRecord entry function
606+
<h6>Properties</h6>
607+
608+
609+
<table class="params">
610+
<thead>
611+
<tr>
612+
613+
<th>Name</th>
614+
615+
616+
<th>Type</th>
617+
618+
619+
620+
621+
622+
<th class="last">Description</th>
623+
</tr>
624+
</thead>
625+
626+
<tbody>
627+
628+
629+
<tr>
630+
631+
<td class="name"><code>currentRecord</code></td>
632+
633+
634+
<td class="type">
635+
636+
637+
<span class="param-type">Object</span>
638+
639+
640+
641+
</td>
642+
643+
644+
645+
646+
647+
<td class="description last">- Current record being saved</td>
648+
</tr>
649+
650+
651+
</tbody>
652+
</table>
653+
654+
</td>
606655
</tr>
607656

608657

@@ -643,7 +692,7 @@ <h5>Parameters:</h5>
643692

644693
<dt class="tag-source">Source:</dt>
645694
<dd class="tag-source"><ul class="dummy"><li>
646-
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line70">line 70</a>
695+
<a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html">src/FileCabinet/SuiteScripts/CS/customModule_CS.js</a>, <a href="src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html#line77">line 77</a>
647696
</li></ul></dd>
648697

649698

@@ -717,7 +766,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
717766
<br class="clear">
718767

719768
<footer>
720-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
769+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
721770
</footer>
722771

723772
<script> prettyPrint(); </script>

docs/src_FileCabinet_SuiteScripts_CS_customModule_CS.js.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/CS/customModule_CS.j
5353
];
5454
//AMD &amp; CommonJS compatibility stuff
5555
// CommonJS
56+
/* istanbul ignore else */
5657
if (typeof module !== 'undefined' &amp;&amp; typeof require !== 'undefined') {
5758
// Set ID for identifying in Jest
5859
module.id = '/SuiteScripts/CS/csExampleModule_CS';
5960
module.exports = csExampleModule_CS.apply(this, Dependencies.map(require));
6061
module.exports.mockable = csExampleModule_CS; // module loader with mockable dependencies
6162
}
6263
// AMD
64+
/* istanbul ignore next */
6365
if (typeof define !== 'undefined') {
66+
/* istanbul ignore next */
6467
define(Dependencies, csExampleModule_CS);
6568
}
6669
})();
@@ -89,7 +92,11 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/CS/customModule_CS.j
8992
log.debug({ title: `Vendor Prefix Set`, details: { VendorPrefix } });
9093
if (!scriptContext.hasOwnProperty('currentRecord'))
9194
throw 'MISSING_RECORD_PROPERTY';
92-
bModule.set_CustomFieldValue(scriptContext.currentRecord, VendorPrefix);
95+
bModule.set_CustomFieldValue({
96+
currentRecord: scriptContext.currentRecord,
97+
fieldId: 'custbody_example-id-1',
98+
value: VendorPrefix,
99+
});
93100
log.audit(`Vendor prefix saved`);
94101
} catch (err) {
95102
log.error({ title: 'csExampleModule_CS.pageInit()', details: err });
@@ -100,6 +107,7 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/CS/customModule_CS.j
100107
* @memberof module:csExampleModule_CS
101108
* @function
102109
* @param {Object} scriptContext -- Passed parameter for NetSuite CS saveRecord entry function
110+
* @param {Object} scriptContext.currentRecord -- Current record being saved
103111
* @description Entry method for CS saveRecord function
104112
* @return {boolean} - Returns `false` if record should not save yet
105113
*/
@@ -108,7 +116,7 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/CS/customModule_CS.j
108116
try {
109117
log.audit('starting custom client script saveRecord');
110118
// Run code to see if...
111-
// allowSave = false;
119+
if (!scriptContext.currentRecord) allowSave = false; //?
112120
} catch (err) {
113121
log.error({ title: 'csExampleModule_CS.saveRecord()', details: err });
114122
}
@@ -136,7 +144,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
136144
<br class="clear">
137145

138146
<footer>
139-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
147+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
140148
</footer>
141149

142150
<script> prettyPrint(); </script>

docs/src_FileCabinet_SuiteScripts_Modules_aModule.js.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/Modules/aModule.js</
4949
const Dependencies = ['N/query', 'N/log'];
5050
//AMD &amp; CommonJS compatibility stuff
5151
// CommonJS
52+
/* istanbul ignore else */
5253
if (typeof module !== 'undefined' &amp;&amp; typeof require !== 'undefined') {
5354
// Set ID for identifying in Jest
5455
module.id = '/SuiteScripts/Modules/aModule';
5556
module.exports = aModule.apply(this, Dependencies.map(require));
5657
module.exports.mockable = aModule; // module loader with mockable dependencies
5758
}
5859
// AMD
60+
/* istanbul ignore next */
5961
if (typeof define !== 'undefined') {
62+
/* istanbul ignore next */
6063
define(Dependencies, aModule);
6164
}
6265
})();
@@ -97,13 +100,15 @@ <h1 class="page-title">Source: src/FileCabinet/SuiteScripts/Modules/aModule.js</
97100
return QueryResult.prefix;
98101
};
99102
// * This is for Jest to have direct access to all methods for running tests
103+
/* istanbul ignore else */
100104
if (typeof module !== 'undefined' &amp;&amp; typeof require !== 'undefined') {
101105
return {
102106
GetVendorPrefix,
103107
RunQuery,
104108
};
105109
}
106110
// * These methods are returned in NetSuite
111+
/* istanbul ignore next */
107112
return {
108113
GetVendorPrefix,
109114
};
@@ -124,7 +129,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
124129
<br class="clear">
125130

126131
<footer>
127-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
132+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
128133
</footer>
129134

130135
<script> prettyPrint(); </script>

docs/suitecloud.config.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
6161
<br class="clear">
6262

6363
<footer>
64-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Nov 26 2022 14:59:55 GMT-0600 (Central Standard Time)
64+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:22:47 GMT+0000 (Coordinated Universal Time)
6565
</footer>
6666

6767
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)