Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"serve-favicon": "^2.0.1",
"source": "0.0.3",
"stream-browserify": "2.0.1",
"supertest": "^1.2.0",
"uglify": "^0.1.5",
"underscore": "1.8.3",
"vinyl-buffer": "^1.0.0",
Expand All @@ -79,7 +80,7 @@
"karma-browserify": "^4.4.0",
"karma-chrome-launcher": "^0.2.1",
"mockery": "^1.4.0",
"supertest": "1.1.0"
"supertest": "^1.2.0"
},
"repository": {
"type": "git",
Expand Down
18 changes: 10 additions & 8 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var loopback = require('loopback');

var app = module.exports = loopback();

app.on('start', function onStart(){
app.on('start', function onStart() {
app.start();
});

app.on('started', function onStarted(){
app.on('started', function onStarted() {
var baseUrl = getUrl(app);
console.log('Web server listening at: %s', baseUrl);
console.log('Get server status at: %s%s', baseUrl, '/status');
Expand All @@ -18,7 +18,7 @@ app.on('started', function onStarted(){
}
});

function getUrl(app){
function getUrl(app) {
if (app.get('url')) {
return app.get('url').replace(/\/$/, '');
} else {
Expand All @@ -33,7 +33,7 @@ function getUrl(app){
* @param options Options used during the boot process
* @param callback
*/
app.boot = function bootServer(options){
app.boot = function bootServer(options) {
var boot = require('loopback-boot');

// Pass boot options to app to allow it to set additional app properties
Expand All @@ -49,12 +49,14 @@ app.boot = function bootServer(options){
*
* @param options Options used override defaults
*/
function getOptions(options){
function getOptions(options) {
// TODO: move to argv module that provides documentation
var argv = require('minimist')(process.argv.slice(2));
var _ = require('underscore');

if (options === undefined) options = {};
if (options === undefined) {
options = {}
}

// Handle common runtime overrides
var cliOptions = {
Expand Down Expand Up @@ -89,8 +91,8 @@ function getOptions(options){
/***
* Starts HTTP server
*/
app.start = function startServer(){
return app.listen(function(){
app.start = function startServer() {
return app.listen(function() {
app.emit('started');
});
};
Expand Down
29 changes: 29 additions & 0 deletions spec/api/apitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const request = require('supertest');
const app = require('../../server/server');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to boot the server in order for the loopback stuff to kick in. Add:

app.boot();

describe('GET /api/proposals', () => {
it('respond with json', (done) => {
request(app)
.get('/api/proposals')
.set('Accept', 'application/json')
.expect('Content-Type', /json/, done)
.expect(200, done);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to test that the response is an array of objects with the correct structure. That may involve creating some test data and then cleaning it up after the test. Ideally you would programmatically associate the proposal model with the memory datasource so don't have to worry about cleaning up the test data.

});
});

describe("POST /api/proposals/submit", () => {
it("Posts a new proposal to /api/proposals", (done) => {
let proposal = {
speakerName: "Danny",
speakerEmail: "danny@pham.com",
talkTitle: "Do this instead of that",
talkDescription: "That is so-so but this, this is revolutionary.",
}
request(app)
.post("/api/proposals/submit")
.send(proposal)
.expect(200, done);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to check the body of the response to make sure it echos what you expected.

});
});