More false-positive singleton fixes, added singleton teardown test, removed singleton-dependent tests
diff --git a/tests/lib/entity.test.js b/tests/lib/entity.test.js
index 94e69e9..80ae702 100644
--- a/tests/lib/entity.test.js
+++ b/tests/lib/entity.test.js
@@ -279,24 +279,7 @@
this.slow(_slow + 1000)
this.timeout(_timeout + 4000)
- it('should refresh an entity with the latest server copy of itself using the Usergrid shared instance', function(done) {
- var client = new UsergridClient(config),
- now = Date.now()
- client.GET(config.test.collection, function(err, getResponse) {
- var entity = new UsergridEntity(getResponse.first)
- var modified = entity.modified
- getResponse.first.putProperty('reloadSingletonTest', now)
- client.PUT(getResponse.first, function(err, putResponse) {
- entity.reload(function() {
- entity.reloadSingletonTest.should.equal(now)
- entity.modified.should.not.equal(modified)
- done()
- })
- })
- })
- })
-
- it('should refresh an entity with the latest server copy of itself by passing an instance of UsergridClient', function(done) {
+ it('should refresh an entity with the latest server copy of itself', function(done) {
var client = new UsergridClient(config),
now = Date.now()
client.GET(config.test.collection, function(err, getResponse) {
@@ -305,6 +288,7 @@
getResponse.first.putProperty('reloadTest', now)
client.PUT(getResponse.first, function(err, putResponse) {
entity.reload(client, function() {
+ client.isSharedInstance.should.be.false()
entity.reloadTest.should.equal(now)
entity.modified.should.not.equal(modified)
done()
@@ -319,26 +303,14 @@
this.slow(_slow + 1000)
this.timeout(_timeout + 4000)
- it('should save an updated entity to the server using the Usergrid shared instance', function(done) {
- var client = new UsergridClient(config),
- now = Date.now()
- client.GET(config.test.collection, function(err, getResponse) {
- var entity = new UsergridEntity(getResponse.first)
- entity.putProperty('saveSingletonTest', now)
- entity.save(function() {
- entity.saveSingletonTest.should.equal(now)
- done()
- })
- })
- })
-
- it('should save an updated entity to the server by passing an instance of UsergridClient', function(done) {
+ it('should save an updated entity to the server', function(done) {
var client = new UsergridClient(config),
now = Date.now()
client.GET(config.test.collection, function(err, getResponse) {
var entity = new UsergridEntity(getResponse.first)
entity.putProperty('saveTest', now)
entity.save(client, function() {
+ client.isSharedInstance.should.be.false()
entity.saveTest.should.equal(now)
done()
})
@@ -351,30 +323,16 @@
this.slow(_slow + 1000)
this.timeout(_timeout + 4000)
- it('should remove an entity from the server using the Usergrid shared instance', function(done) {
- var client = new UsergridClient(config)
- client.POST(config.test.collection, {
- removeSingletonTest: 'test'
- }, function(err, postResponse) {
- var entity = new UsergridEntity(postResponse.first)
- entity.remove(function(err, deleteResponse) {
- deleteResponse.ok.should.be.true()
- // best practice is to delete the entity object here, because it no longer exists on the server
- entity = null
- done()
- })
- })
- })
-
- it('should remove an entity from the server by passing an instance of UsergridClient', function(done) {
+ it('should remove an entity from the server', function(done) {
var client = new UsergridClient(config)
client.POST(config.test.collection, {
removeTest: 'test'
}, function(err, postResponse) {
var entity = new UsergridEntity(postResponse.first)
entity.remove(client, function(err, deleteResponse) {
+ client.isSharedInstance.should.be.false()
deleteResponse.ok.should.be.true()
- // best practice is to delete the entity object here, because it no longer exists on the server
+ // best practice is to desroy the 'entity' instance here, because it no longer exists on the server
entity = null
done()
})
diff --git a/tests/lib/response.test.js b/tests/lib/response.test.js
index e24f2c5..cb680c5 100644
--- a/tests/lib/response.test.js
+++ b/tests/lib/response.test.js
@@ -179,14 +179,6 @@
})
})
- it('should load a new page of entities using the Usergrid shared instance', function(done) {
- firstResponse.loadNextPage(function(err, usergridResponse) {
- usergridResponse.first.uuid.should.not.equal(firstResponse.first.uuid)
- usergridResponse.entities.length.should.equal(2)
- done()
- })
- })
-
it('should load a new page of entities by passing an instance of UsergridClient', function(done) {
firstResponse.loadNextPage(client, function(err, usergridResponse) {
usergridResponse.first.uuid.should.not.equal(firstResponse.first.uuid)
diff --git a/tests/lib/user.test.js b/tests/lib/user.test.js
index 42e2b35..ddc9abe 100644
--- a/tests/lib/user.test.js
+++ b/tests/lib/user.test.js
@@ -70,7 +70,7 @@
})
})
- it('should create a new user on the server by passing an instance of UsergridClient', function(done) {
+ it('should create a new user on the server', function(done) {
var client = new UsergridClient(config),
username = chance.word()
var user = new UsergridUser({
@@ -78,6 +78,7 @@
password: config.test.password
})
user.create(client, function(err, usergridResponse, user) {
+ client.isSharedInstance.should.be.false()
user.username.should.equal(username)
user.should.have.property('uuid').which.is.a.uuid()
user.should.have.property('created')
diff --git a/tests/lib/usergrid.singleton.test.js b/tests/lib/usergrid.singleton.test.js
index aa74e72..5a1a1ba 100644
--- a/tests/lib/usergrid.singleton.test.js
+++ b/tests/lib/usergrid.singleton.test.js
@@ -3,7 +3,8 @@
var should = require('should'),
Usergrid = require('../../usergrid')
-it('should be initialized when defined in another module', function() {
- Usergrid.isInitialized.should.be.true()
- Usergrid.isSharedInstance.should.be.true()
+it('should be initialized when defined in another module', function(done) {
+ Usergrid.should.have.property('isInitialized').which.is.true()
+ Usergrid.should.have.property('isSharedInstance').which.is.true()
+ done()
})
\ No newline at end of file
diff --git a/tests/lib/usergrid.teardown.test.js b/tests/lib/usergrid.teardown.test.js
new file mode 100644
index 0000000..2b44f69
--- /dev/null
+++ b/tests/lib/usergrid.teardown.test.js
@@ -0,0 +1,15 @@
+'use strict'
+
+var should = require('should'),
+ Usergrid = require('../../usergrid'),
+ UsergridClient = require('../../lib/client')
+
+it('should be destroyed', function(done) {
+ // destroy shared instance to prevent other tests from defaulting to use the shared instance
+ var UsergridRef = require.resolve('../../usergrid')
+ delete require.cache[UsergridRef]
+ Usergrid = require('../../usergrid')
+ Usergrid.should.have.property('isInitialized').which.is.false()
+ Usergrid.should.not.be.an.instanceof(UsergridClient)
+ done()
+})
\ No newline at end of file
diff --git a/tests/lib/usergrid.test.js b/tests/lib/usergrid.test.js
index 001c114..3c1a8fb 100644
--- a/tests/lib/usergrid.test.js
+++ b/tests/lib/usergrid.test.js
@@ -8,13 +8,15 @@
_ = require('lodash')
describe('init() / initSharedInstance()', function() {
- it('should be an instance of UsergridClient', function() {
+ it('should be an instance of UsergridClient', function(done) {
Usergrid.init()
Usergrid.initSharedInstance()
Usergrid.should.be.an.instanceof(UsergridClient)
+ done()
})
- it(util.format('should be testing against a Usergrid v%s instance', config.target), function() {
+ it(util.format('should be testing against a Usergrid v%s instance', config.target), function(done) {
util.format('--target=%s', config.target).should.equal(_.last(process.argv))
+ done()
})
})
\ No newline at end of file
diff --git a/tests/main.test.js b/tests/main.test.js
index f4bc035..83d9e9a 100644
--- a/tests/main.test.js
+++ b/tests/main.test.js
@@ -14,8 +14,6 @@
})
// end module config
-/* skip the following test using describe() in order to validate that
- new tests added pass when the shared instance is not initialized */
describe('Usergrid', function() {
return require('./lib/usergrid.test')
})
@@ -24,6 +22,10 @@
return require('./lib/usergrid.singleton.test')
})
+describe('Usergrid teardown', function() {
+ return require('./lib/usergrid.teardown.test')
+})
+
describe('UsergridClient initialization', function() {
return require('./lib/client.init.test')
})
diff --git a/usergrid.js b/usergrid.js
index eb5eb5f..330fffa 100644
--- a/usergrid.js
+++ b/usergrid.js
@@ -3,6 +3,8 @@
var UsergridClient = require('./lib/client')
var Usergrid = {
+ isInitialized: false,
+ isSharedInstance: true,
initSharedInstance: function(options) {
var self = this
if (self.isInitialized) {