mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add remaining tests for QueryResolvers
This commit is contained in:
@@ -24,12 +24,17 @@ describe("QueryResolvers", () => {
|
|||||||
repository = new UnoptimizedInMemoryRepository();
|
repository = new UnoptimizedInMemoryRepository();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function addMockSystems() {
|
||||||
|
const systems = generateMockSystems();
|
||||||
|
await Promise.all(systems.map(async (system) => {
|
||||||
|
await repository.addOrUpdateSystem(system);
|
||||||
|
}));
|
||||||
|
return systems;
|
||||||
|
}
|
||||||
|
|
||||||
describe("systems", () => {
|
describe("systems", () => {
|
||||||
it("returns systems from the repository", async () => {
|
it("returns systems from the repository", async () => {
|
||||||
const systems = generateMockSystems();
|
const systems = await addMockSystems();
|
||||||
await Promise.all(systems.map(async (system) => {
|
|
||||||
await repository.addOrUpdateSystem(system);
|
|
||||||
}));
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
query GetSystems
|
query GetSystems
|
||||||
@@ -38,7 +43,7 @@ describe("QueryResolvers", () => {
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
const response = await testServer.executeOperation({
|
const response = await testServer.executeOperation({
|
||||||
query,
|
query,
|
||||||
@@ -55,16 +60,50 @@ describe("QueryResolvers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("system", () => {
|
describe("system", () => {
|
||||||
|
const query = `
|
||||||
|
query GetSystem($id: ID!)
|
||||||
|
{
|
||||||
|
system(id: $id) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
it("returns a system for an ID from the repository", async () => {
|
it("returns a system for an ID from the repository", async () => {
|
||||||
|
const systems = await addMockSystems();
|
||||||
|
const systemToGet = systems[1];
|
||||||
|
|
||||||
});
|
const response = await testServer.executeOperation({
|
||||||
|
query,
|
||||||
it("returns null if no id provided", async () => {
|
variables: {
|
||||||
|
id: systemToGet.id,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
contextValue: {
|
||||||
|
repository,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
expect(response.body.singleResult.data?.system).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns null if there is no system", async () => {
|
it("returns null if there is no system", async () => {
|
||||||
|
const response = await testServer.executeOperation({
|
||||||
|
query,
|
||||||
|
variables: {
|
||||||
|
id: "nonexistent-id",
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
contextValue: {
|
||||||
|
repository,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
expect(response.body.singleResult.data?.system).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user