-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
btidwell
committed
Apr 10, 2015
1 parent
3721152
commit 482f1b8
Showing
8 changed files
with
188 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
REPORTER = nyan | ||
MOCHA=node_modules/.bin/mocha | ||
ISTANBUL=node_modules/.bin/istanbul | ||
TESTS=$(shell find test/unit -name "*spec.js") | ||
|
||
coverage: | ||
@test -d reports || mkdir reports | ||
$(ISTANBUL) instrument --output controllers-cov controllers | ||
$(ISTANBUL) instrument --output services-cov services | ||
mv controllers controllers-orig && mv controllers-cov controllers | ||
mv services services-orig && mv services-cov services | ||
ISTANBUL_REPORTERS=lcovonly $(MOCHA) -R mocha-istanbul $(TESTS) | ||
mv lcov.info reports/ | ||
rm -rf controllers | ||
rm -rf services | ||
mv controllers-orig controllers | ||
mv services-orig services | ||
genhtml reports/lcov.info --output-directory reports/ | ||
|
||
clean: | ||
rm -rf reports | ||
|
||
test: | ||
@NODE_ENV=test ./node_modules/.bin/mocha --recursive \ | ||
--reporter $(REPORTER) | ||
|
||
.PHONY: test |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "http://github.com/btidwell/pencilblue_facebook.git" | ||
}, | ||
"dependencies": { | ||
"fb": "0.7.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"mocha": "^2.1.0", | ||
"sinon": "^1.12.2", | ||
"istanbul": "^0.3.7", | ||
"mocha-istanbul": "^0.2.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var sinon = require('sinon'); | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var mockService = require('../test/helpers/pb_mock_service'); | ||
var FeedControllerModule = require('../controllers/feed'); | ||
var OauthService = require('../test/helpers/oauth_service_mock'); | ||
var PostsService = require('../test/helpers/posts_service_mock'); | ||
|
||
describe('When using the Feed Controller', function(){ | ||
var pb; | ||
var FeedController; | ||
var expectedJSON; | ||
before(function(){ | ||
pb = mockService.getMockPB(); | ||
FeedController = FeedControllerModule(pb); | ||
expectedJSON = '{data:[{id:"mockid",message:"Mock Message", created_time:"2015-04-09T16:00:04+0000"}]}'; | ||
var oauthStub = sinon.stub(OauthService, 'getAccessToken'); | ||
var postsStub = sinon.stub(PostsService, 'getPagePosts'); | ||
oauthStub.onCall(0).yields('mockaccesstoken'); | ||
postsStub.onCall(0).yields(null, expectedJSON); | ||
}); | ||
|
||
it('We should expect a JSON response from the request handler getPosts', function(done){ | ||
var feedController = new FeedController(); | ||
feedController.getPagePosts(function(err, result){ | ||
expect(result).to.equal(expectedJSON); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('We should expect a public GET route for getPosts handler with a content_type of application/json', function(done){ | ||
FeedController.getRoutes(function(err, routes){ | ||
expect(routes.length).to.equal(1); | ||
var route = routes[0]; | ||
expect(route.method).to.equal('get'); | ||
expect(route.path).to.equal('/action/facebook/posts'); | ||
expect(route.auth_required).to.equal(false); | ||
expect(route.content_type).to.equal('application/json'); | ||
expect(route.handler).to.equal('getPagePosts'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function BaseController(){}; | ||
|
||
BaseController.prototype.init = function(props, cb) { | ||
var self = this; | ||
cb(); | ||
}; | ||
|
||
BaseController.prototype.getPostParams = function(cb) { | ||
cb(null, null); | ||
}; | ||
|
||
/** | ||
* Parses the incoming payload of a request as JSON formatted data. | ||
* @method getJSONPostParams | ||
* @param {Function} cb | ||
*/ | ||
BaseController.prototype.getJSONPostParams = function(cb) { | ||
cb(null, null); | ||
}; | ||
|
||
BaseController.prototype.redirect = function(url, cb) { | ||
cb(url); | ||
}; | ||
|
||
BaseController.apiResponse = function(cd, msg, dta) { | ||
|
||
return JSON.stringify("nothing"); | ||
}; | ||
|
||
//exports | ||
module.exports.BaseController = BaseController; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function OauthService(){} | ||
|
||
OauthService.getName = function(){ | ||
return "oauthService"; | ||
}; | ||
|
||
OauthService.getAccessToken = function(cb){ | ||
cb('mockaccesstoken'); | ||
}; | ||
|
||
module.exports = OauthService; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var PluginService = require("./plugin_service_mock"); | ||
var BaseController = require('./mock_base_controller'); | ||
var util = require("util"); | ||
module.exports.getMockPB = function(){ | ||
return { | ||
config: { | ||
sitePort:'8080', | ||
siteRoot:'http://dev.careerbuildercareers.com:8080', | ||
crawler:{ | ||
maxConcurrency: 10 | ||
} | ||
}, | ||
log:{ | ||
silly:function(message){log(message);}, | ||
info:function(message){log(message);}, | ||
error:function(message){log(message);}, | ||
debug:function(message){log(message);} | ||
}, | ||
PluginService: PluginService, | ||
BaseController: BaseController.BaseController, | ||
util : util | ||
}; | ||
}; | ||
function log(message){ | ||
//console.log is commented out unless a debug of pb.log messages is needed. | ||
//console.log(message); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var OauthService = require('./oauth_service_mock'); | ||
var PostsService = require('./posts_service_mock'); | ||
function PluginService() {} | ||
|
||
PluginService.prototype.getSettingsKV = function(pluginName, cb){ | ||
cb(null, { | ||
app_id: 'mockappid', | ||
app_secret: 'mockappsecret', | ||
facebook_page_id: 'mockpageid' | ||
}); | ||
}; | ||
|
||
PluginService.getService = function(serviceName, pluginName){ | ||
if(serviceName === OauthService.getName()){ | ||
return OauthService; | ||
} | ||
else if(serviceName === PostsService.getName()){ | ||
return PostsService; | ||
} | ||
}; | ||
|
||
module.exports = PluginService; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function PostsService(){} | ||
|
||
PostsService.getName = function(){ | ||
return "postsService"; | ||
}; | ||
|
||
PostsService.getPagePosts = function(cb){ | ||
cb('{}'); | ||
}; | ||
|
||
module.exports = PostsService; |