From 0fe1c4428776f083b32fa1d7bd033ffa18daa618 Mon Sep 17 00:00:00 2001 From: Eric Lang Date: Sun, 7 Nov 2021 15:20:20 -0500 Subject: [PATCH] Test driven development. (#41) --- server/package.json | 22 ++++++++++++++-------- server/routes/api/index.js | 2 ++ server/routes/api/v2.js | 2 +- server/routes/test/v2.js | 11 +++++++++++ server/run.sh | 0 server/server.js | 12 ++++++++---- 6 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 server/routes/api/index.js create mode 100644 server/routes/test/v2.js mode change 100644 => 100755 server/run.sh diff --git a/server/package.json b/server/package.json index f021d3b..5951414 100644 --- a/server/package.json +++ b/server/package.json @@ -1,28 +1,34 @@ { "name": "github-graphs", - "version": "0.0.1", + "version": "0.0.2", "description": "Generates graphs of github things.", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls", + "test": "mocha routes/test --exit --reporter spec", "start": "node server.js" }, "repository": { "type": "git", "url": "git+https://github.com/jrtechs/github-graphs.git" }, - "author": "Jeffery Russell", + "author": "Jeffery Russell, Eric Lang", "license": "ISC", "bugs": { "url": "https://github.com/jrtechs/github-graphs/issues" }, "homepage": "https://github.com/jrtechs/github-graphs#readme", "dependencies": { - "dotenv": "^8.2.0", - "express": "^4.16.4", - "express-session": "^1.15.6", + "dotenv": "~8.2.0", + "express": "~4.16.4", + "express-session": "~1.15.6", "fs": "0.0.1-security", - "got": "^9.6.0", - "memory-cache": "^0.2.0" + "got": "~9.6.0", + "memory-cache": "~0.2.0" + }, + "devDependencies": { + "coveralls": "*", + "mocha": "*", + "nyc": "*" } } diff --git a/server/routes/api/index.js b/server/routes/api/index.js new file mode 100644 index 0000000..864dc35 --- /dev/null +++ b/server/routes/api/index.js @@ -0,0 +1,2 @@ +exports.V1 = require('./v1'); +exports.V2 = require('./v2'); \ No newline at end of file diff --git a/server/routes/api/v2.js b/server/routes/api/v2.js index 4e17a72..b71a463 100644 --- a/server/routes/api/v2.js +++ b/server/routes/api/v2.js @@ -307,4 +307,4 @@ routes.get('/*', (request, result) => } }); -module.exports = routes; \ No newline at end of file +module.exports = routes; diff --git a/server/routes/test/v2.js b/server/routes/test/v2.js new file mode 100644 index 0000000..1a940c9 --- /dev/null +++ b/server/routes/test/v2.js @@ -0,0 +1,11 @@ +const assert = require('assert'); +const V2 = require('../api/v2'); + +describe('github api v2', function() { + it('successfully queries friends', async function() { + var queryFriends = V2.queryFriends; + // it was this point that Eric realized he doesn't understand + // module.exports very well. + assert.strictEqual(typeof(queryFriends), typeof(queryFriends)); + }); +}); \ No newline at end of file diff --git a/server/run.sh b/server/run.sh old mode 100644 new mode 100755 diff --git a/server/server.js b/server/server.js index b99e1e7..f80ec48 100644 --- a/server/server.js +++ b/server/server.js @@ -1,10 +1,14 @@ +const crypto = require('crypto'); + +const app = express(); + +const dotenv = require("dotenv").config(); const express = require("express"); const session = require('express-session'); -const dotenv = require("dotenv").config(); -const app = express(); + const sessionProperties = { - secret: process.env.SESSION_SECRET, + secret: process.env.SESSION_SECRET || crypto.randomBytes(64), cookie: { maxAge: 6000000 }, resave: false, saveUninitialized: false @@ -18,4 +22,4 @@ const routes = require('./routes'); app.use('/', routes); -app.listen(process.env.PORT, () => console.log(`App listening on port ${process.env.PORT}!`)); \ No newline at end of file +app.listen(process.env.PORT || 8100, () => console.log(`App listening on port ${process.env.PORT || 8100}!`)); \ No newline at end of file