Skip to content

Commit

Permalink
Use new fixtures helper to clean db
Browse files Browse the repository at this point in the history
  • Loading branch information
Teddy Chambard committed Dec 24, 2016
1 parent 1494fa3 commit bf529d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/lib/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class MongodbConnector implements IConnector {
return c;
}

cleanDb(ds: string): void {
this.getConnection(ds).dropDatabase();
}

createModelFactory(name: string, myClass: any): IModelFactory {
return new ModelFactory(name, myClass, this);
}
Expand Down
25 changes: 15 additions & 10 deletions src/test/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Server } from 'spirit.io/lib/application';
import { ConnectorHelper } from 'spirit.io/lib/core';
import { MongodbConnector } from '../../lib/connector';
import { context, run } from 'f-promise';
import { setup } from 'f-mocha';
Expand Down Expand Up @@ -33,15 +34,7 @@ export class Fixtures extends GlobalFixtures {
let connector;
if (!context().__server) {
let server: Server = context().__server = new Server(config);
run(() => {
console.log("\n========== Initialize server begins ============");
connector = new MongodbConnector(config.connectors.mongodb);
server.addConnector(connector);
console.log("Connector config: " + JSON.stringify(connector.config, null, 2));
server.init();
}).catch(err => {
done(err);
});

server.on('initialized', function () {
run(() => {
console.log("========== Server initialized ============\n");
Expand All @@ -50,6 +43,7 @@ export class Fixtures extends GlobalFixtures {
done(err);
});
});

server.on('started', function () {
run(() => {
console.log("========== Server started ============\n");
Expand All @@ -61,11 +55,22 @@ export class Fixtures extends GlobalFixtures {
});
});

run(() => {
console.log("\n========== Initialize server begins ============");
connector = new MongodbConnector(config.connectors.mongodb);
server.addConnector(connector);
console.log("Connector config: " + JSON.stringify(connector.config, null, 2));
server.init();
}).catch(err => {
done(err);
});
} else {
firstSetup = false;
}
//

// delete the whole database
let mConnector: MongodbConnector = <MongodbConnector>ConnectorHelper.getConnector('mongodb');
Fixtures.cleanDatabases([mConnector]);
//
if (!firstSetup) done();
return context().__server;
Expand Down
4 changes: 0 additions & 4 deletions src/test/orm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ describe('Spirit.io ORM Framework Tests:', () => {
server = Fixtures.setup(done);
});

it('Delete instances should work as expected', () => {
removaAllDocuments();
});

it('Instanciate class should work either with adminHelper or ModelBase methods', () => {
// this test does not validate populate as it is not the purpose !

Expand Down

0 comments on commit bf529d1

Please sign in to comment.