Skip to content

Commit

Permalink
Update repo.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-watson committed Mar 28, 2024
1 parent bb99371 commit 5d155f3
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions src/__tests__/repo.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
import { ApolloServer } from "@apollo/server";
import { ApolloServer, ContextFunction } from "@apollo/server";
import { readFileSync } from "fs";
import gql from "graphql-tag";
import resolvers from "../resolvers";
import { buildSubgraphSchema } from "@apollo/subgraph";
import {
StandaloneServerContextFunctionArgument,
} from "@apollo/server/standalone";
import { DataSourceContext } from "../types/DataSourceContext";
import API from "../api";

const context: ContextFunction<
[StandaloneServerContextFunctionArgument],
DataSourceContext
> = async ({ req }) => ({
api: new API(),
});

const server = new ApolloServer({
typeDefs: gql(
readFileSync("schema.graphql", {
encoding: "utf-8",
})
),
resolvers,
schema: buildSubgraphSchema({
typeDefs: gql(
readFileSync("schema.graphql", {
encoding: "utf-8",
})
),
resolvers,
}),
});

describe("Repository Template Functionality", () => {
it("Executes Location Entity Resolver", async () => {
//Arrange
const query = `query ($representations: [_Any!]!) {
_entities(representations: $representations) {
...on Thing {
name
}
const query = `query Capsules {
capsules {
id
}
}`;
const variables = {
representations: [{ __typename: "Thing", id: "1" }],
};
const expected = {
_entities: [{ name: "Name" }],
const expected = {
id: "5e9e2c5bf35918ed873b2664",
};
//Act
const res = await server.executeOperation({
query,
variables,
});
const res = await server.executeOperation(
{
query,
variables,
},
{ contextValue: { api: new API() } }
);
//Assert
expect(res.body.kind).toEqual("single");
expect((res.body as any).singleResult.data).toEqual(expected);
expect((res.body as any).singleResult.data.capsules[0]).toEqual(expected);
});
});

0 comments on commit 5d155f3

Please sign in to comment.