- This contains mocks of SuiteScript entry points for use with jest testing.
- Version 0.1.5
- You can install by running
npm install @availentdev/suitemocks --save-dev
- Before using this package
- Once installed and your project is configured for testing
- Copy and paste the following over the contents of jest.config.js
- This adds the array of custom stubs, which allows custom stubs to mimic the import style of stubs provided by @oracle/suitecloud-unit-testing
- Ex.
import afterSubmitContext from 'N/ScriptContext/afterSubmitContext';
- Rather than
./path/to/file/afterSubmitContext
- Ex.
- The transformIgnorePatterns property is modified to include this package so that @babel can transform them properly alongside the stubs provided by @oracle/suitecloud-unit-testing
const SuiteCloudJestConfiguration = require('@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration');
const cliConfig = require('./suitecloud.config');
const TESTING_FRAMEWORK_PATH = '@oracle/suitecloud-unit-testing';
const CORE_STUBS_PATH = `${TESTING_FRAMEWORK_PATH}/stubs`;
const nodeModulesToTransform = [CORE_STUBS_PATH].join('|');
const build = SuiteCloudJestConfiguration.build({
projectFolder: cliConfig.defaultProjectFolder,
projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
customStubs: [
{
module: 'N/ScriptContext/beforeLoadContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/beforeLoadContext.js',
},
{
module: 'N/ScriptContext/beforeSubmitContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/beforeSubmitContext.js',
},
{
module: 'N/ScriptContext/afterSubmitContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/afterSubmitContext.js',
},
{
module: 'N/ScriptContext/inputContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/inputContext.js',
},
{
module: 'N/ScriptContext/mapContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/mapContext.js',
},
{
module: 'N/ScriptContext/reduceContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/reduceContext.js',
},
{
module: 'N/ScriptContext/summaryContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/summaryContext.js',
},
{
module: 'N/ScriptContext/pageInitContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/pageInitContext.js',
},
{
module: 'N/ScriptContext/saveRecordContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/saveRecordContext.js',
},
{
module: 'N/ScriptContext/fieldChangedContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/fieldChangedContext.js',
},
{
module: 'N/ScriptContext/sublistChangedContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/sublistChangedContext.js',
},
{
module: 'N/ScriptContext/postSourcingContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/postSourcingContext.js',
},
{
module: 'N/ScriptContext/lineInitContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/lineInitContext.js',
},
{
module: 'N/ScriptContext/validateFieldContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateFieldContext.js',
},
{
module: 'N/ScriptContext/validateLineContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateLineContext.js',
},
{
module: 'N/ScriptContext/validateInsertContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateInsertContext.js',
},
{
module: 'N/ScriptContext/validateDeleteContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateDeleteContext.js',
},
{
module: 'N/ScriptContext/eachParamsContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MassUpdate/eachParamsContext.js',
},
{
module: 'N/ScriptContext/executeContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ScheduledScript/executeContext.js',
},
{
module: 'N/ScriptContext/onRequestContext',
path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/Suitelet/onRequestContext.js',
},
],
});
build.transformIgnorePatterns = [`/node_modules/(?!(${nodeModulesToTransform}|@availentdev/suitemocks)/)`];
module.exports = build;
-
Each scriptContext mock contains the properties normally found in the scriptContext for that entry point
- Properties representing SuiteScript module objects are included with each of their methods as a jest function
- Properties of primitive data types default to undefined
- Enums are included
- Example for User Event afterSubmit:
{ oldRecord = recordObj, newRecord = recordObj, type = undefined, UserEventType = { COPY: 'copy', CREATE: 'create', VIEW: 'view', EDIT: 'edit', XEDIT: 'xedit', DELETE: 'delete', DROPSHIP: 'dropship', SPECIALORDER: 'specialorder', ORDERITEMS: 'orderitems', CANCEL: 'cancel', APPROVE: 'approve', REJECT: 'reject', RETRACT: 'retract', SAVESUBMIT: 'savesubmit', PACK: 'pack', SHIP: 'ship', EDITFORECAST: 'editforecast', REASSIGN: 'reassign', MARKCOMPLETE: 'markcomplete', PRINT: 'print', EMAIL: 'email', CHANGEPASSWORD: 'changepassword', TRANSFORM: 'transform', PAYBILLS: 'paybills', QUICKVIEW: 'quickview', } }
- oldRecord and newRecord in this example represent record.record objects
- Each method is a jest function
- Immediately available in tests
expect(afterSubmitScriptContextMock.getValue).toHaveBeenCalled();
- However, any mock returns or implementations need to be set up in the test file
- Immediately available in tests
- Each method is a jest function
To create new script contexts, copy an existing context file that most closely matches the one you need. Then, using NetSuite's documentation, add, remove, or modify the properties.
Entry points not yet included:
-
Bundle Installation Script:
- afterInstall(params)
- afterUpdate(params)
- beforeInstall(params)
- beforeUninstall(params)
- beforeUpdate(params)
-
Client Script:
- localizationContextEnter(scriptContext)
- localizationContextExit(scriptContext)
-
Portlet:
- render(params) (needs Portlet object added)
-
RESTlet:
- get
- delete
- put
- post
-
Workflow Action:
- onAction(scriptContext)
-
SDF Installation:
- run(scriptContext)
- Repo owner or admin
- Other community or team contact