Skip to content

Commit

Permalink
test: add more @http v2 E2E tests (#8699)
Browse files Browse the repository at this point in the history
This commit adds E2E tests for the @http v2 directive. This
verifies ${env}, ${aws_region}, and request header behavior.

Co-authored-by: Colin Ihrig <colihrig@amazon.com>
  • Loading branch information
cjihrig and cjihrig-aws committed Nov 6, 2021
1 parent 05151bd commit dbf9925
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
@@ -1,4 +1,4 @@
'use strict'
'use strict';
const path = require('path');
const fs = require('fs');
const os = require('os');
Expand All @@ -14,6 +14,14 @@ const app = jsonServer.create();
const router = jsonServer.router(writableDbPath);
const middlewares = jsonServer.defaults();

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

app.use(middlewares);
app.use(router);

Expand Down
Expand Up @@ -13,9 +13,10 @@ import { deployJsonServer, destroyJsonServer } from '../cdkUtils';

jest.setTimeout(2000000);

const cf = new CloudFormationClient('us-west-2');
const customS3Client = new S3Client('us-west-2');
const awsS3Client = new S3({ region: 'us-west-2' });
const REGION = 'us-west-2';
const cf = new CloudFormationClient(REGION);
const customS3Client = new S3Client(REGION);
const awsS3Client = new S3({ region: REGION });
const BUILD_TIMESTAMP = moment().format('YYYYMMDDHHmmss');
const STACK_NAME = `HttpTransformerV2Test-${BUILD_TIMESTAMP}`;
const BUCKET_NAME = `appsync-http-transformer-v2-test-bucket-${BUILD_TIMESTAMP}`;
Expand Down Expand Up @@ -64,6 +65,11 @@ beforeAll(async () => {
secondType: String!,
id: Int
): [PostComment] @http(url: "${apiUrl}:dataType/:postId/:secondType")
configGet: ConfigResponse @http(
method: GET,
url: "${apiUrl}config/\${aws_region}/\${env}",
headers: [{ key: "x-api-key", value: "fake-api-key" }]
)
}
type CompObj {
userId: Int
Expand All @@ -78,6 +84,11 @@ beforeAll(async () => {
email: String
body: String
}
type ConfigResponse {
apiKey: String
env: String
region: String
}
`;

try {
Expand Down Expand Up @@ -441,3 +452,28 @@ test('Test that POST errors when missing a non-null arg in query/body', async ()
expect(e).toBeUndefined();
}
});

test('Test headers, environment, and region support', async () => {
const response = await GRAPHQL_CLIENT.query(
`mutation {
createComment(input: { title: "Hello, World!" }) {
id
title
configGet {
apiKey
env
region
}
}
}`,
{},
);

expect(response.errors).toBeUndefined();
expect(response.data.createComment.id).toBeDefined();
expect(response.data.createComment.title).toEqual('Hello, World!');
expect(response.data.createComment.configGet).toBeDefined();
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);
});

0 comments on commit dbf9925

Please sign in to comment.