-
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.
TestCasesforGet & POST and DELETE for ticket
- Loading branch information
Showing
3 changed files
with
275 additions
and
23 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,77 @@ | ||
import { unmarshall } from "@aws-sdk/util-dynamodb"; | ||
|
||
const dynamoTableData = [ | ||
{ | ||
event_id: { | ||
S: "test_barcrawl", | ||
}, | ||
eventCost: { | ||
M: { | ||
others: { | ||
N: "100", | ||
}, | ||
paid: { | ||
N: "0", | ||
}, | ||
}, | ||
}, | ||
eventDetails: { | ||
S: "Join ACM", | ||
}, | ||
eventImage: { | ||
S: "img/test.png", | ||
}, | ||
eventProps: { | ||
M: { | ||
end: { | ||
N: "", | ||
}, | ||
host: { | ||
S: "", | ||
}, | ||
location: { | ||
S: "", | ||
}, | ||
}, | ||
}, | ||
event_capacity: { | ||
N: "130", | ||
}, | ||
event_name: { | ||
S: "ACM Fall 2023 Bar Crawl", | ||
}, | ||
event_sales_active_utc: { | ||
N: "0", | ||
}, | ||
event_time: { | ||
N: "1699578000", | ||
}, | ||
member_price: { | ||
S: "price_1O6zHhDiGOXU9RuSvlrcIfOv", | ||
}, | ||
nonmember_price: { | ||
S: "price_1O6zHhDiGOXU9RuSvlrcIfOv", | ||
}, | ||
tickets_sold: { | ||
N: "0", | ||
}, | ||
}, | ||
]; | ||
|
||
const dynamoTableDataUnmarshalled = dynamoTableData.map((x: any) => { | ||
const temp = unmarshall(x); | ||
return temp; | ||
}); | ||
|
||
const dynamoTableDataUnmarshalledUpcomingOnly = dynamoTableData | ||
.map((x: any) => { | ||
const temp = unmarshall(x); | ||
return temp; | ||
}) | ||
.filter((x: any) => x.title != "Event in the past."); | ||
|
||
export { | ||
dynamoTableData, | ||
dynamoTableDataUnmarshalled, | ||
dynamoTableDataUnmarshalledUpcomingOnly, | ||
}; |
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,79 @@ | ||
import { afterAll, expect, test, beforeEach, vi } from "vitest"; | ||
import { | ||
ScanCommand, | ||
DynamoDBClient, | ||
QueryCommand, | ||
} from "@aws-sdk/client-dynamodb"; | ||
import { mockClient } from "aws-sdk-client-mock"; | ||
import init from "../../src/index.js"; | ||
import { | ||
dynamoTableData, | ||
dynamoTableDataUnmarshalled, | ||
} from "./mockPaidEventData.testdata.js"; | ||
import { secretObject } from "./secret.testdata.js"; | ||
|
||
const ddbMock = mockClient(DynamoDBClient); | ||
const jwt_secret = secretObject["jwt_key"]; | ||
vi.stubEnv("JwtSigningKey", jwt_secret); | ||
|
||
const app = await init(); | ||
test("Test paidEvents up", async () => { | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/paidEvents", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = await response.json(); | ||
expect(responseDataJson).toEqual({ Status: "Up" }); | ||
}); | ||
|
||
test("Test paidEvents get ticketEvents", async () => { | ||
ddbMock.on(ScanCommand).resolves({ | ||
Items: dynamoTableData as any, | ||
}); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/paidEvents/ticketEvents", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = await response.json(); | ||
expect(responseDataJson).toEqual(dynamoTableDataUnmarshalled); | ||
}); | ||
|
||
test("Test paidEvents get ticketEvents by id", async () => { | ||
ddbMock.on(QueryCommand).resolves({ | ||
Items: dynamoTableData as any, | ||
}); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/paidEvents/ticketEvents/test_barcrawl", | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
const responseDataJson = await response.json(); | ||
expect(responseDataJson).toEqual(dynamoTableDataUnmarshalled[0]); //[0] since unmarshalled gives an array | ||
}); | ||
|
||
test("Test dynamodb error handling", async () => { | ||
ddbMock.onAnyCommand().rejects("Nope"); | ||
const response = await app.inject({ | ||
method: "GET", | ||
url: "/api/v1/paidEvents/ticketEvents", | ||
}); | ||
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.", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
vi.useRealTimers(); | ||
}); | ||
beforeEach(() => { | ||
ddbMock.reset(); | ||
vi.useFakeTimers(); | ||
}); |