Skip to content

Commit

Permalink
Merge b5d91a5 into 75e5b98
Browse files Browse the repository at this point in the history
  • Loading branch information
troyharvey authored Oct 20, 2016
2 parents 75e5b98 + b5d91a5 commit ea466b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/CreateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateCommand {
this.driversToExecute.shift();
process.results.push(results);
this.runRecursive();
})
});
}

run() {
Expand Down
18 changes: 16 additions & 2 deletions src/TearDownCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ class TearDownCommand {
this.pathToJsonFile = pathToJsonFile;
this.driverLocator = driverLocator;
this.fs = fs;
this.driversToExecute = [];
}

runRecursive() {
if (this.driversToExecute.length == 0){
return new Promise((resolve) => {
resolve();
});
}

return this.driversToExecute[0].tearDown().then((results) => {
this.driversToExecute.shift();
this.runRecursive();
});
}

run() {
let seededData = this.fs.readFileSync(this.pathToJsonFile);

seededData.reverse();

let drivers = this.driverLocator.drivers();
Expand All @@ -16,12 +29,13 @@ class TearDownCommand {
let type = row["type"];
if(type in drivers){
let driver = drivers[type];
driver.tearDown();
this.driversToExecute.push(driver);
}else{
throw Error("Seeded data file does not contain a type that you have a driver for");
}
});

return this.runRecursive();
}
}

Expand Down
24 changes: 15 additions & 9 deletions test/TearDownCommandTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ describe('Tear down command tests', () => {

it('should destroy all the objects in the dependency chain',() => {

let accountDriverSpy = chai.spy.object(['tearDown']);
let contactDriverSpy = chai.spy.object(['tearDown']);

let drivers = {
'account': accountDriverSpy,
'contact': contactDriverSpy
'account': {
type: 'account',
tearDown: () => {
return new Promise((resolve) => { resolve(); });
}
},
'contact': {
type: 'contact',
tearDown: () => {
return new Promise((resolve) => { resolve(); });
}
}
};

let driverLocator = {
Expand Down Expand Up @@ -88,9 +95,8 @@ describe('Tear down command tests', () => {
fsMock
);

tearDownCommand.run();

accountDriverSpy.tearDown.should.have.been.called.once;
contactDriverSpy.tearDown.should.have.been.called.once;
tearDownCommand.run().then(() => {
expect(tearDownCommand.driversToExecute.length).to.be.equal(0);
});
});
});

0 comments on commit ea466b0

Please sign in to comment.