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

Feat: Add getRecordType method to NsRecord [NS-1969] #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions Tests/Utils/record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
*
*/

const FileUnderTest = require('../../Utils/record');
const Record = require('../../Utils/record');

describe('testing record', () => {
it('should return a function ', () => {
expect(FileUnderTest).toEqual(expect.any(Function));
expect(Record).toEqual(expect.any(Function));
});
});

describe('setFieldValues', () => {
it('should check whether method exists', () => {
const result = new FileUnderTest('');
const result = new Record('');
expect(Object.prototype.hasOwnProperty.call(result, 'setFieldValues')).toBeTruthy();
});
it('should assign values to fieldName', () => {
const result = new FileUnderTest();
const result = new Record();
const values = ['123456', '654321'];
result.setFieldValues('selectField', values);
expect(result.getFieldValue('selectField')).toEqual(['123456', '654321']);
Expand All @@ -26,9 +26,38 @@ describe('setFieldValues', () => {

describe('getFieldValues', () => {
it('should return values for id specified', () => {
const result = new FileUnderTest();
const result = new Record();
result.setFieldValues('selectField', ['123', '123']);
const myValues = result.getFieldValues('selectField');
expect(myValues).toEqual(['123', '123']);
});
});

describe('getRecordType', () => {
it('should return record type', () => {
const type = 'salesorder';
const result = new Record(type);
const recordType = result.getRecordType();
expect(recordType).toEqual(type);
});
});

describe('getLineItemCount', () => {
it('should return number representing the length of a given sublist', () => {
const sublistId = 'item';
const itemsSublistData = [{
item_display: '101.173.00',
quantity: '3',
},
{
item_display: '101.174.00',
quantity: '1',
}];
const salesOrder = new Record('salesorder', {
item: itemsSublistData,
});
const mockedItemsLength = itemsSublistData.length;
const itemSublistLength = salesOrder.getLineItemCount(sublistId);
expect(itemSublistLength).toEqual(mockedItemsLength);
});
});
12 changes: 6 additions & 6 deletions Utils/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ const sublistObj = require('./sublistObjectMembers.jsx');
*
* @classDescription Record object
* @constructor
* @param {string} name
* @param {string} type
* @param {object} defaultValues
* @returns {nlobjRecord}
*/
function NsRecord(name, defaultValues = {}) {
function NsRecord(type, defaultValues = {}) {
const id = defaultValues.id || Math.ceil(Math.random() * 100);
const activeLine = {};
this.values = defaultValues;
this.values.item = this.values.item || [];
this.values.links = this.values.links || [];
this.type = 'nlobjRecord';
this.type = type || 'nlobjRecord';
return {
// 1.0 methods
getId: () => id,
getName: () => name,
getRecordType: () => this.type, // same method for both 1.0 and 2.0

// 2.0 methods
// eslint-disable-next-line no-unused-vars
id,
commit: () => {},
commitLine: obj => activeLine[obj.sublistId],
commitLineItem: sublist => activeLine[sublist],
createCurrentLineItemSubrecord: (sublistId, type) => nlapiCreateRecord(type, { sublistId }),

createCurrentLineItemSubrecord:
(sublistId, subRecordFieldId) => nlapiCreateRecord(subRecordFieldId, { sublistId }),
getAll: () => this.values, // Helper
getCurrentLineItemValue: (sublist, field) => this.values[sublist][activeLine[sublist]][field],
getCurrentSublistValue: (obj) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ns-suitescript-mocks",
"version": "0.2.5",
"version": "0.2.6",
"description": "Collection of mocks that can be used to improve unit-tests for SuiteScript 2.0.",
"main": "index.js",
"author": "Damian Krolikowski",
Expand Down