Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

add resetDb fixtures

ThieryMichelb0c105ea1e96
diff --git a/.env.e2e b/.env.e2e
index f659be34..051658df 100644
--- a/.env.e2e
+++ b/.env.e2e
@@ -3,3 +3,5 @@ SKIP_PREFLIGHT_CHECK=true
VITE_SUPABASE_URL=http://127.0.0.1:54341
VITE_SB_PUBLISHABLE_KEY=sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH
VITE_IS_DEMO=false
+
+SERVICE_ROLE_KEY=eyJhbGciOiJFUzI1NiIsImtpZCI6ImIzM2Q0Njk2LWMwNzUtNGEzNy04OWRhLTVhYWM5ZjYwZDMxYyIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MjA4ODU4MjY4OH0.rCjn2ElCZyuZZY7MfYDzKmL_-gzSe91Vw8XryhpnKSblPiRpmOYVhG0C4SELh73WQpEkMfWH9d5sle4CogQ1Zw
diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts
new file mode 100644
index 00000000..f6038f33
--- /dev/null
+++ b/e2e/fixtures.ts
@@ -0,0 +1,54 @@
+import { test as base, expect } from "@playwright/test";
+import { createClient } from "@supabase/supabase-js";
+
+const adminSupabase = createClient(
+ process.env.VITE_SUPABASE_URL ?? "http://127.0.0.1:54341",
+ process.env.SERVICE_ROLE_KEY!,
+ { auth: { autoRefreshToken: false, persistSession: false } },
+);
+
+// Tables in FK-safe deletion order (children before parents)
+const TABLES = [
+ "tasks",
+ "contact_notes",
+ "deal_notes",
+ "deals",
+ "contacts",
+ "companies",
+ "tags",
+ "favicons_excluded_domains",
+ "configuration",
+ "sales",
+];
+
+async function resetDb() {
+ console.log("Resetting database...");
+ for (const table of TABLES) {
+ // Supabase client delete need a where clause to get executed, so we use one that will match on all rows (id is not null)
+ await adminSupabase.from(table).delete().not("id", "is", null);
+ }
+
+ // Delete all auth users (cascades to sales via DB trigger)
+ const { data } = await adminSupabase.auth.admin.listUsers();
+ console.log("auth users", { data });
+ await Promise.all(
+ data.users.map((user) => adminSupabase.auth.admin.deleteUser(user.id)),
+ );
+
+ console.log("Database reset success");
+}
+
+export const test = base.extend<{ resetDb: void }>({
+ resetDb: [
+ // The first argument to a Playwright fixture function must use object destructuring ({}) — _ is not allowed.
+ // Playwright uses this to statically analyze which fixtures are requested.
+ // eslint-disable-next-line no-empty-pattern
+ async ({}, use) => {
+ await resetDb();
+ await use();
+ },
+ { auto: true },
+ ],
+});
+
+export { expect };
diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.ts
index 1529bede..384c54b7 100644
--- a/e2e/onboarding.spec.ts
+++ b/e2e/onboarding.spec.ts
@@ -1,8 +1,20 @@
-import { test, expect } from "@playwright/test";
+import { test, expect } from "./fixtures";
test("user onboarding", async ({ page }) => {
await page.goto("http://localhost:5175/");
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Atomic CRM/);
+ await expect(page.getByText("Welcome to Atomic CRM")).toBeVisible();
+
+ await page.getByLabel("First name").fill("John");
+ await page.getByLabel("Last name").fill("Doe");
+ await page.getByLabel("Email").fill("[email protected]");
+ await page.getByLabel("Password").fill("password");
+ await page.getByRole("button", { name: "Create account" }).click();
+
+ await expect(page.getByText("What's next?")).toBeVisible();
+ await expect(page.getByText("Install Atomic CRM")).toBeVisible();
+ await expect(page.getByText("Add your first contact")).toBeVisible();
+ await expect(page.getByText("Add your first note")).toBeVisible();
});
diff --git a/makefile b/makefile
index fbce808d..86e3e602 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ start-app: ## start the app locally
npm run dev
start-app-e2e: ## start the app pointing to the e2e supabase instance
- npx vite --force --mode e2e &
+ npx vite --port 5175 --force --mode e2e &
stop-app-e2e:
kill $$(lsof -t -i:5175)
diff --git a/playwright.config.ts b/playwright.config.ts
index dfe72abf..1513fd54 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -1,18 +1,20 @@
-import { defineConfig, devices } from '@playwright/test';
+import { defineConfig, devices } from "@playwright/test";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
-// import dotenv from 'dotenv';
-// import path from 'path';
-// dotenv.config({ path: path.resolve(__dirname, '.env') });
+import dotenv from "dotenv";
+import path from "path";
+import { fileURLToPath } from "url";
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+dotenv.config({ path: path.resolve(__dirname, ".env.e2e") });
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
- testDir: './e2e',
+ testDir: "./e2e",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -22,31 +24,31 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
- reporter: 'html',
+ reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('')`. */
// baseURL: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
- trace: 'on-first-retry',
+ trace: "on-first-retry",
},
/* Configure projects for major browsers */
projects: [
{
- name: 'chromium',
- use: { ...devices['Desktop Chrome'] },
+ name: "chromium",
+ use: { ...devices["Desktop Chrome"] },
},
{
- name: 'firefox',
- use: { ...devices['Desktop Firefox'] },
+ name: "firefox",
+ use: { ...devices["Desktop Firefox"] },
},
{
- name: 'webkit',
- use: { ...devices['Desktop Safari'] },
+ name: "webkit",
+ use: { ...devices["Desktop Safari"] },
},
/* Test against mobile viewports. */