chore: cleanup package.json and automate api type generation
This commit is contained in:
@@ -38,4 +38,4 @@ describe("API Integration", () => {
|
||||
);
|
||||
expect([401, 422]).toContain(response.status);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,4 +20,4 @@ describe("Database Integration", () => {
|
||||
expect(user.email).toBe(adminEmail);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,4 +20,4 @@ describe("Feature Utilities", () => {
|
||||
delete process.env.TEST_ENV_KEY;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,113 +1,116 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe('API Key Management', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Mock the session API to simulate being logged in as an admin
|
||||
await page.route('**/api/session', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
user: {
|
||||
id: 'user_123',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
role: 'admin'
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
});
|
||||
test.describe("API Key Management", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Mock the session API to simulate being logged in as an admin
|
||||
await page.route("**/api/session", async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
user: {
|
||||
id: "user_123",
|
||||
name: "Test User",
|
||||
email: "test@example.com",
|
||||
role: "admin",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
// Mock the initial empty API keys list
|
||||
await page.route('**/api/apikey/', async (route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ apiKeys: [] }),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
});
|
||||
// Mock the initial empty API keys list
|
||||
await page.route("**/api/apikey/", async (route) => {
|
||||
if (route.request().method() === "GET") {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ apiKeys: [] }),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('should create, update, and delete an API key', async ({ page }) => {
|
||||
// Go to the API Keys page
|
||||
await page.goto('/dashboard/apikey');
|
||||
test("should create, update, and delete an API key", async ({ page }) => {
|
||||
// Go to the API Keys page
|
||||
await page.goto("/dashboard/apikey");
|
||||
|
||||
// 1. CREATE
|
||||
await page.click('button:has-text("Create New API Key")');
|
||||
await page.fill('input[placeholder="Enter a descriptive name for your API key"]', 'My Test Key');
|
||||
|
||||
// Mock the creation response
|
||||
await page.route('**/api/apikey/', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
apiKey: {
|
||||
id: 'key_1',
|
||||
name: 'My Test Key',
|
||||
key: 'sk-test-key-12345',
|
||||
isActive: true,
|
||||
expiresAt: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
// 1. CREATE
|
||||
await page.click('button:has-text("Create New API Key")');
|
||||
await page.fill(
|
||||
'input[placeholder="Enter a descriptive name for your API key"]',
|
||||
"My Test Key",
|
||||
);
|
||||
|
||||
await page.click('button:has-text("Create API Key")');
|
||||
// Mock the creation response
|
||||
await page.route("**/api/apikey/", async (route) => {
|
||||
if (route.request().method() === "POST") {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
apiKey: {
|
||||
id: "key_1",
|
||||
name: "My Test Key",
|
||||
key: "sk-test-key-12345",
|
||||
isActive: true,
|
||||
expiresAt: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Verify it appeared in the table
|
||||
const table = page.locator('table').first();
|
||||
await expect(table).toContainText('My Test Key');
|
||||
await expect(table).toContainText('••••••••');
|
||||
await page.click('button:has-text("Create API Key")');
|
||||
|
||||
// 2. UPDATE (Toggle status)
|
||||
// Mock the update response
|
||||
await page.route('**/api/apikey/update', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
apiKey: {
|
||||
id: 'key_1',
|
||||
name: 'My Test Key',
|
||||
key: 'sk-test-key-12345',
|
||||
isActive: false,
|
||||
expiresAt: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
}),
|
||||
});
|
||||
});
|
||||
// Verify it appeared in the table
|
||||
const table = page.locator("table").first();
|
||||
await expect(table).toContainText("My Test Key");
|
||||
await expect(table).toContainText("••••••••");
|
||||
|
||||
// Find and click the switch (Mantine Switch is usually an input type=checkbox)
|
||||
await page.click('input[type="checkbox"]', { force: true });
|
||||
|
||||
// 3. DELETE
|
||||
// Mock the delete response
|
||||
await page.route('**/api/apikey/delete', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ success: true }),
|
||||
});
|
||||
});
|
||||
// 2. UPDATE (Toggle status)
|
||||
// Mock the update response
|
||||
await page.route("**/api/apikey/update", async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
apiKey: {
|
||||
id: "key_1",
|
||||
name: "My Test Key",
|
||||
key: "sk-test-key-12345",
|
||||
isActive: false,
|
||||
expiresAt: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.click('button:has(svg.tabler-icon-trash)');
|
||||
await page.click('button:has-text("Delete API Key")');
|
||||
// Find and click the switch (Mantine Switch is usually an input type=checkbox)
|
||||
await page.click('input[type="checkbox"]', { force: true });
|
||||
|
||||
// Verify it's gone
|
||||
await expect(table).not.toContainText('My Test Key');
|
||||
await expect(page.locator('text=No API keys created yet')).toBeVisible();
|
||||
});
|
||||
// 3. DELETE
|
||||
// Mock the delete response
|
||||
await page.route("**/api/apikey/delete", async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ success: true }),
|
||||
});
|
||||
});
|
||||
|
||||
await page.click("button:has(svg.tabler-icon-trash)");
|
||||
await page.click('button:has-text("Delete API Key")');
|
||||
|
||||
// Verify it's gone
|
||||
await expect(table).not.toContainText("My Test Key");
|
||||
await expect(page.locator("text=No API keys created yet")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe('Login Flow', () => {
|
||||
test('should see signin page content', async ({ page }) => {
|
||||
// Go to the signin page
|
||||
await page.goto('/signin');
|
||||
test.describe("Login Flow", () => {
|
||||
test("should see signin page content", async ({ page }) => {
|
||||
// Go to the signin page
|
||||
await page.goto("/signin");
|
||||
|
||||
// Check if the signin page content is visible
|
||||
await expect(page.locator('h1')).toContainText('Welcome back!');
|
||||
await expect(page.locator('button:has-text("Sign in")')).toBeVisible();
|
||||
await expect(page.locator('button:has-text("Continue with GitHub")')).toBeVisible();
|
||||
});
|
||||
// Check if the signin page content is visible
|
||||
await expect(page.locator("h1")).toContainText("Welcome back!");
|
||||
await expect(page.locator('button:has-text("Sign in")')).toBeVisible();
|
||||
await expect(
|
||||
page.locator('button:has-text("Continue with GitHub")'),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test('should redirect to signin if not authenticated', async ({ page }) => {
|
||||
// Clear cookies/storage to ensure we are not authenticated
|
||||
await page.goto('/signin');
|
||||
await page.context().clearCookies();
|
||||
await page.evaluate(() => localStorage.clear());
|
||||
|
||||
// Try to access the profile page (which is protected)
|
||||
await page.goto('/profile');
|
||||
test("should redirect to signin if not authenticated", async ({ page }) => {
|
||||
// Clear cookies/storage to ensure we are not authenticated
|
||||
await page.goto("/signin");
|
||||
await page.context().clearCookies();
|
||||
await page.evaluate(() => localStorage.clear());
|
||||
|
||||
// Should be redirected back to signin
|
||||
await expect(page).toHaveURL(/\/signin/);
|
||||
});
|
||||
});
|
||||
// Try to access the profile page (which is protected)
|
||||
await page.goto("/profile");
|
||||
|
||||
// Should be redirected back to signin
|
||||
await expect(page).toHaveURL(/\/signin/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe('Signup Flow', () => {
|
||||
test('should see signup page content', async ({ page }) => {
|
||||
// Go to the signup page
|
||||
await page.goto('/signup');
|
||||
test.describe("Signup Flow", () => {
|
||||
test("should see signup page content", async ({ page }) => {
|
||||
// Go to the signup page
|
||||
await page.goto("/signup");
|
||||
|
||||
// Check if the signup page content is visible
|
||||
await expect(page.locator('h1')).toContainText('Create an account');
|
||||
await expect(page.locator('button:has-text("Create account")')).toBeVisible();
|
||||
|
||||
// Check for form fields
|
||||
await expect(page.getByPlaceholder('Your name')).toBeVisible();
|
||||
await expect(page.getByPlaceholder('your@email.com')).toBeVisible();
|
||||
await expect(page.getByPlaceholder('Your password')).toBeVisible();
|
||||
});
|
||||
// Check if the signup page content is visible
|
||||
await expect(page.locator("h1")).toContainText("Create an account");
|
||||
await expect(
|
||||
page.locator('button:has-text("Create account")'),
|
||||
).toBeVisible();
|
||||
|
||||
test('should navigate to signin page from signup', async ({ page }) => {
|
||||
await page.goto('/signup');
|
||||
|
||||
// Click on "Sign in" link
|
||||
await page.click('button:has-text("Sign in")');
|
||||
// Check for form fields
|
||||
await expect(page.getByPlaceholder("Your name")).toBeVisible();
|
||||
await expect(page.getByPlaceholder("your@email.com")).toBeVisible();
|
||||
await expect(page.getByPlaceholder("Your password")).toBeVisible();
|
||||
});
|
||||
|
||||
// Should be redirected to signin
|
||||
await expect(page).toHaveURL(/\/signin/);
|
||||
});
|
||||
test("should navigate to signin page from signup", async ({ page }) => {
|
||||
await page.goto("/signup");
|
||||
|
||||
// Click on "Sign in" link
|
||||
await page.click('button:has-text("Sign in")');
|
||||
|
||||
// Should be redirected to signin
|
||||
await expect(page).toHaveURL(/\/signin/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user