Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

test: add end to end tests for subscriptions #578

Merged
merged 4 commits into from
Feb 25, 2022

Conversation

ssvegaraju
Copy link
Contributor

Issue #, if available:

Description of changes:
Added end to end tests for empty notification and id notification scenarios. Tested using yarn int-test and making sure that the notification table and output looked as expected through the AWS Console.

Checklist:

  • Have you successfully deployed to an AWS account with your changes?
  • Have you written new tests for your core changes, as applicable?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ssvegaraju ssvegaraju requested a review from a team as a code owner February 24, 2022 09:00
Copy link
Contributor

@carvantes carvantes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. There are several minor changes to be made.

Also, can you add tests for Subscription validation? those ones are easy, just post invalid Subscriptions (non-allowlisted endpoint, unsupported channel, invalid criteria) and assert that you get a 400 error

integration-tests/subscriptions.test.ts Show resolved Hide resolved
const postPatientResult = await client.post('Patient', resourceThatMatchesSubscription);
expect(postPatientResult.status).toEqual(201);
// 3. Verify that notifications are received
// give 2 minutes for notification to be placed in ddb table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we need to wait one minute after creating the subscription but BEFORE posting the Patient that matches the subscription.(otherwise the Subscription may not be enabled yet due to caching)

I think that this needs to be fixed on tenant isolation tests as well

expect(postPatientResult.status).toEqual(201);
// 3. Verify that notifications are received
// give 2 minutes for notification to be placed in ddb table
await new Promise((r) => setTimeout(r, 120_000));
Copy link
Contributor

@carvantes carvantes Feb 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used several times, It'd be better to declare this helper function once.
You can move an existing sleep fn to test utils and then use it everywhere:

const sleep = async (milliseconds: number) => {

Comment on lines 148 to 151
// now we search for our patient to make sure it was updated correctly
const searchResult = await client.get(
`${subResource.criteria}&_lastUpdated=gt${new Date(new Date().getTime() - 180_000).toISOString()}`,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really needed. There are other existing tests for update/search

Comment on lines 103 to 108
let notifications = await subscriptionsHelper.getNotifications(
`/${uuid}/Patient/${postPatientResult.data.id}`,
);
expect(notifications).not.toEqual([]);
expect(notifications[0].httpMethod).toEqual('PUT');
expect(notifications[0].body).toBeNull();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be faster using waitForExpect. That way you don't need to wait an entire minute.

Also, can you assert that the headers match?

// 4. Delete the Subscription
const deleteSubscriptionResult = await client.delete(`Subscription/${postSubscriptionResult.data.id}`);
expect(deleteSubscriptionResult.status).toEqual(200);
await new Promise((r) => setTimeout(r, 120_000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wait can be only 1 minute

Comment on lines 96 to 97
// 2. Create/Update a resource that matches the subscription.
const postPatientResult = await client.post('Patient', resourceThatMatchesSubscription);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to test Update as well.

Comment on lines 125 to 127
notifications = await subscriptionsHelper.getNotifications(`/${uuid}/Patient/${postPatientResult.data.id}`);
// we still have the one notification from earlier in the test, but no more
expect(notifications.length).toEqual(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we also need to lookup notifications for postAnotherPatientResult.data.id and make sure that there are none.

integration-tests/subscriptions.test.ts Show resolved Hide resolved
await expect(client.post('Subscription', subResource)).rejects.toMatchObject({
response: { status: 400 },
});
subResource.channel.type = 'SMS';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be sms (case sensitive). Make sure that you are using the codes as they appear on https://fhir-ru.github.io/valueset-subscription-channel-type.html#expansion across this tests

Here you are getting a 404 because 'SMS' is an invalid code, so the validator (either HAPI or JSON schema) reject it, but what we want to test is the custom logic we wrote to reject valid channels that we don't support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I've updated the test to the correct spelling and also updated websocket to match the standard as well.

const notifications = await subscriptionsHelper.getNotifications(
`/${uuid}/Patient/${postPatientResult.data.id}`,
);
expect(notifications).not.toEqual([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove this line. The length check on the next line is sufficient

Comment on lines +148 to +150
expect(notifications[0].httpMethod).toEqual('PUT');
expect(notifications[0].body).toBeNull();
expect(notifications[0].headers).toHaveProperty('x-api-key', SUBSCRIPTIONS_API_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for completeness, can you also make this assertions for notifications[1]?

Comment on lines +209 to +211
expect(notifications[0].httpMethod).toEqual('POST');
expect(notifications[0].body).toBeNull();
expect(notifications[0].headers).toHaveProperty('x-api-key', SUBSCRIPTIONS_API_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, let's assert the same for notifications[1]

Copy link
Contributor

@carvantes carvantes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ssvegaraju ssvegaraju merged commit d83f52f into feat-subscriptions Feb 25, 2022
@ssvegaraju ssvegaraju deleted the test-subE2ETests branch February 25, 2022 08:30
carvantes added a commit that referenced this pull request Mar 7, 2022
* feat: add GSI to Resource DDB Table (#533)

* feat: Add data validation for subscription (#543)

* fix: remove _subsciptionStatus from export result field (#555)

* feat: sns, sqs, dlq for Subscriptions  (#554)

* feat: Rest hook Lambda (#558)

* feat: subscriptionReaper (#557)

* feat: add subscriptionsMatcher Lambda (#559)

* test: Add Subscriptions test infrastructure/helper (#569)

* fix: update unit tests for subscription reaper (#567)

* test: add subscriptions env vars in gh actions (#572)

* fix: encrypt logs for new Lambda fns (#574)

* test: add Subscription reaper tests (#575)

* feat: emit end to end latency metric from rest-hook Lambda (#570)

* test: add tests for tenant isolation of subscriptions (#577)

* feat: add DLQ for matcher Lambda (#576)

* test: add end to end tests for subscriptions (#578)

* perf: partial failures for restHook Lambda (#579)

* docs: add Subscription docs (#582)

Co-authored-by: Sukeerth Vegaraju <ssvegaraju@yahoo.co.in>
Co-authored-by: zheyanyu <zheyanyu@amazon.com>
Co-authored-by: Yanyu Zheng <yz2690@columbia.edu>
Co-authored-by: brndhpkn <98061326+brndhpkn@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants