Skip to content

Commit 3d5b28b

Browse files
feat(Geo) Construct: Phase 3 - Integration Testing (#2950)
* adding output schemas * creating changeset * API changes * adding package and required files with partial implementation * adding API changes with package * adding initial version of construct and API * updating API and exposed endpoints * adding output definition * split APi definition and outputs aspects defined * unit testing v1 and debugging * updating tsconfig * fixing some expressions * updating API from recent commits * removing all previous changesets * Revert "removing all previous changesets" This reverts commit e2af23b. * removing changeset files instead of directory * Revert "removing changeset files instead of directory" This reverts commit 93e024f. * removing changeset files * adding changeset * clean up * geo client-output bug fixed * updating API and fixing policy name duplication bug * adding changeset for changed packages and updated README * first iteration of api key support for map and place resources * small fixes * bumping packages * unit testing for backend-geo files complete * updating API.md * adding output schemas * creating changeset * API changes * adding package and required files with partial implementation adding package and required files with partial implementation# * adding initial version of construct and API * updating API and exposed endpoints * adding output definition * split APi definition and outputs aspects defined * unit testing v1 and debugging * updating tsconfig * fixing some expressions * updating API from recent commits * removing all previous changesets * Revert "removing all previous changesets" This reverts commit e2af23b. * removing changeset files instead of directory * Revert "removing changeset files instead of directory" This reverts commit 93e024f. * removing changeset files * adding changeset * clean up * geo client-output bug fixed * updating API and fixing policy name duplication bug * adding changeset for changed packages and updated README * small fixes * bumping packages * regenerating package-lock with new cdk versions * updating packages and adding v1.5 schema * stepping back, reverting last commit * new package-lock * small fixes v3 * adding new schema and api key integration v1 * updating API * fixing API * fixing unit test issues after fixes v3 * adding unit testing for api key support(all except client config) * updating API * new output schema to accomodate for api keys * small fixes v4 * small fixes v5 * API key names outputted and configuring amplify outputs * small changes and test coverage * small changes * updating package-lock * updating package-lock * adding integration test for Geo construct and API key support testing * fixing package lock * update form data to fix dependabot alert (#2940) * fixing stringify issue from PR 1 and downgrading location alpha version * adding new output stringify algorithm * fix to bumping cdk-lib deps to 2.195 * bumping all baselines to 2.207 * updating alpha package * adding missing changesets * fixing e2e issues v1 * updating API * following naming convention of integration test * small fix for node:crypto * adding changeset description and removing isdefault * updating API * small fixes v2 * updating API * fixing schema * naming conventions * tackling changeset version issues * fixing node:crypto issues * updating APIs --------- Co-authored-by: Amplifiyer <[email protected]>
1 parent 55caecb commit 3d5b28b

File tree

12 files changed

+950
-339
lines changed

12 files changed

+950
-339
lines changed

.changeset/wild-deer-post.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

package-lock.json

Lines changed: 695 additions & 338 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@aws-sdk/client-cognito-identity-provider": "^3.750.0",
6565
"@aws-sdk/client-dynamodb": "^3.750.0",
6666
"@aws-sdk/client-iam": "^3.750.0",
67+
"@aws-sdk/client-location": "^3.859.0",
6768
"@aws-sdk/client-s3": "^3.750.0",
6869
"@aws-sdk/client-ssm": "^3.750.0",
6970
"@changesets/cli": "^2.26.1",

packages/integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@aws-sdk/client-cognito-identity-provider": "^3.750.0",
2727
"@aws-sdk/client-iam": "^3.750.0",
2828
"@aws-sdk/client-lambda": "^3.750.0",
29+
"@aws-sdk/client-location": "^3.859.0",
2930
"@aws-sdk/client-s3": "^3.750.0",
3031
"@aws-sdk/client-sqs": "^3.750.0",
3132
"@aws-sdk/client-sts": "^3.750.0",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { defineDeploymentTest } from './deployment.test.template.js';
2+
import { GeoAPIKeySupportTestProjectCreator } from '../../test-project-setup/geo_api_key_support_testing.js';
3+
4+
defineDeploymentTest(new GeoAPIKeySupportTestProjectCreator());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { defineSandboxTest } from './sandbox.test.template.js';
2+
import { GeoAPIKeySupportTestProjectCreator } from '../../test-project-setup/geo_api_key_support_testing.js';
3+
4+
defineSandboxTest(new GeoAPIKeySupportTestProjectCreator());

packages/integration-tests/src/test-project-setup/cdk/create_empty_cdk_project.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,16 @@ export const createEmptyCdkProject = async (
3434
force: true,
3535
});
3636

