-
Notifications
You must be signed in to change notification settings - Fork 514
fix(tests): use sql.json in onboarding migration test and refresh metrics snapshot #1420
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
base: dev
Are you sure you want to change the base?
Changes from all commits
e72e498
ca17a11
9f37134
82dd811
6306300
50430fb
35fd07b
0cd6bf8
41dbef8
6c3c1f2
367cacf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,16 +13,16 @@ | |
| expect(response.body).toHaveProperty("login_code"); | ||
| expect(response.body).toHaveProperty("expires_at"); | ||
|
|
||
| // Verify that the expiration time is about 2 hours from now | ||
| // Verify that the expiration time is about 2 minutes from now (default polling-code TTL) | ||
| const expiresAt = new Date(response.body.expires_at); | ||
| const now = new Date(); | ||
| const twoHoursInMs = 2 * 60 * 60 * 1000; | ||
| expect(expiresAt.getTime() - now.getTime()).toBeGreaterThan(twoHoursInMs - 10000); // Allow for a small margin of error | ||
| expect(expiresAt.getTime() - now.getTime()).toBeLessThan(twoHoursInMs + 10000); // Allow for a small margin of error | ||
| const twoMinutesInMs = 2 * 60 * 1000; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the time that I'm reviewing this, these tests are failing in CI on your branch. Since you touched them in this PR, could you take a look to see what's up? |
||
| expect(expiresAt.getTime() - now.getTime()).toBeGreaterThan(twoMinutesInMs - 10000); // Allow for a small margin of error | ||
|
Check failure on line 20 in apps/e2e/tests/backend/endpoints/api/v1/auth/cli/route.test.ts
|
||
| expect(expiresAt.getTime() - now.getTime()).toBeLessThan(twoMinutesInMs + 10000); // Allow for a small margin of error | ||
| }); | ||
|
|
||
| it("should create a new CLI auth attempt with custom expiration time", async ({ expect }) => { | ||
| const customExpirationMs = 30 * 60 * 1000; // 30 minutes | ||
| const customExpirationMs = 10 * 60 * 1000; // 10 minutes (max is 15) | ||
|
|
||
| const response = await niceBackendFetch("/api/latest/auth/cli", { | ||
| method: "POST", | ||
|
|
@@ -32,12 +32,12 @@ | |
| }, | ||
| }); | ||
|
|
||
| expect(response.status).toBe(200); | ||
|
Check failure on line 35 in apps/e2e/tests/backend/endpoints/api/v1/auth/cli/route.test.ts
|
||
| expect(response.body).toHaveProperty("polling_code"); | ||
| expect(response.body).toHaveProperty("login_code"); | ||
| expect(response.body).toHaveProperty("expires_at"); | ||
|
|
||
| // Verify that the expiration time is about 30 minutes from now | ||
| // Verify that the expiration time is about the requested 10 minutes from now | ||
| const expiresAt = new Date(response.body.expires_at); | ||
| const now = new Date(); | ||
| expect(expiresAt.getTime() - now.getTime()).toBeGreaterThan(customExpirationMs - 10000); // Allow for a small margin of error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { randomUUID } from "node:crypto"; | ||
| import { deepPlainEquals } from "@stackframe/stack-shared/dist/utils/objects"; | ||
| import { wait } from "@stackframe/stack-shared/dist/utils/promises"; | ||
| import { randomUUID } from "node:crypto"; | ||
| import { expect } from "vitest"; | ||
| import { NiceResponse, it } from "../../../../helpers"; | ||
| import { Auth, InternalApiKey, Project, Team, backendContext, createMailbox, niceBackendFetch } from "../../../backend-helpers"; | ||
|
|
@@ -173,12 +173,10 @@ | |
| backendContext.set({ mailbox: mailboxes[2], ipData: { country: "CH", ipAddress: "127.0.0.1", city: "Zurich", region: "ZH", latitude: 47.3769, longitude: 8.5417, tzIdentifier: "Europe/Zurich" } }); | ||
| await Auth.Otp.signIn(); | ||
|
|
||
| await wait(3000); // the event log is async, so let's give it some time to be written to the DB | ||
|
|
||
| const response = await niceBackendFetch("/api/v1/internal/metrics", { accessType: 'admin' }); | ||
| const response = await waitForMetricsToIncludeUsersByCountry({ countryCode: "CH", expectedCount: 1 }); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request: So it's great that you added polling helpers, but in line with the other polling helpers in test files you should probably have them throw on timeout. |
||
| expect(response).toMatchSnapshot(`metrics_result_with_users`); | ||
|
|
||
| await ensureAnonymousUsersAreStillExcluded(response); | ||
|
Check failure on line 179 in apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts
|
||
| }, { | ||
| timeout: 240_000, | ||
| }); | ||
|
|
@@ -299,9 +297,11 @@ | |
| await Auth.Anonymous.signUp(); | ||
| } | ||
|
|
||
| await wait(3000); // the event log is async, so let's give it some time to be written to the DB | ||
|
|
||
| const response = await niceBackendFetch("/api/v1/internal/metrics", { accessType: 'admin' }); | ||
| const response = await waitForMetricsMatch(false, (r) => { | ||
| if (r.body?.total_users !== 1) return false; | ||
| const dau = r.body?.daily_active_users?.[r.body.daily_active_users.length - 1]; | ||
| return dau?.activity === 1 && r.body?.users_by_country?.["CA"] === 1; | ||
| }); | ||
|
|
||
| // Should only count 1 regular user | ||
| expect(response.body.total_users).toBe(1); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.