From 63e55842cbbbc4df9e99cd7fe41e0d902ae13fc6 Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 11:05:30 +0100 Subject: [PATCH 1/6] add getRecordType method to NsRecord --- Utils/record.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Utils/record.js b/Utils/record.js index 837970f..4e58549 100644 --- a/Utils/record.js +++ b/Utils/record.js @@ -47,6 +47,7 @@ function NsRecord(name, defaultValues = {}) { getLineItemCount: sublist => this.values[sublist].length, getLineItemText: (sublist, field, index) => this.values[sublist][index - 1][`${field}_display`], getLineItemValue: (sublist, field, index) => this.values[sublist][index - 1][field], + getRecordType: () => this.type, getSublistText: options => this.values[options.sublistId][options.line][options.fieldId], getSublistValue: options => this.values[options.sublistId][options.line][options.fieldId], getSublists: sublistObj, From 681c98fe1ca4b9d0e513f76daef8529c5ace46f0 Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 11:12:51 +0100 Subject: [PATCH 2/6] add unit test --- Tests/Utils/record.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Utils/record.test.js b/Tests/Utils/record.test.js index 7d54a8a..de33723 100644 --- a/Tests/Utils/record.test.js +++ b/Tests/Utils/record.test.js @@ -32,3 +32,11 @@ describe('getFieldValues', () => { expect(myValues).toEqual(['123', '123']); }); }); + +describe('getRecordType', () => { + it('should return record type', () => { + const result = new FileUnderTest(); + const recordType = result.getRecordType(); + expect(recordType).toEqual('nlobjRecord'); + }); +}); From 0fe98eb8066662f8b602af0b43c580bedbfa4006 Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 11:42:18 +0100 Subject: [PATCH 3/6] update N/Record definition to return type, remove getName method as not relevant --- Tests/Utils/record.test.js | 15 ++++++++------- Utils/record.js | 9 ++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/Utils/record.test.js b/Tests/Utils/record.test.js index de33723..8573756 100644 --- a/Tests/Utils/record.test.js +++ b/Tests/Utils/record.test.js @@ -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']); @@ -26,7 +26,7 @@ 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']); @@ -35,8 +35,9 @@ describe('getFieldValues', () => { describe('getRecordType', () => { it('should return record type', () => { - const result = new FileUnderTest(); + const type = 'salesorder'; + const result = new Record(type); const recordType = result.getRecordType(); - expect(recordType).toEqual('nlobjRecord'); + expect(recordType).toEqual(type); }); }); diff --git a/Utils/record.js b/Utils/record.js index 4e58549..95d0ad0 100644 --- a/Utils/record.js +++ b/Utils/record.js @@ -5,21 +5,21 @@ 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 @@ -47,7 +47,6 @@ function NsRecord(name, defaultValues = {}) { getLineItemCount: sublist => this.values[sublist].length, getLineItemText: (sublist, field, index) => this.values[sublist][index - 1][`${field}_display`], getLineItemValue: (sublist, field, index) => this.values[sublist][index - 1][field], - getRecordType: () => this.type, getSublistText: options => this.values[options.sublistId][options.line][options.fieldId], getSublistValue: options => this.values[options.sublistId][options.line][options.fieldId], getSublists: sublistObj, From a62d63cc8fe2db5bd74145bf220bc9cfedfc381c Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 11:50:25 +0100 Subject: [PATCH 4/6] rename argument from createCurrentLineItemSubrecord method --- Utils/record.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils/record.js b/Utils/record.js index 95d0ad0..c8e6f55 100644 --- a/Utils/record.js +++ b/Utils/record.js @@ -27,8 +27,8 @@ function NsRecord(type, defaultValues = {}) { 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) => { From 7d4fb01d82058a98305cdcd93b229ccd89dd9480 Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 11:57:06 +0100 Subject: [PATCH 5/6] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index afa92c7..2c93308 100644 --- a/package.json +++ b/package.json @@ -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", From 10735ad0d8e98be8a14c67638e811073fa9ad90f Mon Sep 17 00:00:00 2001 From: Simon Camilleri Date: Thu, 17 Jan 2019 15:51:52 +0100 Subject: [PATCH 6/6] added another unit, screw you codecov --- Tests/Utils/record.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/Utils/record.test.js b/Tests/Utils/record.test.js index 8573756..2a491f3 100644 --- a/Tests/Utils/record.test.js +++ b/Tests/Utils/record.test.js @@ -41,3 +41,23 @@ describe('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); + }); +});