Added first passing tests for Usergrid.GET
diff --git a/lib/client.js b/lib/client.js
index d13a1b2..06f61dc 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -2,7 +2,9 @@
var UsergridRequest = require('./request'),
ok = require('objectkit'),
- helpers = require('../helpers')
+ helpers = require('../helpers'),
+ config = require('../package.json'),
+ urljoin = require('url-join');
var UsergridClient = function(orgId, appId) {
var self = this
@@ -15,19 +17,27 @@
}
}
-UsergridClient.prototype.GET = function(uri, options, callback) {
+UsergridClient.prototype.GET = function(type, options, callback) {
+ callback = callback || options
+ var uri = urljoin(config.usergrid.baseUrl, this.orgId, this.appId, type)
return new UsergridRequest('GET', uri, options, callback)
}
-UsergridClient.prototype.PUT = function(uri, options, callback) {
+UsergridClient.prototype.PUT = function(type, options, callback) {
+ callback = callback || options
+ var uri = urljoin(config.usergrid.baseUrl, this.orgId, this.appId, type)
return new UsergridRequest('PUT', uri, options, callback)
}
-UsergridClient.prototype.POST = function(uri, options, callback) {
+UsergridClient.prototype.POST = function(type, options, callback) {
+ callback = callback || options
+ var uri = urljoin(config.usergrid.baseUrl, this.orgId, this.appId, type)
return new UsergridRequest('POST', uri, options, callback)
}
-UsergridClient.prototype.DELETE = function(uri, options, callback) {
+UsergridClient.prototype.DELETE = function(type, options, callback) {
+ callback = callback || options
+ var uri = urljoin(config.usergrid.baseUrl, this.orgId, this.appId, type)
return new UsergridRequest('DELETE', uri, options, callback)
}
diff --git a/package.json b/package.json
index 3dfcf59..268b839 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"underscore": "",
"underscore.inflection": "",
"underscore.string": "",
+ "url-join": "",
"volos-analytics-apigee": "",
"volos-analytics-common": "",
"volos-analytics-memory": "",
@@ -33,5 +34,12 @@
"start": "node app.js",
"test": "mocha tests"
},
+ "usergrid": {
+ "appId": "sandbox",
+ "baseUrl": "https://api.usergrid.com",
+ "clientId": "YXA6GXSAACS2EeOYd20aP4G6Lw",
+ "clientSecret": "YXA66BeEvgNpJBwc4PAbvZZGTVS_SSw",
+ "orgId": "brandon.apigee"
+ },
"version": "2.0.0"
}
\ No newline at end of file
diff --git a/tests/config.js b/tests/config.js
deleted file mode 100644
index 8b64f4c..0000000
--- a/tests/config.js
+++ /dev/null
@@ -1,4 +0,0 @@
-module.exports = {
- clientId: "YXA6GXSAACS2EeOYd20aP4G6Lw",
- clientSecret: "YXA66BeEvgNpJBwc4PAbvZZGTVS_SSw"
-}
\ No newline at end of file
diff --git a/tests/usergrid.js b/tests/usergrid.js
index 9d767cc..a7dae92 100644
--- a/tests/usergrid.js
+++ b/tests/usergrid.js
@@ -3,37 +3,52 @@
var should = require('should')
var ok = require('objectkit')
-var config = require('./config')
+var config = require('../package.json')
var Usergrid = require('../usergrid')
var UsergridClient = require('../lib/client')
describe('Usergrid', function() {
- it('should fail to initialize without a client ID and secret', function() {
+ it('should fail to initialize without an orgId and appId', function() {
should(function() {
Usergrid.initialize()
}).throw()
})
- it('should initialize when using a client ID and secret', function(done) {
- Usergrid.initialize(config.clientId, config.clientSecret)
+ it('should initialize when using an orgId and appId', function(done) {
+ Usergrid.initialize(config.usergrid.orgId, config.usergrid.appId)
+ Usergrid.orgId.should.equal(config.usergrid.orgId)
+ Usergrid.appId.should.equal(config.usergrid.appId)
Usergrid.should.be.ok
done()
})
});
+describe('Usergrid.GET', function() {
+
+ this.slow(1000)
+ this.timeout(6000)
+
+ it('should make a GET call to usergrid and retrieve entities', function(done) {
+ Usergrid.GET('tests', {
+ headers: {
+ 'User-Agent': 'request'
+ }
+ }, function(err, usergridResponse) {
+ usergridResponse.statusCode.should.equal(200)
+ usergridResponse.entities.should.be.an.instanceOf(Array)
+ usergridResponse.first.should.be.an.instanceOf(Object)
+ usergridResponse.last.should.be.an.instanceOf(Object)
+ usergridResponse.first.uuid.should.be.an.instanceOf(String)
+ usergridResponse.last.uuid.should.be.an.instanceOf(String)
+ done()
+ })
+ })
+})
// Usergrid.init('peter', 'frog')
// var client = new UsergridClient('bob', 'joe')
-// Usergrid.GET("https://api.usergrid.com/brandon.apigee/sandbox/tests", {
-// headers: {
-// 'User-Agent': 'request'
-// }
-// }, function(err, usergridResponse) {
-// console.log('test1', usergridResponse.entities.length);
-// console.log('test2', usergridResponse.first.uuid);
-// console.log('test3', usergridResponse.last.uuid);
-// })
+
// Usergrid.POST("https://api.usergrid.com/brandon.apigee/sandbox/tests", {
// headers: {