Socket
Socket
Sign inDemoInstall

suitescript-mocks

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

suitescript-mocks

Set of mocks for unit testing Netsuite Suitescript 2.*


Version published
Weekly downloads
29
increased by3.57%
Maintainers
1
Weekly downloads
 
Created
Source

SuiteScript Mocks

This is a set of mocks for unit testing Netsuite. Modules that don't have a mock written for them instead use a stub from https://github.com/KyleJonesWinsted/suitecloud-unit-testing-stubs.

Setup:

package.json type should not be module

jest.config.js

const SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration.js");
const { defaults } = require("jest-config");
const SuiteScriptMocks = require("suitescript-mocks");
const cliConfig = require("./suitecloud.config.js");

const config = SuiteCloudJestConfiguration.build({
    projectFolder: cliConfig.defaultProjectFolder,
    projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
    customStubs: SuiteScriptMocks.stubs,
});

module.exports = {
    ...config,
    moduleFileExtensions: [...defaults.moduleFileExtensions, "cjs"],
};

suitecloud.config.js

const SuiteCloudJestUnitTestRunner = require("@oracle/suitecloud-unit-testing/services/SuiteCloudJestUnitTestRunner");

module.exports = {
    defaultProjectFolder: "src",
    commands: {
        "project:deploy": {
            beforeExecuting: async (args) => {
                await SuiteCloudJestUnitTestRunner.run({
                    // Jest configuration options.
                });
                return args;
            },
        },
    },
};

Usage:

The SuiteScriptMocks object exported by default by this package has a number of properties on it that control how the mocks work.

PropertyDescription
outputDebugLogsChoose whether or not to output debug logs to the console.
outputErrorLogsChoose whether or not to output error logs to the console.
outputAuditLogsChoose whether or not to output audit logs to the console.
currentScriptDetails loaded when using runtime.getCurrentScript()
currentUserDetails loaded when using runtime.getCurrentUser()
currentSessionDetails loaded when using runtime.getCurrentSession()
featuresMap of which netsuite features are enabled, used by runtime.isFeatureInEffect
sentEmailsList of emails sent using N/email.
cachesList of caches used by cache.getCache.
filesList of files used by file.load, etc. Use File constructor when creating files to add to this.
createdFilesList of files that have been created.
savedFilesList of files that have been saved.
deletedFilesList of files that have been deleted.
recordsList of records used by record.load, etc. Use Record constructor when creating records to add to this.
createdRecordsList of records that have been created.
savedRecordsList of records that have been saved.
deletedRecordsList of records that have been deleted.
searchesList of searches used by search.load, etc. Use Search constructor when creating searches to add to this.
runSearchesList of searches that have been run.
searchResultsList of search results used to mock dynamically created and executed searches. Every search created with search.create will consume the first element in the list.
lookupFieldsResultsList of results used to mock search.lookupFields. Every call to search.lookupFields will consume the first element in the list.
taskStatusesList of task statuses used by task.checkStatus.
submittedTasksList of submitted tasks.
logsList of execution logs created by N/log
resetFunction used to reset the state of the mocks library. Advisable to do before every test run, likely in a beforeEach.

For specific examples please look at the tests.

Keywords

FAQs

Package last updated on 30 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc