From 8a1320094fe3fcc14b8b91e0012509a8e16c3df2 Mon Sep 17 00:00:00 2001 From: ysandler Date: Sat, 27 Jun 2020 21:02:09 -0500 Subject: [PATCH] refact: depreicated importTables for setTables --- src/entities/Nodule.js | 13 +++++++---- tests/core/NoduleTests.js | 47 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/entities/Nodule.js b/src/entities/Nodule.js index 638d394..9112ce5 100644 --- a/src/entities/Nodule.js +++ b/src/entities/Nodule.js @@ -44,13 +44,18 @@ class Nodule { } importTables = tablesToImport => { - const validateTablesResponse = this._validateTables(tablesToImport) + console.log('Function importTables has been depricated, please use "setTables()"') + this.setTables(tablesToImport) + } + + setTables = tablesToSet => { + const validateTablesResponse = this._validateTables(tablesToSet) if (validateTablesResponse.status === 'ERR') { throw validateTablesResponse } else { let tables = [] - if (!Array.isArray(tablesToImport)) tables = [tablesToImport] - else tables = tablesToImport + if (!Array.isArray(tablesToSet)) tables = [tablesToSet] + else tables = tablesToSet this.tables = tables } } @@ -61,7 +66,7 @@ class Nodule { this.type = 'Nodule' this.isValid = true - if (props.tables) this.importTables(props.tables) + if (props.tables) this.setTables(props.tables) else this.tables = [] } diff --git a/tests/core/NoduleTests.js b/tests/core/NoduleTests.js index 0071e2c..d0ede39 100644 --- a/tests/core/NoduleTests.js +++ b/tests/core/NoduleTests.js @@ -113,9 +113,54 @@ const failToExport = () => { else return false } +const setTables = () => { + const initialTable = new Table({ + id: 'XYZ', + label: 'Test Table', + rows: [{ id: 'xyz', data: 'lh' }] + }) + + const overrideTable = new Table({ + id: 'XYZ', + label: 'Test Table', + rows: [{ id: 'abc', data: 'row' }] + }) + + const expectedOutput = { + id: 'ABC', + label: 'Test Node', + type: 'Nodule', + tables: [{ + id: 'XYZ', + label: 'Test Table', + rows: [{ id: 'abc', data: 'row' }], + type: 'Table', + isValid: true + }], + isValid: true + } + + try { + const nodule = new Nodule({ + id: 'ABC', + label: 'Test Node', + tables: initialTable + }) + nodule.setTables(overrideTable) + const nodeProps = nodule.getProperties() + + if (JSON.stringify(nodeProps) == JSON.stringify(expectedOutput)) return true + else return false + } catch (err) { + console.log(err) + return false + } +} + export default [ { name: 'Entity | Get Nodule Properties', test: getNodeProperties }, { name: 'Entity | Create Nodule Without Tables', test: createNodeWithoutTables }, { name: 'Entity | Import Tables to Nodule', test: importTables }, - { name: 'Entity | Fail to Export', test: failToExport } + { name: 'Entity | Fail to Export', test: failToExport }, + { name: 'Entity | Nodule setTables', test: setTables } ] \ No newline at end of file