Skip to content

Commit

Permalink
test: add @http v2 parent data e2e test (#8705)
Browse files Browse the repository at this point in the history
This commit adds an e2e test for @http v2 which verifies that
data from the parent resolver can be accessed.

Co-authored-by: Colin Ihrig <colihrig@amazon.com>
  • Loading branch information
cjihrig and cjihrig-aws committed Nov 6, 2021
1 parent cc21d4d commit f798bbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const app = jsonServer.create();
const router = jsonServer.router(writableDbPath);
const middlewares = jsonServer.defaults();

app.use('/config/:region/:env', (req, res) => {
app.use('/config/:region/:env/:commentId', (req, res) => {
res.json({
apiKey: req.headers['x-api-key'],
env: req.params.env,
region: req.params.region,
commentId: req.params.commentId,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ beforeAll(async () => {
): [PostComment] @http(url: "${apiUrl}:dataType/:postId/:secondType")
configGet: ConfigResponse @http(
method: GET,
url: "${apiUrl}config/\${aws_region}/\${env}",
url: "${apiUrl}config/\${aws_region}/\${env}/\${!ctx.source.id}",
headers: [{ key: "x-api-key", value: "fake-api-key" }]
)
}
Expand All @@ -88,6 +88,7 @@ beforeAll(async () => {
apiKey: String
env: String
region: String
commentId: String
}
`;

Expand Down Expand Up @@ -453,7 +454,7 @@ test('Test that POST errors when missing a non-null arg in query/body', async ()
}
});

test('Test headers, environment, and region support', async () => {
test('Test headers, parent data, environment, and region support', async () => {
const response = await GRAPHQL_CLIENT.query(
`mutation {
createComment(input: { title: "Hello, World!" }) {
Expand All @@ -463,6 +464,7 @@ test('Test headers, environment, and region support', async () => {
apiKey
env
region
commentId
}
}
}`,
Expand All @@ -476,4 +478,5 @@ test('Test headers, environment, and region support', async () => {
expect(response.data.createComment.configGet.apiKey).toEqual('fake-api-key');
expect(response.data.createComment.configGet.env).toEqual('NONE');
expect(response.data.createComment.configGet.region).toEqual(REGION);
expect(response.data.createComment.configGet.commentId).toEqual(response.data.createComment.id);
});

0 comments on commit f798bbf

Please sign in to comment.