-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore(dashboard): user journey smoke tests #7124
base: next
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
apps/api/.gitignore
Outdated
@@ -121,3 +121,4 @@ backups/ | |||
|
|||
# Nest.js auto-generated metadata (https://docs.nestjs.com/recipes/swc#monorepo-and-cli-plugins) | |||
src/metadata.ts | |||
src/.env.test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the .env.test
file from git, because the local file that I used for the tests had sensitive clerk credentials
@@ -28,4 +28,6 @@ tsconfig.node.tsbuildinfo | |||
/test-results/ | |||
/playwright-report/ | |||
/blob-report/ | |||
/playwright/.cache/ | |||
/playwright/ | |||
.env.test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.env.test
is the file for the Dashboard env variables
/playwright/.cache/ | ||
/playwright/ | ||
.env.test | ||
.env.playwright |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.env.playwright
is the file for the playwright that has all env variables to setup the clerk and api session
@@ -5,6 +5,7 @@ | |||
"type": "module", | |||
"scripts": { | |||
"start": "vite", | |||
"start:test": "vite --mode test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run dashboard and use .env.test
file
"@novu/dal": "workspace:*", | ||
"@novu/testing": "workspace:*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used to initialize the api session
bridgeServer = new BridgeServer({ secretKey: session.environment.apiKeys[0].key, apiUrl: process.env.API_URL }); | ||
|
||
const newWorkflow = workflow(workflowId, async ({ step }) => { | ||
await step.inApp( | ||
inAppStepId, | ||
async (controls) => { | ||
return { | ||
subject: `Hi ${controls.name}! You've been invited to join the Novu project`, | ||
body, | ||
}; | ||
}, | ||
{ | ||
controlSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', default: 'John' }, | ||
}, | ||
} as const, | ||
} | ||
); | ||
}); | ||
await bridgeServer.start({ workflows: [newWorkflow] }); | ||
await session.testAgent.post(`/v1/bridge/sync`).send({ | ||
bridgeUrl: bridgeServer.serverPath, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run the bridge server and sync the workflow
await session.testAgent.post(`/v1/bridge/sync`).send({ | ||
bridgeUrl: bridgeServer.serverPath, | ||
}); | ||
await page.waitForTimeout(2000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed
/** | ||
* TODO: Currently we are running tests with a single Clerk user and organization. | ||
* This approach has a drawback that the tests are not independent from each other and write the data to the same organization. | ||
* We should consider creating a new Clerk user and organization for each test using the @clerk/backend package. | ||
* Then initialize the BE session with the new Clerk user and organization and update Clerk user metadata from the newly created session. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully, it explains the problem well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! We should leverage Clerk Backend API, create a user before every run, sign in with that user, and then delete the user at the end.
Regarding the need for Clerk webhooks during user and organization creation, I suggest connecting to Mongo directly from the test code using the response of the Clerk API to create the user and organization record the application needs to function.
On user deletion, I don't think we need to do anything in Mongo as we run in a dockerized environment.
@@ -0,0 +1,3 @@ | |||
{ | |||
"type": "commonjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dal
and testing
packages are CJS modules which can't be imported by the ESM modules.
So this is the trick (together with tsconfig.json) to say "please allow me to import" in my test files :D
private memberRepository = getEERepository<MemberRepository>('MemberRepository'); | ||
private memberRepository: MemberRepository; | ||
|
||
constructor({ mockClerkClient = true }: { mockClerkClient?: boolean } = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the Dashboard E2E tests we don't want to mock the Clerk client, because we initialize the Clerk session with a real user that has the org and metadata that is used by the Dashboard code.
@novu/client
@novu/framework
@novu/js
@novu/nest
@novu/headless
@novu/nextjs
@novu/node
@novu/notification-center
novu
@novu/providers
@novu/react
@novu/react-native
@novu/shared
@novu/stateless
commit: |
@@ -0,0 +1,115 @@ | |||
import { StepTypeEnum } from '@novu/shared'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about naming it from the user journey perspective? For example: manage-workflows.e2e.ts
.
I added the e2e extension as we have the convention with e2e testing file naming on the API.
@@ -0,0 +1,90 @@ | |||
import { test } from '@playwright/test'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about naming it from the user journey perspective? For example: sync-workflow.e2e.ts.
await bridgeServer.stop(); | ||
}); | ||
|
||
test('code defined workflow user journey', async ({ page }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('code defined workflow user journey', async ({ page }) => { | |
test('sync workflow', async ({ page }) => { |
await initializeSession({ page }); | ||
}); | ||
|
||
test('dashboard defined workflow user journey', async ({ page }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('dashboard defined workflow user journey', async ({ page }) => { | |
test('manage workflows', async ({ page }) => { |
/** | ||
* TODO: Currently we are running tests with a single Clerk user and organization. | ||
* This approach has a drawback that the tests are not independent from each other and write the data to the same organization. | ||
* We should consider creating a new Clerk user and organization for each test using the @clerk/backend package. | ||
* Then initialize the BE session with the new Clerk user and organization and update Clerk user metadata from the newly created session. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! We should leverage Clerk Backend API, create a user before every run, sign in with that user, and then delete the user at the end.
Regarding the need for Clerk webhooks during user and organization creation, I suggest connecting to Mongo directly from the test code using the response of the Clerk API to create the user and organization record the application needs to function.
On user deletion, I don't think we need to do anything in Mongo as we run in a dockerized environment.
} | ||
|
||
async expectNameValidationError(): Promise<void> { | ||
await expect(await this.page.getByText('Name is required')).toBeVisible(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Page object models are usually selectors and request helpers that keep the e2e code dry. To me, expectations belong to the test. Moreover, E2E tests have to be readable and self-explanatory. Dryness is not the most critical requirement.
So, I suggest adding all the expectations in the e2e file and using the page object models for selectors, event listeners and waiting logic. This ensures that page object models are highly reusable and can work with any expectation the e2e will require.
Most importantly, when the e2e is read by the future maintainer, they don't have to jump into every function to see what it does.
const workflowIdInput = await this.page.locator('input[name="workflowId"]'); | ||
|
||
// check the workflow id | ||
await expect(await workflowIdInput.inputValue()).toEqual(workflowId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following on my previous comment, this is a good example of overloading a page object function with expectation logic that belongs to the test.
@@ -0,0 +1,10 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the extra tsconfig.json required?
await page.addInitScript((currentSession) => { | ||
window.addEventListener('DOMContentLoaded', () => { | ||
localStorage.setItem('nv_auth_token', currentSession.token); | ||
localStorage.setItem('nv_last_environment_id', currentSession.environment._id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer required in the new dashboard. We can safely remove it.
|
||
return new EEMemberRepository(new CommunityOrganizationRepository(), new ClerkClientMock()); | ||
if (mockClerkClient) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to my previous comment about creating a Clerk user before each test run and doing an actual sign-in so that we can test the actual interaction between Clerk and the application, not a mocked version of it.
What changed? Why was the change needed?
Dashboard - the core user journeys smoke tests that cover:
TODO (in the future):
Screenshots