37+
// Update tsconfig.json to include types for "node:" imports
38+
const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
39+
const tsconfig = JSON.parse(await fsp.readFile(tsconfigPath, 'utf-8'));
40+
if (!tsconfig.compilerOptions.types) {
41+
tsconfig.compilerOptions.types = [];
42+
}
43+
if (!tsconfig.compilerOptions.types.includes('node')) {
44+
tsconfig.compilerOptions.types.push('node');
45+
}
46+
await fsp.writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2));
47+
3748
return { projectName, projectRoot };
3849
};
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import { TestProjectBase } from './test_project_base.js';
2+
import fs from 'fs/promises';
3+
import { createEmptyAmplifyProject } from './create_empty_amplify_project.js';
4+
import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
5+
import { TestProjectCreator } from './test_project_creator.js';
6+
import { AmplifyClient } from '@aws-sdk/client-amplify';
7+
import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js';
8+
import { BackendIdentifier } from '@aws-amplify/plugin-types';
9+
import {
10+
ListGeofenceCollectionsCommand,
11+
ListKeysCommand,
12+
Location,
13+
LocationClient,
14+
} from '@aws-sdk/client-location';
15+
import { DeployedResourcesFinder } from '../find_deployed_resource.js';
16+
import assert from 'node:assert';
17+
18+
/**
19+
* Creates test project for testing new Geo backend functionality with API key support.
20+
*/
21+
export class GeoAPIKeySupportTestProjectCreator implements TestProjectCreator {
22+
readonly name = 'geo-api-key-support';
23+
24+
/**
25+
* Initializes project creator object
26+
*/
27+
constructor(
28+
private readonly cfnClient: CloudFormationClient = new CloudFormationClient(
29+
e2eToolingClientConfig,
30+
),
31+
private readonly amplifyClient: AmplifyClient = new AmplifyClient(
32+
e2eToolingClientConfig,
33+
),
34+
private readonly locationClient: LocationClient = new Location(
35+
e2eToolingClientConfig,
36+
),
37+
private readonly resourceFinder: DeployedResourcesFinder = new DeployedResourcesFinder(),
38+
) {}
39+
40+
createProject = async (e2eProjectDir: string): Promise<TestProjectBase> => {
41+
const { projectName, projectRoot, projectAmplifyDir } =
42+
await createEmptyAmplifyProject(this.name, e2eProjectDir);
43+
44+
const project = new GeoAPIKeySupportTestProject(
45+
projectName,
46+
projectRoot,
47+
projectAmplifyDir,
48+
this.cfnClient,
49+
this.amplifyClient,
50+
this.locationClient,
51+
this.resourceFinder,
52+
);
53+
54+
await fs.cp(
55+
project.sourceProjectAmplifyDirURL,
56+
project.projectAmplifyDirPath,
57+
{ recursive: true },
58+
);
59+
60+
return project;
61+
};
62+
}
63+
64+
/**
65+
* Creates project with geo and auth resources initialized
66+
*/
67+
export class GeoAPIKeySupportTestProject extends TestProjectBase {
68+
readonly sourceProjectDirPath = '../../src/test-projects/geo-api-key-support';
69+
readonly sourceProjectAmplifyDirURL = new URL(
70+
`${this.sourceProjectDirPath}/amplify`,
71+
import.meta.url,
72+
);
73+
74+
/**
75+
* Creates an instance of a test project with Geofence Collections and API keys provisioned
76+
*/
77+
constructor(
78+
name: string,
79+
projectDirPath: string,
80+
projectAmplifyDirPath: string,
81+
cfnClient: CloudFormationClient,
82+
amplifyClient: AmplifyClient,
83+
private readonly locationClient: LocationClient,
84+
private readonly resourceFinder: DeployedResourcesFinder,
85+
) {
86+
super(
87+
name,
88+
projectDirPath,
89+
projectAmplifyDirPath,
90+
cfnClient,
91+
amplifyClient,
92+
);
93+
}
94+
95+
/**
96+
* Override implementation of post deployment assertions specific to Amplify Geo tests
97+
*/
98+
override async assertPostDeployment(
99+
backendId: BackendIdentifier,
100+
): Promise<void> {
101+
await super.assertPostDeployment(backendId); // perform regular post-deployment tests
102+
103+
const testCollection = await this.resourceFinder.findByBackendIdentifier(
104+
backendId,
105+
'AWS::Location::GeofenceCollection',
106+
(name) => name.includes('amplifyTestCollection'),
107+
);
108+
109+
const testAPIKey = await this.resourceFinder.findByBackendIdentifier(
110+
backendId,
111+
'AWS::Location::APIKey',
112+
(name) => name.includes('amplifyTestIndexKey'),
113+
);
114+
115+
assert.equal(testCollection.length, 1);
116+
assert.equal(testAPIKey.length, 1);
117+
118+
const expectedCollectionResponse = {
119+
Entries: [
120+
{
121+
CollectionName: 'amplifyTestCollection',
122+
Description:
123+
'This is a geofence collection setup for integration testing purposes.',
124+
CreateTime: new Date(),
125+
UpdateTime: new Date(),
126+
},
127+
],
128+
};
129+
130+
const collectionResponse = await this.locationClient.send(
131+
new ListGeofenceCollectionsCommand(),
132+
);
133+
134+
const hasCollection = collectionResponse.Entries?.some(
135+
(entry) =>
136+
entry.CollectionName ===
137+
expectedCollectionResponse.Entries[0].CollectionName &&
138+
entry.Description === expectedCollectionResponse.Entries[0].Description,
139+
);
140+
141+
assert.ok(
142+
hasCollection,
143+
'Expected collection not found in client response.',
144+
);
145+
146+
const expectedKeysResponse = {
147+
Entries: {
148+
KeyName: 'amplifyTestIndexKey',
149+
CreateTime: new Date(),
150+
UpdateTime: new Date(),
151+
Restrictions: {
152+
AllowActions: ['geo-places:Autocomplete'],
153+
},
154+
},
155+
};
156+
157+
const keyResponse = await this.locationClient.send(new ListKeysCommand());
158+
159+
const hasKey = keyResponse.Entries?.some(
160+
(entry) =>
161+
entry.KeyName === expectedKeysResponse.Entries.KeyName &&
162+
JSON.stringify(entry.Restrictions?.AllowActions) ===
163+
JSON.stringify(
164+
expectedKeysResponse.Entries.Restrictions.AllowActions,
165+
),
166+
);
167+
168+
assert.ok(hasKey, 'Expected key not found in client response.');
169+
}
170+
171+
private verifyCollectionResponse = async (expectedResponse: unknown) => {
172+
const locationResponse = await this.locationClient.send(
173+
new ListGeofenceCollectionsCommand(),
174+
);
175+
assert.equal(locationResponse, expectedResponse);
176+
};
177+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineAuth } from '@aws-amplify/backend';
2+
3+
export const auth = defineAuth({
4+
loginWith: {
5+
email: true,
6+
},
7+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineBackend } from '@aws-amplify/backend';
2+
import { map, place, collection } from './geo/resource.js';
3+
import { auth } from './auth/resource.js';
4+
5+
defineBackend({
6+
auth,
7+
map,
8+
place,
9+
collection,
10+
});

0 commit comments

Comments
 (0)