-
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.
build real unit and integration tests
- Loading branch information
1 parent
408d3d2
commit 8c3d53c
Showing
15 changed files
with
925 additions
and
81 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
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,17 @@ | ||
import { expect, test } from "vitest"; | ||
import { InternalServerError } from "../../src/errors/index.js"; | ||
import { EventGetResponse } from "../../src/routes/events.js"; | ||
|
||
const appKey = process.env.APPLICATION_KEY; | ||
if (!appKey) { | ||
throw new InternalServerError({ message: "No application key found" }); | ||
} | ||
|
||
const baseEndpoint = `https://${appKey}.aws.qa.acmuiuc.org`; | ||
|
||
test("getting events", async () => { | ||
const response = await fetch(`${baseEndpoint}/api/v1/events`); | ||
expect(response.status).toBe(200); | ||
Check failure on line 14 in tests/live/events.test.ts
|
||
const responseJson = (await response.json()) as EventGetResponse; | ||
expect(responseJson.length).greaterThan(0); | ||
}); |
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,16 @@ | ||
import { expect, test } from "vitest"; | ||
import { InternalServerError } from "../../src/errors/index.js"; | ||
|
||
const appKey = process.env.APPLICATION_KEY; | ||
if (!appKey) { | ||
throw new InternalServerError({ message: "No application key found" }); | ||
} | ||
|
||
const baseEndpoint = `https://${appKey}.aws.qa.acmuiuc.org`; | ||
|
||
test("healthz", async () => { | ||
const response = await fetch(`${baseEndpoint}/api/v1/healthz`); | ||
expect(response.status).toBe(200); | ||
Check failure on line 13 in tests/live/healthz.test.ts
|
||
const responseJson = await response.json(); | ||
expect(responseJson).toEqual({ message: "UP" }); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { afterAll, expect, test, beforeEach, vi } from "vitest"; | ||
import { ScanCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
import { mockClient } from "aws-sdk-client-mock"; | ||
import init from "../../src/index.js"; | ||
import { EventGetResponse } from "../../src/routes/events.js"; | ||
import { | ||
dynamoTableData, | ||
dynamoTableDataUnmarshalled, | ||
dynamoTableDataUnmarshalledUpcomingOnly, | ||
} from "./mockEventData.testdata.js"; | ||
|
||
const ddbMock = mockClient(DynamoDBClient); | ||
|
||
const app = await init(); | ||
test("Test getting events", async () => { | ||
ddbMock.on(ScanCommand).resolves({ | ||
Items: dynamoTableData as any, | ||
}); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/events", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = (await response.json()) as EventGetResponse; | ||
expect(responseDataJson).toEqual(dynamoTableDataUnmarshalled); | ||
}); | ||
|
||
test("Test dynamodb error handling", async () => { | ||
ddbMock.on(ScanCommand).rejects("Could not get data."); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/events", | ||
}); | ||
expect(response.statusCode).toBe(500); | ||
const responseDataJson = await response.json(); | ||
expect(responseDataJson).toEqual({ | ||
error: true, | ||
name: "DatabaseFetchError", | ||
id: 106, | ||
message: "Failed to get events from Dynamo table.", | ||
}); | ||
}); | ||
|
||
test("Test upcoming only", async () => { | ||
const date = new Date(2024, 7, 10, 13, 0, 0); // 2024-08-10T17:00:00.000Z, don't ask me why its off a month | ||
vi.setSystemTime(date); | ||
ddbMock.on(ScanCommand).resolves({ | ||
Items: dynamoTableData as any, | ||
}); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/events?upcomingOnly=true", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = (await response.json()) as EventGetResponse; | ||
expect(responseDataJson).toEqual(dynamoTableDataUnmarshalledUpcomingOnly); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
vi.useRealTimers(); | ||
}); | ||
beforeEach(() => { | ||
ddbMock.reset(); | ||
vi.useFakeTimers(); | ||
}); |
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,17 @@ | ||
import { afterAll, expect, test } from "vitest"; | ||
import init from "../../src/index.js"; | ||
import { EventGetResponse } from "../../src/routes/events.js"; | ||
|
||
const app = await init(); | ||
test("Test getting events", async () => { | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/healthz", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = (await response.json()) as EventGetResponse; | ||
expect(responseDataJson).toEqual({ message: "UP" }); | ||
}); | ||
afterAll(async () => { | ||
await app.close(); | ||
}); |
Oops, something went wrong.