Skip to content

Commit

Permalink
test(notifications): gen2 integ tests (#3667)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha authored May 1, 2024
1 parent 1e6f42b commit 0ea629d
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 578 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "Aws Amplify",
"license": "Apache-2.0",
"dependencies": {
"express": "^4.18.2"
"express": "^4.19.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"testTargets" : [
{
"parallelizable" : true,
"target" : {
"containerPath" : "container:PushNotificationHostApp.xcodeproj",
"identifier" : "6084F1AB2967B87200434CBF",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AWSPinpointPushNotificationsPlugin
import AWSPinpointAnalyticsPlugin

let amplifyConfigurationFilePath = "testconfiguration/AWSPushNotificationPluginIntegrationTest-amplifyconfiguration"
let amplifyOutputsFilePath = "testconfiguration/AWSPushNotificationPluginIntegrationTest-amplifyconfiguration"
let amplifyOutputsFilePath = "testconfiguration/AWSPushNotificationPluginIntegrationTest-amplify_outputs"

var pushNotificationHubSubscription: UnsubscribeToken?
var analyticsHubSubscription: UnsubscribeToken?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest

final class PushNotificationHostAppUITests: XCTestCase {
let timeout = TimeInterval(3)
let timeout = TimeInterval(6)
let app = XCUIApplication()

lazy var deviceIdentifier: String? = {
Expand Down Expand Up @@ -82,9 +82,9 @@ final class PushNotificationHostAppUITests: XCTestCase {
initAmplify()
grantNotificationPermissionIfNeeded()

let identifyUserButton = app.buttons["Register Device"]
if identifyUserButton.waitForExistence(timeout: timeout) {
identifyUserButton.tap()
let registerDeviceButton = app.buttons["Register Device"]
if registerDeviceButton.waitForExistence(timeout: timeout) {
registerDeviceButton.tap()
} else {
XCTFail("Failed to find 'Register Device' button")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,117 @@ cp amplifyconfiguration.json ~/.aws-amplify/amplify-ios/testconfiguration/AWSPus
The following steps demonstrate to set up the same as above with Amplify CLI Gen2.
1. From a new folder, run `npm create amplify@beta`. This uses the following versions of the Amplify CLI, see `package.json` file below.
```json
{
...
"devDependencies": {
"@aws-amplify/backend": "^0.15.0",
"@aws-amplify/backend-cli": "^0.15.0",
"aws-cdk": "^2.139.0",
"aws-cdk-lib": "^2.139.0",
"constructs": "^10.3.0",
"esbuild": "^0.20.2",
"tsx": "^4.7.3",
"typescript": "^5.4.5"
},
"dependencies": {
"aws-amplify": "^6.2.0"
},
}
```

2. Update `amplify/backend.ts` to create the analytics stack (https://docs.amplify.aws/gen2/build-a-backend/add-aws-services/analytics/) and notifications stack

```ts
const pushNotificationStack = backend.createStack('pushNotification-analytics-stack')
const pinpoint = new CfnApp(pushNotificationStack, "PinPoint", {
name: "pushNotification-pinPoint"
})

const pinpointPolicy = new Policy(pushNotificationStack, "PinpointPolicy", {
policyName: "PinpointPolicy",
statements: [
new PolicyStatement({
actions: ["mobiletargeting:*"],
resources: [pinpoint.attrArn + "/*"],
}),
],
});

backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(pinpointPolicy)
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(pinpointPolicy)

backend.addOutput({
analytics: {
amazon_pinpoint: {
app_id: pinpoint.ref,
aws_region: Stack.of(pinpoint).region,
}
}
})

backend.addOutput({
notifications: {
amazon_pinpoint_app_id: pinpoint.ref,
aws_region: Stack.of(pushNotificationStack).region,
channels: ['APNS']
}
})
```

Update `amplify/auth/resource.ts`. The resulting file should look like this

```ts
import { defineAuth, defineFunction } 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
}
});

```

3. Deploy the backend with npx amplify sandbox

For example, this deploys to a sandbox env and generates the amplify_outputs.json file.

```
npx amplify sandbox --config-out-dir ./config --profile [PROFILE]
```

1. Copy `amplify_outputs.json` to `AWSPushNotificationPluginIntegrationTest-amplify_outputs.json` inside `~/.aws-amplify/amplify-ios/testconfiguration/`
4. Copy `amplify_outputs.json` to `AWSPushNotificationPluginIntegrationTest-amplify_outputs.json` inside `~/.aws-amplify/amplify-ios/testconfiguration/`
```
cp amplify_outputs.json ~/.aws-amplify/amplify-ios/testconfiguration/AWSPushNotificationPluginIntegrationTest-amplify_outputs.json
```

### Deploying from a branch (Optional)

If you want to be able utilize Git commits for deployments

1. Commit and push the files to a git repository.

2. Navigate to the AWS Amplify console (https://us-east-1.console.aws.amazon.com/amplify/home?region=us-east-1#/)

3. Click on "Try Amplify Gen 2" button.

4. Choose "Option 2: Start with an existing app", and choose Github, and press Next.

5. Find the repository and branch, and click Next

6. Click "Save and deploy" and wait for deployment to finish.

7. Generate the `amplify_outputs.json` configuration file

```
npx amplify generate outputs --branch main --app-id [APP_ID] --profile [AWS_PROFILE]
```

## Run Integration Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ At the time this was written, it follows the steps from here https://docs.amplif
"aws-amplify": "^6.2.0"
},
}
```
2. Update `amplify/storage/resource.ts`. The resulting file should look like this
Expand Down Expand Up @@ -213,7 +213,7 @@ cfnUserPool.addPropertyOverride(
For example, this deploys to a sandbox env and generates the amplify_outputs.json file.
```
npx amplify sandbox --config-out-dir ./config --config-version 1 --profile [PROFILE]
npx amplify sandbox --config-out-dir ./config --profile [PROFILE]
```
5. Copy the `amplify_outputs.json` file over to the test directory as `AWSS3StoragePluginTests-amplify_outputs.json`. The tests will automatically pick this file up. Create the directories in this path first if it currently doesn't exist.
Expand Down Expand Up @@ -241,5 +241,5 @@ If you want to be able utilize Git commits for deployments
10. Generate the `amplify_outputs.json` configuration file
```
npx amplify generate outputs --branch main --app-id [APP_ID] --profile [AWS_PROFILE] --config-version 1
npx amplify generate outputs --branch main --app-id [APP_ID] --profile [AWS_PROFILE]
```

0 comments on commit 0ea629d

Please sign in to comment.