Skip to content

Commit 3e48485

Browse files
andreachildCole-Greer
authored andcommitted
Removed duplicates of airports.source.schema.graphql and changed references to use a common file. Changed integration test references to neptune db host and port to have values injected from environment variables so that contributors do not have to modify the case files to execute tests, which could lead to accidental commit of real URLs.
Fixed tests failing due to hardcoded output directory reference in main.js, missing comma in json file, typo in referenced file suffix, and incorrect order of test cases (delete, create changed to create, delete).
1 parent b6e130d commit 3e48485

15 files changed

+78
-46
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ test/TestCases/Case02/output/**
1212
test/TestCases/Case03/output/**
1313
test/TestCases/Case04/output/**
1414
test/TestCases/Case05/output/**
15-
test/TestCases/Case06/output/**
15+
test/TestCases/Case06/output/**
16+
*.iml

.jest.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
'transform': {},
3+
'verbose': true,
4+
'testSequencer': './test/jestTestSequencer.js',
5+
'globals': {
6+
// neptune db that has pre-loaded air routes sample data host and port
7+
// ex. db-neptune-foo-bar.cluster-abc.us-west-2.neptune.amazonaws.com
8+
'AIR_ROUTES_DB_HOST': process.env.AIR_ROUTES_DB_HOST,
9+
// ex. 8182
10+
'AIR_ROUTES_DB_PORT': process.env.AIR_ROUTES_DB_PORT
11+
}
12+
};

.jest.json

-5
This file was deleted.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"scripts": {
2222
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install",
2323
"lint": "eslint neptune-for-graphql.mjs ./src",
24-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.json",
25-
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.json --testPathPattern=test/TestCases/Case01"
24+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js",
25+
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case01"
2626
},
2727
"jest": {
2828
"collectCoverage": true,

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ async function main() {
404404
// Outputs
405405
// ****************************************************************************
406406

407-
mkdirSync('./output', { recursive: true });
407+
mkdirSync(outputFolderPath, { recursive: true });
408408

409409
// Output GraphQL schema no directives
410410
if (inputGraphQLSchema != '') {

test/TestCases/Case01/Case01.04.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readJSONFile, testResolverQueriesResults } from '../../testLib';
44

55
const casetest = readJSONFile('./test/TestCases/Case01/case.json');
66

7-
await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.cjs',
7+
await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.js',
88
'./test/TestCases/Case01/queries',
99
casetest.host,
1010
casetest.port);

test/TestCases/Case01/case.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "Unit Test (Air Routes)",
33
"description":"Start from graphql schema with directives, using Air Routes unit test schema",
44
"argv":["--quiet",
5-
"--input-schema-file", "./test/TestCases/Case01/input/airports.source.schema.graphql",
5+
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
66
"--input-schema-changes-file", "./test/TestCases/Case01/input/changesAirport.json",
77
"--output-js-resolver-file", "./test/TestCases/Case01/output/output.resolver.graphql.cjs",
88
"--output-folder-path", "./test/TestCases/Case01/output",
99
"--output-no-lambda-zip"],
10-
"host": "<your-airroutes-db-host>",
11-
"port": "<your-airroutes-db-port>"
10+
"host": "<AIR_ROUTES_DB_HOST>",
11+
"port": "<AIR_ROUTES_DB_PORT>",
1212
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1313
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1414
}

test/TestCases/Case02/case.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"--output-js-resolver-file", "./test/TestCases/Case02/output/output.resolver.graphql.cjs",
77
"--output-folder-path", "./test/TestCases/Case02/output",
88
"--output-no-lambda-zip"],
9-
"host": "<your-airroutes-db-host>",
10-
"port": "<your-airroutes-db-port>"
9+
"host": "<AIR_ROUTES_DB_HOST>",
10+
"port": "<AIR_ROUTES_DB_PORT>",
1111
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1212
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1313
}

test/TestCases/Case03/case.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"--input-schema-file", "./test/TestCases/Case03/input/todo.schema.graphql",
66
"--output-folder-path", "./test/TestCases/Case03/output",
77
"--output-no-lambda-zip"],
8-
"host": "",
9-
"port": "",
8+
"host": "<AIR_ROUTES_DB_HOST>",
9+
"port": "<AIR_ROUTES_DB_PORT>",
1010
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1111
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1212
}

test/TestCases/Case04/case.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "Get Database Schema",
33
"description":"",
44
"argv":["--quiet",
5-
"--input-graphdb-schema-neptune-endpoint", "<neptune-endpoint>",
5+
"--input-graphdb-schema-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
66
"--output-folder-path", "./test/TestCases/Case04/output",
77
"--output-no-lambda-zip"],
8-
"host": "",
9-
"port": "",
8+
"host": "<AIR_ROUTES_DB_HOST>",
9+
"port": "<AIR_ROUTES_DB_PORT>",
1010
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1111
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1212
}

test/TestCases/Case05/case01.json

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
2-
"name": "Unit Test (Air Routes) Remove Pipeline",
3-
"description":"Remove pipeline",
4-
"argv":["--quiet",
5-
"--remove-aws-pipeline-name", "AirportsJestTest",
6-
"--output-folder-path", "./test/TestCases/Case05/output"],
7-
"host": "",
8-
"port": "",
2+
"name": "Unit Test (Air Routes) Pipeline",
3+
"description":"Create pipeline",
4+
"argv":["--quiet",
5+
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
6+
"--output-folder-path", "./test/TestCases/Case05/output",
7+
"--create-update-aws-pipeline",
8+
"--create-update-aws-pipeline-name", "AirportsJestTest",
9+
"--create-update-aws-pipeline-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
10+
"--output-resolver-query-https"],
11+
"host": "<AIR_ROUTES_DB_HOST>",
12+
"port": "<AIR_ROUTES_DB_PORT>",
913
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1014
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1115
}

test/TestCases/Case05/case02.json

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
2-
"name": "Unit Test (Air Routes) Pipeline",
3-
"description":"Create pipeline",
4-
"argv":["--quiet",
5-
"--input-schema-file", "./test/TestCases/Case05/input/airports.source.schema.graphql",
6-
"--output-folder-path", "./test/TestCases/Case05/output",
7-
"--create-update-aws-pipeline",
8-
"--create-update-aws-pipeline-name", "AirportsJestTest",
9-
"--create-update-aws-pipeline-neptune-endpoint", "<neptune-endpoint>",
10-
"--output-resolver-query-https"],
11-
"host": "",
12-
"port": "",
13-
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
14-
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
2+
"name": "Unit Test (Air Routes) Remove Pipeline",
3+
"description":"Remove pipeline",
4+
"argv":["--quiet",
5+
"--remove-aws-pipeline-name", "AirportsJestTest",
6+
"--output-folder-path", "./test/TestCases/Case05/output"],
7+
"host": "<AIR_ROUTES_DB_HOST>",
8+
"port": "<AIR_ROUTES_DB_HOST>",
9+
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
10+
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1511
}

test/TestCases/Case06/case.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
"name": "Unit Test (Air Routes) CDK Pipeline",
33
"description":"Create CDK pipeline",
44
"argv":["--quiet",
5-
"--input-schema-file", "./test/TestCases/Case06/input/airports.source.schema.graphql",
5+
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
66
"--output-folder-path", "./test/TestCases/Case06/output",
77
"--output-aws-pipeline-cdk",
88
"--output-aws-pipeline-cdk-name", "AirportCDKTestJest",
99
"--output-aws-pipeline-cdk-neptume-database-name", "airport00",
1010
"--output-aws-pipeline-cdk-region", "us-east-1",
11-
"--output-aws-pipeline-cdk-neptume-endpoint", "<neptune-endpoint>",
11+
"--output-aws-pipeline-cdk-neptume-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
1212
"--output-resolver-query-https"],
13-
"host": "",
14-
"port": "",
13+
"host": "<AIR_ROUTES_DB_HOST>",
14+
"port": "<AIR_ROUTES_DB_PORT>",
1515
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
1616
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
1717
}

test/testLib.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import axios from 'axios';
33
import fs from 'fs';
44

5-
5+
const HOST_PLACEHOLDER = '<AIR_ROUTES_DB_HOST>';
6+
const PORT_PLACEHOLDER = '<AIR_ROUTES_DB_PORT>';
67

78
async function queryNeptune(q, language, host, port, param) {
89
try {
@@ -18,9 +19,32 @@ async function queryNeptune(q, language, host, port, param) {
1819
}
1920
}
2021

22+
/**
23+
* Searches the given text for a placeholder text and if found replaces it with an environment variable value of the same name.
24+
* It is expected that the placeholder text is surrounded by angle brackets and the environment variable name is the placeholder text without the angle brackets.
25+
*
26+
* @param text the text to search and replace the placeholder
27+
* @param placeholder the placeholder text to search for
28+
* @returns text with replaced placeholder if found
29+
* @throws error if the placeholder text is found but the environment variable is not set
30+
*/
31+
function replacePlaceholderWithEnvironmentVariable(text, placeholder) {
32+
if (text.includes(placeholder)) {
33+
// remove angle brackets
34+
let envVarName = placeholder.replace(/[<>]/g, '');
35+
if (process.env[envVarName]) {
36+
return text.replace(placeholder, process.env[envVarName]);
37+
}
38+
throw new Error('Expected environment variable ' + envVarName + ' is not set');
39+
}
40+
return text;
41+
}
2142

2243
function readJSONFile(fileName) {
23-
return JSON.parse(fs.readFileSync(fileName, 'utf8'));
44+
let text = fs.readFileSync(fileName, 'utf8');
45+
text = replacePlaceholderWithEnvironmentVariable(text, HOST_PLACEHOLDER);
46+
text = replacePlaceholderWithEnvironmentVariable(text, PORT_PLACEHOLDER);
47+
return JSON.parse(text);
2448
}
2549

2650

0 commit comments

Comments
 (0)