forked from angular-app/angular-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): replace "restler" with "request" to solve bug with node …
…0.10.0
- Loading branch information
1 parent
847cc83
commit 46eafb9
Showing
6 changed files
with
40 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var config = require('./config.js'); | ||
var rest = require('restler'); | ||
var rest = require('request'); | ||
var apiKey = config.mongo.apiKey; | ||
var baseUrl = config.mongo.dbUrl + '/databases/' + config.security.dbName + '/collections/'; | ||
|
||
|
@@ -9,19 +9,20 @@ var checkDocument = function(collection, query, done) { | |
var url = baseUrl + collection + '/'; | ||
console.log(url); | ||
var params = { apiKey:apiKey, q: JSON.stringify(query) }; | ||
var request = rest.get(url, { query: params }); | ||
request.on('error', function(err, response) { console.log('error', err, response); done(err, null); }); | ||
request.on('fail', function(err, response) { console.log('fail', err, response); done(err, null); }); | ||
request.on('success', function(data) { console.log('success', data); done(null, data); }); | ||
var request = rest.get(url, { qs: params, json: {} }, function(err, response, data) { | ||
done(null, data); | ||
}); | ||
}; | ||
|
||
var createDocument = function(collection, document, done) { | ||
var url = baseUrl + collection + '/?apiKey=' + apiKey; | ||
var createDocument = function(collection, doc, done) { | ||
var url = baseUrl + collection + '/'; | ||
console.log(url); | ||
var request = rest.postJson(url, document); | ||
request.on('error', function(err, response) { console.log('error', err, response); done(err, null); }); | ||
request.on('fail', function(err, response) { console.log('fail', err, response); done(err, null); }); | ||
request.on('success', function(data) { console.log('success', data); done(null, data); }); | ||
var request = rest.post(url, { qs: { apiKey:apiKey }, json: doc }, function(err, response, data) { | ||
if ( !err ) { | ||
console.log('Document created', data); | ||
} | ||
done(err, data); | ||
}); | ||
}; | ||
|
||
var adminUser = { email: '[email protected]', password: 'changeme', admin: true}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,10 @@ var config = { | |
// so that we don't have to actually call out to the server - Yay!! | ||
function mockupRestInterface(test, expectedUrl, expectedOptions, expectedEvent, expectedResult) { | ||
MongoDBStrategy.__set__('rest', { | ||
get: function(url, options) { | ||
get: function(url, options, callback) { | ||
test.equal(url, expectedUrl, 'rest.get fn received invalid parameter'); | ||
test.deepEqual(options, expectedOptions, 'rest.get fn received invalid parameter'); | ||
return { | ||
on: function(eventString, callback) { | ||
if ( eventString === expectedEvent ) { | ||
callback(expectedResult); | ||
} | ||
} | ||
}; | ||
callback(null, null, expectedResult); | ||
} | ||
}); | ||
} | ||
|
@@ -39,7 +33,7 @@ var baseUrl = config.dbUrl + '/databases/' + config.dbName + '/collections/' + c | |
|
||
module.exports = { | ||
testGet: function(test) { | ||
mockupRestInterface(test, baseUrl + config.testId, { query: { apiKey: config.apiKey }}, 'success', config.testUser); | ||
mockupRestInterface(test, baseUrl + config.testId, { json: {}, qs: { apiKey: config.apiKey }}, 'success', config.testUser); | ||
|
||
var db = new MongoDBStrategy(config.dbUrl, config.apiKey, 'ascrum', 'users'); | ||
db.get(config.testId, function(err, result) { | ||
|
@@ -52,7 +46,7 @@ module.exports = { | |
|
||
testFindByEmail_found: function(test) { | ||
var db = new MongoDBStrategy(config.dbUrl, config.apiKey, 'ascrum', 'users'); | ||
mockupRestInterface(test, baseUrl, { query: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', [config.testUser]); | ||
mockupRestInterface(test, baseUrl, { json: {}, qs: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', [config.testUser]); | ||
db.findByEmail('[email protected]', function(err, result) { | ||
test.ok(!err); | ||
test.ok(result !== null); | ||
|
@@ -64,7 +58,7 @@ module.exports = { | |
|
||
testFindByEmail_notfound: function(test) { | ||
var db = new MongoDBStrategy(config.dbUrl, config.apiKey, 'ascrum', 'users'); | ||
mockupRestInterface(test, baseUrl, { query: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', []); | ||
mockupRestInterface(test, baseUrl, { json: {}, qs: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', []); | ||
db.findByEmail('[email protected]', function(err, result) { | ||
test.ok(!err); | ||
test.ok(result === null); | ||
|
@@ -73,7 +67,7 @@ module.exports = { | |
}, | ||
|
||
testVerifyUser: function(test) { | ||
mockupRestInterface(test, baseUrl, { query: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', [config.testUser]); | ||
mockupRestInterface(test, baseUrl, { json: {}, qs: { apiKey: config.apiKey, q: JSON.stringify({email:"[email protected]"}) }}, 'success', [config.testUser]); | ||
var db = new MongoDBStrategy(config.dbUrl, config.apiKey, 'ascrum', 'users'); | ||
db.verifyUser('[email protected]', 'XX', function(err, user) { | ||
test.ok(!err); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters