Skip to content

Commit 675bca0

Browse files
committed
Tests
Type: Testing Implemented two tests
1 parent 7bf1c6b commit 675bca0

17 files changed

+2159
-3602
lines changed

__test__/client_formCheck.test.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

__test__/server_consultTrip.test.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

__test__/server_geonameAPI.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import regeneratorRuntime from "regenerator-runtime/runtime";
2+
let geonameAPI = require ("../src/server/geonameAPI.js");
3+
4+
const mockResponse = {
5+
"longitude":"13.41053",
6+
"latitude":"52.52437"
7+
};
8+
9+
const city = "Berlin";
10+
11+
12+
//Setup adapted from https://medium.com/fernandodof/how-to-mock-fetch-calls-with-jest-a666ae1e7752
13+
14+
global.fetch = jest.fn(() => Promise.resolve({
15+
json: () => Promise.resolve(mockResponse)
16+
}));
17+
18+
describe('Mock geonameAPI', () => {
19+
let testgeonameApi;
20+
21+
describe('When the city is posted to the geoname server for the api call', () => {
22+
beforeEach(async () => {
23+
testgeonameApi = await geonameAPI(city);
24+
});
25+
26+
it('Then the mockResponse JSON object should be returned', () => {
27+
expect(testgeonameApi).toMatchObject(mockResponse);
28+
});
29+
});
30+
});

package-lock.json

Lines changed: 2073 additions & 3493 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
"name": "example-project",
33
"version": "1.0.0",
44
"main": "index.js",
5+
"jest": {
6+
"globals": {
7+
"combinedApiResponseJSON": {}
8+
},
9+
"setupFiles": [
10+
"dotenv/config"
11+
]
12+
},
513
"scripts": {
614
"test": "jest",
715
"start": "node src/server/index.js",
@@ -13,14 +21,20 @@
1321
"license": "ISC",
1422
"description": "",
1523
"dependencies": {
24+
"babel-jest": "^25.5.1",
1625
"body-parser": "^1.19.0",
1726
"cors": "^2.8.5",
1827
"dotenv": "^8.0.0",
1928
"express": "^4.17.1",
29+
"express-mocks-http": "0.0.11",
2030
"form-data": "^2.3.3",
31+
"jest": "^24.9.0",
2132
"node-fetch": "^2.6.0",
33+
"regenerator-runtime": "^0.13.5",
34+
"supertest": "^5.0.0-0",
2235
"webpack": "^4.35.3",
23-
"webpack-cli": "^3.3.5"
36+
"webpack-cli": "^3.3.5",
37+
"workbox-webpack-plugin": "^5.1.3"
2438
},
2539
"devDependencies": {
2640
"@babel/core": "^7.5.4",
@@ -29,7 +43,6 @@
2943
"clean-webpack-plugin": "^3.0.0",
3044
"css-loader": "^3.6.0",
3145
"html-webpack-plugin": "^3.2.0",
32-
"jest": "^27.4.5",
3346
"mini-css-extract-plugin": "^0.9.0",
3447
"node-sass": "^4.14.1",
3548
"optimize-css-assets-webpack-plugin": "^6.0.1",

src/client/js/globalVariables.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/client/js/results.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/client/views/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ <h2>
281281

282282
<!-- L2 Step 8 -->
283283
<script type="text/javascript" src="../../../dist/main.js"></script>
284-
<!--
285284
<script>
286285
// Check that service workers are supported
287286
if ('serviceWorker' in navigator) {
@@ -291,7 +290,5 @@ <h2>
291290
});
292291
}
293292
</script>
294-
-->
295-
296293
</body>
297294
</html>

src/server/consultTrip.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Consulting a specific trip from when you click a link on the saved trip log on the client side
22

3-
let consultTrip = function (req, res) {
3+
function consultTrip(req, res) {
44
console.log("::::::::: Inside consultTrip :::::::");
55
// Create an empty object
66
let tripLogId = {};
77
tripLogId = req.body;
88

9+
console.log(req.body);
10+
console.log(tripLogId);
11+
912
// Extract the Trip ID
1013
let consultTripId = tripLogId.tripId;
1114
console.log("tripID: " + consultTripId);
@@ -21,4 +24,3 @@ let consultTrip = function (req, res) {
2124
};
2225

2326
module.exports = consultTrip;
24-

src/server/deleteSaved.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Deleting trip from database
2-
let deleteSaved = function(req, res){
2+
function deleteSaved(req, res){
33

44
let delTripId = req.body.tripId;
55

0 commit comments

Comments
 (0)