-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
4f3b1e6
commit 72d1856
Showing
11 changed files
with
776 additions
and
37 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
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,14 @@ | ||
require('simple-console-colors'); | ||
const express = require("express"); | ||
const routes = require("./routes"); | ||
const app = express(); | ||
|
||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
if (process.env.NODE_ENV === "production") | ||
app.use(express.static("client/build")); | ||
|
||
app.use(routes); | ||
|
||
module.exports = app; |
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
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
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,3 @@ | ||
module.exports = { | ||
testEnvironment: 'node' | ||
}; |
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const router = require("express").Router(); | ||
const testController = require("../../controllers/testController"); | ||
|
||
router | ||
.route("/") | ||
.get(testController.findAll) | ||
router.route("/") | ||
.get(testController.testRoute); | ||
|
||
router.route('/db') | ||
.get(testController.findAll); | ||
|
||
module.exports = router; |
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
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 |
---|---|---|
@@ -1,19 +1,8 @@ | ||
require('simple-console-colors'); | ||
const express = require("express"); | ||
const routes = require("./routes"); | ||
const server = express(); | ||
const app = require('./app') | ||
const PORT = process.env.PORT || 3001; | ||
const mongooseConnect = require("./dbconfig/connection.js"); | ||
const mongooseConnection = require("./dbconfig/connection.js"); | ||
|
||
server.use(express.urlencoded({ extended: true })); | ||
server.use(express.json()); | ||
|
||
if (process.env.NODE_ENV === "production") | ||
server.use(express.static("client/build")); | ||
|
||
server.use(routes); | ||
|
||
server.listen(PORT, () => { | ||
app.listen(PORT, () => { | ||
console.log(`Server running on PORT ${PORT}!`); | ||
mongooseConnect(); | ||
mongooseConnection.connect(); | ||
}); |
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,29 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
const mongooseConnection = require("../dbconfig/connection.js"); | ||
|
||
describe('Test the api route', () => { | ||
it('Should 200 the GET method', async () => { | ||
const response = await request(app).get('/api/test'); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
it('Should 404 a random route', async () => { | ||
const response = await request(app).get('/api/nonExistentRoute'); | ||
expect(response.statusCode).toBe(404); | ||
}); | ||
}) | ||
|
||
describe('Test the database route', () => { | ||
beforeAll(() => { | ||
return mongooseConnection.connect(); | ||
}); | ||
afterAll(() => { | ||
return mongooseConnection.disconnect(); | ||
}); | ||
|
||
it('Should return documents from the db test route', async () => { | ||
const response = await request(app).get('/api/test/db'); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.body).not.toBeNull(); | ||
}); | ||
}) |
Oops, something went wrong.