-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): start implementing test for bulk inventory creation API r…
…oute
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { POST as changeRole } from "@/app/api/v0/auth/role/route"; | ||
import { POST as createBulkInventories } from "@/app/api/v0/admin/bulk/route"; | ||
import { db } from "@/models"; | ||
import { | ||
beforeAll, | ||
|
@@ -12,6 +13,7 @@ import { | |
import { mockRequest, setupTests, testUserData, testUserID } from "../helpers"; | ||
import { AppSession, Auth } from "@/lib/auth"; | ||
import { Roles } from "@/util/types"; | ||
import { BulkInventoryProps } from "@/backend/AdminService"; | ||
|
||
const mockSession: AppSession = { | ||
user: { id: testUserID, role: Roles.User }, | ||
|
@@ -21,6 +23,13 @@ const mockAdminSession: AppSession = { | |
user: { id: testUserID, role: Roles.Admin }, | ||
expires: "1h", | ||
}; | ||
const mockBulkInventoriesRequest: BulkInventoryProps = { | ||
cityLocodes: ["US NYC", "DE BER", "BR AAX"], | ||
emails: ["[email protected]", "[email protected]"], | ||
years: [2022, 2023, 2024], | ||
scope: "gpc_basic_plus", | ||
gwp: "AR6", | ||
}; | ||
|
||
describe("Admin API", () => { | ||
let prevGetServerSession = Auth.getServerSession; | ||
|
@@ -45,6 +54,27 @@ describe("Admin API", () => { | |
}); | ||
}); | ||
|
||
it("should allow creating bulk inventories for admin users", async () => { | ||
const req = mockRequest(mockBulkInventoriesRequest); | ||
Auth.getServerSession = jest.fn(() => Promise.resolve(mockAdminSession)); | ||
const res = await createBulkInventories(req, { params: {} }); | ||
expect(res.status).toBe(200); | ||
const body = await res.json(); | ||
console.dir(body.errors); | ||
expect(body.errors.length).toBe(0); // TODO ignore missing data from Global API in errors | ||
expect(body.results.length).toBe( | ||
mockBulkInventoriesRequest.cityLocodes.length, | ||
); | ||
|
||
// TODO assert required database changes: | ||
// TODO check inventories created | ||
// TODO check population entries for inventory | ||
// TODO check all data sources for inventory are connected | ||
// TODO check that users were added to inventory (without sending the emails) | ||
// TODO check all data sources are connected | ||
// TODO check all users were invited | ||
}, 60000); | ||
|
||
it("should change the user role when logged in as admin", async () => { | ||
const req = mockRequest({ | ||
email: testUserData.email, | ||
|