-
Notifications
You must be signed in to change notification settings - Fork 4k
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.
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.
I'll think about this, as it will require reimplementing all the current setup.
@@ -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: |
/** | ||
* 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.
@@ -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?
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.
yes it is for the tests to treat them as commonjs
module, otherwise the @novu/testing
package won't work
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.
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.
partially, the nv_auth_token
is used in tests setup
|
||
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