diff --git a/tests/unit/server-test.js b/tests/unit/server-test.js index 432e8a3f6..650d4d832 100644 --- a/tests/unit/server-test.js +++ b/tests/unit/server-test.js @@ -7,13 +7,16 @@ module('Unit | Server'); test('it can be instantiated', function(assert) { let server = new Server({ environment: 'test' }); + assert.ok(server); + + server.shutdown(); }); test('it runs the default scenario in non-test environments', function(assert) { assert.expect(1); - new Server({ + let server = new Server({ environment: 'development', scenarios: { default(server) { @@ -21,36 +24,51 @@ test('it runs the default scenario in non-test environments', function(assert) { } } }); + + server.shutdown(); }); module('Unit | Server #loadConfig'); test('forces timing to 0 in test environment', function(assert) { let server = new Server({ environment: 'test' }); + server.loadConfig(function() { this.timing = 50; }); + assert.equal(server.timing, 0); + + server.shutdown(); }); test("doesn't modify user's timing config in other environments", function(assert) { let server = new Server({ environment: 'blah' }); + server.loadConfig(function() { this.timing = 50; }); + assert.equal(server.timing, 50); + + server.shutdown(); }); module('Unit | Server #db'); test('its db is isolated across instances', function(assert) { let server1 = new Server({ environment: 'test' }); + server1.db.createCollection('contacts'); server1.db.contacts.insert({ name: 'Sam' }); + server1.shutdown(); + let server2 = new Server({ environment: 'test' }); assert.equal(server2.contacts, undefined); + + server2.shutdown(); }); module('Unit | Server #create'); @@ -61,6 +79,8 @@ test('create fails when no factories or models are registered', function(assert) assert.throws(function() { server.create('contact'); }); + + server.shutdown(); }); test('create fails when an expected factory isn\'t registered', function(assert) { @@ -74,6 +94,8 @@ test('create fails when an expected factory isn\'t registered', function(assert) assert.throws(function() { server.create('contact'); }, /no model or factory was found/); + + server.shutdown(); }); test('create works when models but no factories are registered', function(assert) { @@ -85,7 +107,10 @@ test('create works when models but no factories are registered', function(assert }); server.create('contact'); + assert.equal(server.db.contacts.length, 1); + + server.shutdown(); }); test('create adds the data to the db', function(assert) { @@ -103,6 +128,8 @@ test('create adds the data to the db', function(assert) { assert.equal(contactsInDb.length, 1); assert.deepEqual(contactsInDb[0], { id: '1', name: 'Sam' }); + + server.shutdown(); }); test('create returns the new data in the db', function(assert) { @@ -118,6 +145,8 @@ test('create returns the new data in the db', function(assert) { let contact = server.create('contact'); assert.deepEqual(contact, { id: '1', name: 'Sam' }); + + server.shutdown(); }); test('create allows for attr overrides', function(assert) { @@ -135,6 +164,8 @@ test('create allows for attr overrides', function(assert) { assert.deepEqual(sam, { id: '1', name: 'Sam' }); assert.deepEqual(link, { id: '2', name: 'Link' }); + + server.shutdown(); }); test('create allows for attr overrides with extended factories', function(assert) { @@ -161,6 +192,8 @@ test('create allows for attr overrides with extended factories', function(assert assert.deepEqual(link, { id: '1', name: 'Link', age: 500, is_young: false }); assert.deepEqual(youngLink, { id: '2', name: 'Link', age: 10, is_young: true }); + + server.shutdown(); }); test('create allows for attr overrides with arrays', function(assert) { @@ -180,6 +213,8 @@ test('create allows for attr overrides with arrays', function(assert) { assert.deepEqual(sam, { id: '1', name: ['Sam', 'Carl'] }); assert.deepEqual(link, { id: '2', name: ['Link'] }); assert.deepEqual(noname, { id: '3', name: [] }); + + server.shutdown(); }); test('create allows for nested attr overrides', function(assert) { @@ -202,6 +237,8 @@ test('create allows for nested attr overrides', function(assert) { assert.deepEqual(contact1, { id: '1', address: { streetName: 'Main', streetAddress: 1000 } }); assert.deepEqual(contact2, { id: '2', address: { streetName: 'Main', streetAddress: 1001 } }); + + server.shutdown(); }); test('create allows for arrays of attr overrides', function(assert) { @@ -224,6 +261,8 @@ test('create allows for arrays of attr overrides', function(assert) { assert.deepEqual(contact1, { id: '1', websites: ['http://example.com', 'http://placekitten.com/320/240'] }); assert.deepEqual(contact2, { id: '2', websites: ['http://example.com', 'http://placekitten.com/321/241'] }); + + server.shutdown(); }); test('create allows to extend factory with trait', function(assert) { @@ -249,6 +288,8 @@ test('create allows to extend factory with trait', function(assert) { assert.deepEqual(article, { id: '1', title: 'Lorem ipsum' }); assert.deepEqual(publishedArticle, { id: '2', title: 'Lorem ipsum', isPublished: true, publishedAt: '2010-01-01 10:00:00' }); + + server.shutdown(); }); test('create allows to extend factory with multiple traits', function(assert) { @@ -281,6 +322,8 @@ test('create allows to extend factory with multiple traits', function(assert) { publishedAt: '2010-01-01 10:00:00' }); assert.deepEqual(publishedArticleWithContent, { id: '3', title: 'Lorem ipsum', isPublished: true, publishedAt: '2010-01-01 10:00:00', content: 'content' }); + + server.shutdown(); }); test('create allows to extend factory with traits containing afterCreate callbacks', function(assert) { @@ -309,6 +352,8 @@ test('create allows to extend factory with traits containing afterCreate callbac assert.deepEqual(articleWithComments, { id: '1', title: 'Lorem ipsum' }); assert.equal(server.db.comments.length, 3); + + server.shutdown(); }); test('create does not execute afterCreate callbacks from traits that are not applied', function(assert) { @@ -337,6 +382,8 @@ test('create does not execute afterCreate callbacks from traits that are not app assert.deepEqual(articleWithComments, { id: '1', title: 'Lorem ipsum' }); assert.equal(server.db.comments.length, 0); + + server.shutdown(); }); test('create allows to extend with multiple traits and to apply attr overrides', function(assert) { @@ -367,6 +414,8 @@ test('create allows to extend with multiple traits and to apply attr overrides', assert.deepEqual(publishedArticleWithContent, { id: '1', title: 'Lorem ipsum', isPublished: true, publishedAt: '2012-01-01 10:00:00', content: 'content' }); + + server.shutdown(); }); test('create throws errors when using trait that is not defined and distinquishes between traits and non-traits', function(assert) { @@ -393,11 +442,16 @@ test('create throws errors when using trait that is not defined and distinquishe assert.throws(() => { server.create('article', 'private'); }, /'private' trait is not registered in 'article' factory/); + + server.shutdown(); }); module('Unit | Server #createList', { beforeEach() { this.server = new Server({ environment: 'test' }); + }, + afterEach() { + this.server.shutdown(); } }); @@ -538,6 +592,9 @@ test('createList throws errors when using trait that is not defined and distinqu module('Unit | Server #build', { beforeEach() { this.server = new Server({ environment: 'test' }); + }, + afterEach() { + this.server.shutdown(); } }); @@ -752,6 +809,9 @@ test('build throws errors when using trait that is not defined and distinquishes module('Unit | Server #buildList', { beforeEach() { this.server = new Server({ environment: 'test' }); + }, + afterEach() { + this.server.shutdown(); } }); @@ -898,6 +958,8 @@ test('server configures default passthroughs when useDefaultPassthroughs is true assert.ok(isPassedThrough); }); + + server.shutdown(); }); test('server does not configure default passthroughs when useDefaultPassthroughs is false', function(assert) { @@ -910,4 +972,6 @@ test('server does not configure default passthroughs when useDefaultPassthroughs assert.ok(!isPassedThrough); }); + + server.shutdown(); });