-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test interactions with planx db
- Loading branch information
Showing
1 changed file
with
92 additions
and
1 deletion.
There are no files selected for viewing
93 changes: 92 additions & 1 deletion
93
api.planx.uk/modules/analytics/metabase/collection/collection.test.ts
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 +1,92 @@ | ||
test.todo("should test collection check and creation"); | ||
import { $api } from "../../../../client/index.js"; | ||
import { updateMetabaseId } from "./updateMetabaseId.js"; | ||
import { getTeamIdAndMetabaseId } from "./getTeamIdAndMetabaseId.js"; | ||
|
||
describe("getTeamIdAndMetabaseId", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test("successfully gets team and existing metabase id", async () => { | ||
vi.spyOn($api.client, "request").mockResolvedValue({ | ||
teams: [ | ||
{ | ||
id: 26, | ||
name: "Barnet", | ||
metabaseId: 20, | ||
}, | ||
], | ||
}); | ||
|
||
const teamAndMetabaseId = await getTeamIdAndMetabaseId("Barnet"); | ||
|
||
expect(teamAndMetabaseId.id).toEqual(26); | ||
expect(teamAndMetabaseId.metabaseId).toEqual(20); | ||
}); | ||
|
||
test("handles team with null metabase id", async () => { | ||
vi.spyOn($api.client, "request").mockResolvedValue({ | ||
teams: [ | ||
{ | ||
id: 26, | ||
name: "Barnet", | ||
metabaseId: null, | ||
}, | ||
], | ||
}); | ||
|
||
const teamAndMetabaseId = await getTeamIdAndMetabaseId("Barnet"); | ||
|
||
expect(teamAndMetabaseId.id).toEqual(26); | ||
expect(teamAndMetabaseId.metabaseId).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("updateMetabaseId", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test("successfully updates metabase ID", async () => { | ||
// Mock the GraphQL request | ||
vi.spyOn($api.client, "request").mockResolvedValue({ | ||
update_teams: { | ||
returning: [ | ||
{ | ||
id: 1, | ||
name: "Test Team", | ||
metabase_id: 123, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const result = await updateMetabaseId(1, 123); | ||
|
||
expect(result).toEqual({ | ||
update_teams: { | ||
returning: [ | ||
{ | ||
id: 1, | ||
name: "Test Team", | ||
metabase_id: 123, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
expect($api.client.request).toHaveBeenCalledWith(expect.any(String), { | ||
id: 1, | ||
metabaseId: 123, | ||
}); | ||
}); | ||
|
||
test("handles GraphQL error", async () => { | ||
// Mock a failed GraphQL request | ||
vi.spyOn($api.client, "request").mockRejectedValue( | ||
new Error("GraphQL error"), | ||
); | ||
|
||
await expect(updateMetabaseId(1, 123)).rejects.toThrow("GraphQL error"); | ||
}); | ||
}); |