From 738ab2e62204f0637eeb540498e345dcda839580 Mon Sep 17 00:00:00 2001 From: Troy Harvey Date: Wed, 19 Oct 2016 15:10:40 -0400 Subject: [PATCH] seededData.json is a dependency ordered array (#15) --- src/CreateCommand.js | 7 +++-- test/CreateCommandTest.js | 56 ++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/CreateCommand.js b/src/CreateCommand.js index f508e95..1f9272b 100644 --- a/src/CreateCommand.js +++ b/src/CreateCommand.js @@ -10,12 +10,11 @@ class CreateCommand { let graph = this.dependencyGraph.run(); let drivers = this.driverLocator.drivers(); - let result = {}; + let result = []; graph.forEach((graphElement) => { - let lowerElement = graphElement.toLowerCase(); - let driver = drivers[lowerElement]; - result[lowerElement] = driver.create(); + let driver = drivers[graphElement.toLowerCase()]; + result.push(driver.create()); }); this.fs.writeFileSync('./seededData.json', JSON.stringify(result)); diff --git a/test/CreateCommandTest.js b/test/CreateCommandTest.js index 09f6a38..5d6e27e 100644 --- a/test/CreateCommandTest.js +++ b/test/CreateCommandTest.js @@ -17,10 +17,13 @@ describe('Create command tests', () => { let AccountDriver = { create: function () { return ({ - 'id': 1, - 'firstName': 'Bob', - 'lastName': 'Jones', - 'email': 'bob@jones.com', + 'type': 'account', + 'properties': { + 'id': 1, + 'firstName': 'Bob', + 'lastName': 'Jones', + 'email': 'bob@jones.com' + } }); } }; @@ -28,11 +31,14 @@ describe('Create command tests', () => { let ContactDriver = { create: function () { return ({ - 'id': 1, - 'firstName': 'Bob', - 'lastName': 'Jones', - 'email': 'bob@jones.com', - 'accountId': 1 + 'type': 'contact', + 'properties': { + 'id': 1, + 'firstName': 'Bob', + 'lastName': 'Jones', + 'email': 'bob@jones.com', + 'accountId': 1 + } }); } }; @@ -60,20 +66,26 @@ describe('Create command tests', () => { createCommand.run(); - expect(dataExpectedToBeWrittenToFile).to.equal(JSON.stringify({ - 'account': { - 'id': 1, - 'firstName': 'Bob', - 'lastName': 'Jones', - 'email': 'bob@jones.com', + expect(dataExpectedToBeWrittenToFile).to.equal(JSON.stringify([ + { + 'type': 'account', + 'properties': { + 'id': 1, + 'firstName': 'Bob', + 'lastName': 'Jones', + 'email': 'bob@jones.com' + } }, - 'contact': { - 'id': 1, - 'firstName': 'Bob', - 'lastName': 'Jones', - 'email': 'bob@jones.com', - 'accountId': 1 + { + 'type': 'contact', + 'properties': { + 'id': 1, + 'firstName': 'Bob', + 'lastName': 'Jones', + 'email': 'bob@jones.com', + 'accountId': 1 + } } - })); + ])); }); });