Skip to content

Commit

Permalink
🤓 add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Purvi Kanal committed Jul 18, 2018
1 parent 6f2d638 commit df7d2db
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"author": "",
"devDependencies": {
"jest": "^22.4.4",
"nodemon": "^1.17.5"
"nodemon": "^1.17.5",
"supertest": "^3.1.0"
},
"dependencies": {
"express": "^4.16.3",
Expand All @@ -20,10 +21,18 @@
"winston": "^3.0.0"
},
"nodemonConfig": {
"ignore": ["**/*.test.js", "**/*.spec.js", ".git", "node_modules"]
"ignore": [
"**/*.test.js",
"**/*.spec.js",
".git",
"node_modules"
]
},
"jest": {
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(js)$",
"moduleFileExtensions": ["js", "json"]
"moduleFileExtensions": [
"js",
"json"
]
}
}
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require("express");
const morgan = require("morgan");
const admin = require("firebase-admin");
require("dotenv").config();

const router = require("./api");
const { logger } = require("./utils/logger");
Expand All @@ -28,6 +27,12 @@ app.use("/", router);
app.use(errorHandler);

// Serve the application at the given port
app.listen(port, () => {
logger.info(`🎧 Listening at http://localhost:${port}/`);
});
if (process.env.NODE_ENV !== "test") {
app.listen(port, () => {
logger.info(`🎧 Listening at http://localhost:${port}/`);
});
}

module.exports = {
app
};
12 changes: 12 additions & 0 deletions src/routes/health/health.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const request = require("supertest");

const { healthRouter } = require("./health.router");
const { app } = require("../../index");

describe("tests for the health check endpoint", () => {
it("returns a 200", () => {
return request(app)
.get("/health")
.expect(200);
});
});
48 changes: 39 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ compare-versions@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.2.1.tgz#a49eb7689d4caaf0b6db5220173fd279614000f7"

component-emitter@^1.2.1:
component-emitter@^1.2.0, component-emitter@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"

Expand Down Expand Up @@ -1013,6 +1013,10 @@ [email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"

cookiejar@^2.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c"

copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
Expand Down Expand Up @@ -1204,10 +1208,6 @@ dot-prop@^4.1.0:
dependencies:
is-obj "^1.0.0"

dotenv@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.0.0.tgz#24e37c041741c5f4b25324958ebbc34bca965935"

duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
Expand Down Expand Up @@ -1635,14 +1635,18 @@ forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"

form-data@~2.3.1:
form-data@^2.3.1, form-data@~2.3.1:
version "2.3.2"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099"
dependencies:
asynckit "^0.4.0"
combined-stream "1.0.6"
mime-types "^2.1.12"

formidable@^1.1.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.2.1.tgz#70fb7ca0290ee6ff961090415f4b3df3d2082659"

forwarded@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
Expand Down Expand Up @@ -3012,7 +3016,7 @@ methmeth@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/methmeth/-/methmeth-1.1.0.tgz#e80a26618e52f5c4222861bb748510bd10e29089"

methods@~1.1.2:
methods@^1.1.1, methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"

Expand Down Expand Up @@ -3070,6 +3074,10 @@ [email protected]:
version "1.4.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"

mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"

mime@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-2.3.1.tgz#b1621c54d63b97c47d3cfe7f7215f7d64517c369"
Expand Down Expand Up @@ -3753,7 +3761,7 @@ [email protected]:
version "6.5.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"

qs@~6.5.1:
qs@^6.5.1, qs@~6.5.1:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"

Expand Down Expand Up @@ -3802,7 +3810,7 @@ read-pkg@^1.0.0:
normalize-package-data "^2.3.2"
path-type "^1.0.0"

readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.6:
readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
dependencies:
Expand Down Expand Up @@ -4370,6 +4378,28 @@ stubs@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/stubs/-/stubs-3.0.0.tgz#e8d2ba1fa9c90570303c030b6900f7d5f89abe5b"

[email protected]:
version "3.8.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.8.2.tgz#e4a11b9d047f7d3efeb3bbe536d9ec0021d16403"
dependencies:
component-emitter "^1.2.0"
cookiejar "^2.1.0"
debug "^3.1.0"
extend "^3.0.0"
form-data "^2.3.1"
formidable "^1.1.1"
methods "^1.1.1"
mime "^1.4.1"
qs "^6.5.1"
readable-stream "^2.0.5"

supertest@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/supertest/-/supertest-3.1.0.tgz#f9ebaf488e60f2176021ec580bdd23ad269e7bc6"
dependencies:
methods "~1.1.2"
superagent "3.8.2"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down

0 comments on commit df7d2db

Please sign in to comment.