Skip to content

Commit

Permalink
integration tests for api and database SirSeim#29
Browse files Browse the repository at this point in the history
  • Loading branch information
cf7 committed Apr 4, 2017
1 parent 4d04cb9 commit 9b9717d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
es6: true
rules:
no-extra-parens:
error
off
curly:
error
eqeqeq:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"start": "if [ -f $(npm bin)/../../.env ]; then node server.js; else node server.js; fi;",
"nodemon": "nodemon -e js,json,html,css server.js",
"test": "mocha --recursive --require mocha-istanbul 'test' && istanbul report text-summary lcov",
"test": "npm run db-stop; $(npm bin)/../../test/test_db.sh; NODE_ENV=test mocha --recursive --require mocha-istanbul 'test' && istanbul report text-summary lcov;",
"travis-test": "mocha --recursive --require mocha-istanbul 'test' && istanbul report text-summary lcov",
"lint": "eslint server.js **/*.js",
"report": "istanbul report",
Expand Down
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ var url = require('url');

var setup = {
host: process.env.NODE_ENV === "production" ? "0.0.0.0" : "localhost",
port: process.env.PORT || "8080"
port: (process.env.NODE_ENV === "test" ? process.env.TEST_PORT : process.env.PORT) || "8080"
};
var Api = require(Path.join(__dirname, 'routes/api_routes.js'));
var viewRoutes = require(Path.join(__dirname, 'routes/view_routes.js'));

var postgresqlPool = {
register: function (server, options, next) {
var params = url.parse(process.env.DATABASE_URL);
var params = url.parse(process.env.NODE_ENV === "test" ? process.env.DATABASE_URL_TEST : process.env.DATABASE_URL);
var auth = params.auth.split(':');

var dbconfig = {
Expand Down Expand Up @@ -148,7 +148,7 @@ SPY.register({

SPY.start(function () {
SPY.log(['info', 'SPY'], "Server started on " + setup.host + ":" + setup.port);
SPY.log(['info', 'SPY'], process.env.DATABASE_URL);
SPY.log(['info', 'SPY'], (process.env.NODE_ENV === "test" ? process.env.DATABASE_URL_TEST : process.env.DATABASE_URL));
});

module.exports = SPY;
4 changes: 3 additions & 1 deletion test/hello_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var expect = chai.expect;
var request = require('supertest');
var SPY = require('../server.js');

console.log(process.env.NODE_ENV);

describe("Hello", function() {
it("tests the Testing", function (done) {
expect("hello").to.eql("hello");
Expand All @@ -13,7 +15,7 @@ describe("Hello", function() {
});

// can use supertest
describe("Server", function() {
describe("API Routes", function() {
var localStorage = {};

it("tests the server", function (done) {
Expand Down
8 changes: 4 additions & 4 deletions test/test_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ rm -rf log;
mkdir db;
mkdir log;
echo 'Initializing db';
initdb db;
pg_ctl -D db -l log/postgres.log start;
initdb $(npm bin)/../../db;
pg_ctl -D $(npm bin)/../../db -l $(npm bin)/../../log/postgres.log start;
sleep 4;
psql -f ../config/create_spy_test.sql -d postgres; # need to create the new database from within the default postgres database that is initialized first
psql -f ../db_setup/db.sql -d spy_test;
psql -f $(npm bin)/../../config/create_spy_test.sql -d postgres; # need to create the new database from within the default postgres database that is initialized first
psql -f $(npm bin)/../../db_setup/db.sql -d spy_test;

# connect as spy_tester
# $ psql -d spy_test -U spy_tester

0 comments on commit 9b9717d

Please sign in to comment.