generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculation Endpoints: Adds Validation and Tests (#1521)
* adds calculation tests for server * adds admin variables to CI * adds validation for request bodies for calculation endpoints * linting on test file * Fix: resolved undefined return to return id property * adds tests with invalid bodies * fixes test description for invalid bodies * refactors tests * removes stale endpoints
- Loading branch information
Showing
7 changed files
with
100 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ on: | |
branches: | ||
- develop | ||
jobs: | ||
build: | ||
server-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
@@ -39,6 +39,8 @@ jobs: | |
echo "APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/" >> .env | ||
echo "[email protected]" >> .env | ||
echo "SECURITY_ADMIN_PASSWORD=Dogfood1!" >> .env | ||
echo "[email protected]" >> .env | ||
echo "ADMIN_PASSWORD=Dogfood1!" >> .env | ||
echo "SQL_SERVER_NAME=localhost" >> .env | ||
echo "SQL_SERVER_PORT=1434" >> .env | ||
echo "SQL_DATABASE_NAME=tdmtestdb" >> .env | ||
|
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 |
---|---|---|
|
@@ -67,31 +67,33 @@ APPLICATIONINSIGHTS_CONNECTION_STRING= | |
############################################################### | ||
## Testing (Comment out ALL the above variables) ## | ||
############################################################### | ||
# TEST_ENV= | ||
# TEST_ENV=true | ||
|
||
# PORT= | ||
# NODE_OPTIONS= | ||
# PORT=5002 | ||
# NODE_OPTIONS=--trace-deprecation | ||
|
||
# JWT_SECRET_KEY= | ||
# JWT_SECRET_KEY=testingSecretKey | ||
|
||
# CLIENT_URL= | ||
# SERVER_URL= | ||
# CLIENT_URL=http://localhost:3001 | ||
# SERVER_URL=http://localhost:5002 | ||
|
||
# SENDGRID_API_KEY= | ||
# EMAIL_SENDER= | ||
# EMAIL_PUBLIC_COMMENT_LA_CITY= | ||
# EMAIL_PUBLIC_COMMENT_WEB_TEAM= | ||
# SENDGRID_API_KEY=SG.testAPIkey | ||
# EMAIL_SENDER=[email protected] | ||
# EMAIL_PUBLIC_COMMENT_LA_CITY=[email protected] | ||
# EMAIL_PUBLIC_COMMENT_WEB_TEAM=[email protected] | ||
|
||
# APPLICATIONINSIGHTS_CONNECTION_STRING= | ||
# APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/ | ||
|
||
## Server Test Accounts | ||
# SECURITY_ADMIN_EMAIL= | ||
# SECURITY_ADMIN_PASSWORD= | ||
# # Server Test Accounts | ||
# [email protected] | ||
# SECURITY_ADMIN_PASSWORD=Dogfood1! | ||
# [email protected] | ||
# ADMIN_PASSWORD=Dogfood1! | ||
|
||
## testingcontainer Environment Variables | ||
# SQL_SERVER_NAME= | ||
# SQL_SERVER_PORT= | ||
# SQL_DATABASE_NAME= | ||
# SQL_USER_NAME= | ||
# SQL_PASSWORD= | ||
# SQL_ENCRYPT = | ||
# # testingcontainer Environment Variables | ||
# SQL_SERVER_NAME=localhost | ||
# SQL_SERVER_PORT=1434 | ||
# SQL_DATABASE_NAME=tdmtestdb | ||
# SQL_USER_NAME=sa | ||
# SQL_PASSWORD=TestPassw0rd | ||
# SQL_ENCRYPT = false |
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,72 @@ | ||
const request = require("supertest"); | ||
const { | ||
setupServer, | ||
teardownServer | ||
} = require("../_jest-setup_/utils/server-setup"); | ||
|
||
let server; | ||
|
||
beforeAll(async () => { | ||
server = await setupServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await teardownServer(); | ||
}); | ||
|
||
describe("tests that require a calculation id", () => { | ||
////////////////////////////// | ||
// general // | ||
////////////////////////////// | ||
let calcId; // id of the calculation | ||
|
||
beforeEach(async () => { | ||
// get a calculation id for the tests | ||
const res = await request(server).get("/api/calculations"); | ||
calcId = res.body[0].id; | ||
}); | ||
|
||
afterEach(async () => { | ||
// cleanup state | ||
calcId = undefined; | ||
}); | ||
|
||
// GET "/" all calculations | ||
it("should get all calculations", async () => { | ||
const res = await request(server).get("/api/calculations"); | ||
expect(Array.isArray(res.body)).toBeTruthy(); | ||
res.body.forEach(calc => { | ||
expect(calc).toHaveProperty("id"); | ||
expect(calc).toHaveProperty("name"); | ||
expect(calc).toHaveProperty("description"); | ||
expect(calc).toHaveProperty("deprecated"); | ||
expect(calc).toHaveProperty("dateCreated"); | ||
expect(calc).toHaveProperty("dateModified"); | ||
}); | ||
}); | ||
|
||
// GET "/:calcId" calculation by id | ||
it("should get calculation by id", async () => { | ||
const res = await request(server).get(`/api/calculations/${calcId}`); | ||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.id).toEqual(calcId); | ||
}); | ||
|
||
// GET "/:calcId" calculation by inexistent id | ||
it("should NOT get calculation by id", async () => { | ||
const res = await request(server).get(`/api/calculations/9999999`); | ||
expect(res.statusCode).toEqual(404); | ||
}); | ||
|
||
// GET "/:calcId/rules" all rules for a calculation | ||
it("should get all rules for a calculation", async () => { | ||
const res = await request(server).get(`/api/calculations/${calcId}/rules`); | ||
expect(res.statusCode).toEqual(200); | ||
expect(Array.isArray(res.body)).toBeTruthy(); | ||
res.body.forEach(calc => { | ||
expect(calc).toHaveProperty("id"); | ||
expect(calc).toHaveProperty("calculationId"); | ||
expect(calc.calculationId).toEqual(calcId); | ||
}); | ||
}); | ||
}); |
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