-
Notifications
You must be signed in to change notification settings - Fork 127
feat(data) AppSync Events WebSocket Unit Tests + Integration Tests #3048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tylerjroach
merged 13 commits into
feat/appsync-events
from
tjroach/appsync-events-tests2
May 9, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f2b4f2
websocket unit tests
tylerjroach 87de0f4
Make websocket tests deterministic
mattcreaser 6dfbfb5
appsync events rest integration tests
tylerjroach 941a904
appsync events websocket integration tests
tylerjroach 9d1cb59
Merge branch 'tjroach/appsync-events-integration-tests' into tjroach/…
tylerjroach 4fb0da7
lint
tylerjroach 1187945
fix compile issue
tylerjroach 80b74b9
fix test hanging issue
tylerjroach 60afc87
fix custom channel
tylerjroach e75a888
fix test
tylerjroach b75211f
lint
tylerjroach 5024de4
Pr comments and gen2 backend files
tylerjroach 84bd0ff
lint
tylerjroach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
appsync/aws-sdk-appsync-events/src/androidTest/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.amazonaws.sdk.appsync.events.test"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| </manifest> |
21 changes: 21 additions & 0 deletions
21
appsync/aws-sdk-appsync-events/src/androidTest/backend/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ## AWS Amplify + AWS AppSync Events Template | ||
|
|
||
| ## Getting Started | ||
|
|
||
| 1. Setup AWS Account with Amplify | ||
|
|
||
| https://docs.amplify.aws/android/start/account-setup/ | ||
|
|
||
| 2. Install dependencies: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| 3. Deploy Sandbox | ||
|
|
||
| ```bash | ||
| npx ampx sandbox | ||
| ``` | ||
|
|
||
| 4. Make note of the amplify_outputs.json file that was generated. You will need to copy this file to the test project. |
20 changes: 20 additions & 0 deletions
20
appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| version: 1 | ||
| backend: | ||
| phases: | ||
| build: | ||
| commands: | ||
| - npm ci | ||
| - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID | ||
| frontend: | ||
| phases: | ||
| build: | ||
| commands: | ||
| - mkdir ./dist && touch ./dist/index.html | ||
| artifacts: | ||
| baseDirectory: dist | ||
| files: | ||
| - '**/*' | ||
| cache: | ||
| paths: | ||
| - node_modules/**/* | ||
| - .npm/**/* |
11 changes: 11 additions & 0 deletions
11
appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify/auth/resource.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineAuth } from '@aws-amplify/backend'; | ||
|
|
||
| /** | ||
| * Define and configure your auth resource | ||
| * @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
| */ | ||
| export const auth = defineAuth({ | ||
| loginWith: { | ||
| email: true, | ||
| }, | ||
| }); |
105 changes: 105 additions & 0 deletions
105
appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify/backend.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { defineBackend } from '@aws-amplify/backend' | ||
| import { auth } from './auth/resource' | ||
| import { | ||
| AuthorizationType, | ||
| CfnApi, | ||
| CfnChannelNamespace, | ||
| CfnApiKey, | ||
| } from 'aws-cdk-lib/aws-appsync' | ||
| import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam' | ||
|
|
||
| const backend = defineBackend({ auth }) | ||
|
|
||
| const customResources = backend.createStack('custom-resources-appsync-events') | ||
|
|
||
| const cfnEventAPI = new CfnApi(customResources, 'cfnEventAPI', { | ||
| name: 'appsync-events-integration-tests', | ||
| eventConfig: { | ||
| authProviders: [ | ||
| { authType: AuthorizationType.API_KEY }, | ||
| { authType: AuthorizationType.IAM }, | ||
| { | ||
| authType: AuthorizationType.USER_POOL, | ||
| cognitoConfig: { | ||
| awsRegion: customResources.region, | ||
| userPoolId: backend.auth.resources.userPool.userPoolId, | ||
| }, | ||
| } | ||
| ], | ||
| connectionAuthModes: [ | ||
| { authType: AuthorizationType.API_KEY }, | ||
| { authType: AuthorizationType.IAM }, | ||
| { authType: AuthorizationType.USER_POOL } | ||
| ], | ||
| defaultPublishAuthModes: [ | ||
| { authType: AuthorizationType.API_KEY }, | ||
| { authType: AuthorizationType.IAM }, | ||
| { authType: AuthorizationType.USER_POOL } | ||
| ], | ||
| defaultSubscribeAuthModes: [ | ||
| { authType: AuthorizationType.API_KEY }, | ||
| { authType: AuthorizationType.IAM }, | ||
| { authType: AuthorizationType.USER_POOL } | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| new CfnChannelNamespace(customResources, 'CfnEventsIntegrationTestsNamespace', { | ||
| apiId: cfnEventAPI.attrApiId, | ||
| name: 'default', | ||
| }) | ||
|
|
||
| new CfnChannelNamespace(customResources, 'CfnEventsIntegrationTestsCustomNamespace', { | ||
| apiId: cfnEventAPI.attrApiId, | ||
| name: 'custom', | ||
| }) | ||
|
|
||
| // attach a policy to the authenticated user role in our User Pool to grant access to the Event API: | ||
| backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy( | ||
| new Policy(customResources, 'AuthAppSyncEventPolicy', { | ||
| statements: [ | ||
| new PolicyStatement({ | ||
| actions: [ | ||
| 'appsync:EventConnect', | ||
| 'appsync:EventSubscribe', | ||
| 'appsync:EventPublish', | ||
| ], | ||
| resources: [`${cfnEventAPI.attrApiArn}/*`, `${cfnEventAPI.attrApiArn}`], | ||
| }), | ||
| ], | ||
| }) | ||
| ); | ||
|
|
||
| // Add the policy as an inline policy (not `addToPrincialPolicy`) to avoid circular deps | ||
| backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy( | ||
| new Policy(customResources, 'UnauthAppSyncEventPolicy', { | ||
| statements: [ | ||
| new PolicyStatement({ | ||
| actions: [ | ||
| 'appsync:EventConnect', | ||
| 'appsync:EventPublish', | ||
| 'appsync:EventSubscribe', | ||
| ], | ||
| resources: [`${cfnEventAPI.attrApiArn}/*`, `${cfnEventAPI.attrApiArn}`], | ||
| }), | ||
| ], | ||
| }) | ||
| ) | ||
|
|
||
| // Create an API key | ||
| const apiKey = new CfnApiKey(customResources, 'EventApiKey', { | ||
| apiId: cfnEventAPI.attrApiId, | ||
| description: 'API Key for Event API', | ||
| expires: Math.floor(Date.now() / 1000) + (37 * 24 * 60 * 60) // Set for 37 days | ||
| }) | ||
|
|
||
| backend.addOutput({ | ||
| custom: { | ||
| events: { | ||
| url: `https://${cfnEventAPI.getAtt('Dns.Http').toString()}/event`, | ||
| aws_region: customResources.region, | ||
| default_authorization_type: AuthorizationType.API_KEY, | ||
| api_key: apiKey.attrApiKey | ||
| }, | ||
| }, | ||
| }) |
3 changes: 3 additions & 0 deletions
3
appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "module" | ||
| } |
17 changes: 17 additions & 0 deletions
17
appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2022", | ||
| "module": "es2022", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "paths": { | ||
| "$amplify/*": [ | ||
| "../.amplify/generated/*" | ||
| ] | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.