forked from Brunastephane/MLA-pilot
-
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.
Activity tracking tests for endpoints (#25)
* tests for /exercises endpoint - installing jest and supertest - configuring jest - configuring server to close after tests - updating /exercises/add api to return exercise object created * adding step to run tests for activity tracking - includes temp changes to run build pipeline after pushing to this branch * forgot to install packages before running test * using npm ci instead * to trigger build on push * triggering test with changes to activity tracking * cleaning up the activity tracking workflow file and triggering a build * added delete endpoint for weekly targets for testing * removed redundant lines from delete exercises test * tests for /targets endpoints * removing temporary feature branch push trigger from activity tracking workflow
- Loading branch information
1 parent
5925e99
commit db0fa9c
Showing
8 changed files
with
808 additions
and
7,877 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,90 @@ | ||
const mongoose = require('mongoose'); | ||
const request = require('supertest'); | ||
const { app, server } = require('../server'); | ||
require("dotenv").config; | ||
|
||
const username = "testuser" | ||
const today = new Date() | ||
|
||
const exerciseToAdd = { | ||
username: username, | ||
exerciseType: "Running", | ||
description: " ", | ||
duration: 100, | ||
distance: 10, | ||
date: today | ||
} | ||
|
||
const exerciseToUpdate = { | ||
username: username, | ||
exerciseType: "Running", | ||
description: " ", | ||
duration: 15, | ||
distance: 1.5, | ||
date: today | ||
} | ||
|
||
let exerciseId = " " | ||
|
||
afterAll(async () => { | ||
await server.close() | ||
await mongoose.connection.close() | ||
}); | ||
|
||
describe("GET /exercises/", () => { | ||
it("should return all exercises", async () => { | ||
return request(app) | ||
.get("/exercises/") | ||
.expect('Content-Type', /json/) | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
}) | ||
}); | ||
}); | ||
|
||
describe("POST /exercises/add", () => { | ||
test("should create a new exercise", async () => { | ||
return request(app) | ||
.post("/exercises/add") | ||
.send(exerciseToAdd) | ||
.expect(200) | ||
.then(({ body }) => { | ||
exerciseId = body.data._id | ||
expect(body.data.duration).toBe(exerciseToAdd.duration) | ||
expect(body.data.distance).toBe(exerciseToAdd.distance) | ||
}) | ||
}); | ||
}); | ||
|
||
describe("GET /exercises/:id", () => { | ||
test("should get exercise for an id", async () => { | ||
return request(app) | ||
.get(`/exercises/${exerciseId}`) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
}); | ||
}); | ||
|
||
describe("PUT /exercises/update/:id", () => { | ||
test("should update an existing exercise", async () => { | ||
return request(app) | ||
.put(`/exercises/update/${exerciseId}`) | ||
.send(exerciseToUpdate) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body.exercise._id).toBe(exerciseId) | ||
expect(body.exercise.duration).toBe(exerciseToUpdate.duration) | ||
expect(body.exercise.distance).toBe(exerciseToUpdate.distance) | ||
}) | ||
}); | ||
}); | ||
|
||
describe("DELETE /exercises/:id", () => { | ||
test("should delete an exercise for given id", async () => { | ||
return request(app) | ||
.delete(`/exercises/${exerciseId}`) | ||
.expect(200) | ||
}); | ||
}); | ||
|
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,83 @@ | ||
const mongoose = require('mongoose'); | ||
const request = require('supertest'); | ||
const moment = require('moment') | ||
const { app, server } = require('../server'); | ||
require("dotenv").config; | ||
|
||
const username = "test" | ||
const weekStartDate = moment().startOf('week').toDate() | ||
console.log(weekStartDate) | ||
const weeklyTargetToAdd = { | ||
username: username, | ||
runningTarget: 10, | ||
cyclingTarget: 20, | ||
swimmingTarget: 0, | ||
gymTarget: 100, | ||
otherTarget: 0, | ||
weekStartDate: weekStartDate | ||
} | ||
|
||
const weeklyTargetToUpdate = { | ||
username: username, | ||
runningTarget: 10, | ||
cyclingTarget: 45, | ||
swimmingTarget: 10, | ||
gymTarget: 60, | ||
otherTarget: 0, | ||
weekStartDate: weekStartDate | ||
} | ||
|
||
let weeklyTargetId = " " | ||
|
||
afterAll(async () => { | ||
await server.close() | ||
await mongoose.connection.close() | ||
}); | ||
|
||
describe("GET /targets/", () => { | ||
it("should return all weekly targets", async () => { | ||
return request(app) | ||
.get("/targets/") | ||
.expect('Content-Type', /json/) | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.statusCode).toBe(200); | ||
}) | ||
}); | ||
}); | ||
|
||
describe("POST /targets/add", () => { | ||
test("should create a new weekly target", async () => { | ||
return request(app) | ||
.post("/targets/add") | ||
.send(weeklyTargetToAdd) | ||
.expect(201) | ||
.then(({ body }) => { | ||
weeklyTargetId = body._id | ||
expect(body.username).toBe(username) | ||
expect(body.runningTarget).toBe(weeklyTargetToAdd.runningTarget) | ||
}) | ||
}); | ||
}); | ||
|
||
describe("PATCH /targets/update", () => { | ||
test("should create a new weekly target", async () => { | ||
return request(app) | ||
.patch("/targets/update") | ||
.send(weeklyTargetToUpdate) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body._id).toBe(weeklyTargetId) | ||
expect(body.username).toBe(username) | ||
expect(body.runningTarget).toBe(weeklyTargetToUpdate.runningTarget) | ||
}) | ||
}); | ||
}); | ||
|
||
describe("DELETE /targets/:id", () => { | ||
test("should delete a target for given id", async () => { | ||
return request(app) | ||
.delete(`/targets/${weeklyTargetId}`) | ||
.expect(200) | ||
}); | ||
}); |