@mars-stack/cli 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/e2e/README.md +1 -1
- package/template/e2e/api.spec.ts +2 -1
- package/template/e2e/auth.spec.ts +1 -1
- package/template/scripts/seed.contract.test.ts +15 -0
- package/template/scripts/seed.ts +1 -1
- package/template/src/app/api/csrf/route.test.ts +27 -0
- package/template/src/app/api/csrf/route.ts +1 -1
- package/template/src/features/auth/index.ts +2 -1
- package/template/src/features/auth/validators.ts +1 -1
package/package.json
CHANGED
package/template/e2e/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Playwright E2E — feature coverage map
|
|
2
2
|
|
|
3
|
-
Browser-level tests for user-visible behaviour. Run: `yarn test:e2e` from the project root (`playwright.config.ts`).
|
|
3
|
+
Browser-level tests for user-visible behaviour. Run: `yarn test:e2e` from the project root (`playwright.config.ts`). **First run:** install browsers with `npx playwright install` (or `npx playwright install --with-deps chromium` in CI — see the smoke recipe below).
|
|
4
4
|
|
|
5
5
|
## Smoke (MARS-044)
|
|
6
6
|
|
package/template/e2e/api.spec.ts
CHANGED
|
@@ -5,7 +5,8 @@ test.describe('API endpoints', () => {
|
|
|
5
5
|
const response = await request.get('/api/csrf');
|
|
6
6
|
expect(response.ok()).toBeTruthy();
|
|
7
7
|
const body = await response.json();
|
|
8
|
-
expect(body.
|
|
8
|
+
expect(body.token).toBeDefined();
|
|
9
|
+
expect(body.csrfToken).toBe(body.token);
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
test('readiness endpoint returns ok', async ({ request }) => {
|
|
@@ -3,7 +3,7 @@ import { test, expect } from '@playwright/test';
|
|
|
3
3
|
test.describe('Authentication flow', () => {
|
|
4
4
|
test('signup page loads', async ({ page }) => {
|
|
5
5
|
await page.goto('/register');
|
|
6
|
-
await expect(page
|
|
6
|
+
await expect(page.getByRole('heading', { name: /create your account/i })).toBeVisible();
|
|
7
7
|
await expect(page.locator('form')).toBeVisible();
|
|
8
8
|
});
|
|
9
9
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
describe('scripts/seed.ts', () => {
|
|
10
|
+
it('imports hashing from password-hash so prisma db seed works under tsx (no server-only)', () => {
|
|
11
|
+
const src = readFileSync(resolve(__dirname, 'seed.ts'), 'utf8');
|
|
12
|
+
expect(src).toContain("@mars-stack/core/auth/password-hash");
|
|
13
|
+
expect(src).not.toMatch(/from ['"]@mars-stack\/core\/auth\/password['"]/);
|
|
14
|
+
});
|
|
15
|
+
});
|
package/template/scripts/seed.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrismaClient } from '../prisma/generated/prisma/client.js';
|
|
2
2
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
3
|
-
import { hashPassword } from '@mars-stack/core/auth/password';
|
|
3
|
+
import { hashPassword } from '@mars-stack/core/auth/password-hash';
|
|
4
4
|
|
|
5
5
|
const adapter = new PrismaPg({
|
|
6
6
|
connectionString: process.env.DATABASE_URL!,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
+
|
|
4
|
+
const { mockRequireCSRFToken } = vi.hoisted(() => ({
|
|
5
|
+
mockRequireCSRFToken: vi.fn(),
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
vi.mock('@/lib/mars', () => ({
|
|
9
|
+
requireCSRFToken: mockRequireCSRFToken,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import { GET } from './route';
|
|
13
|
+
|
|
14
|
+
describe('GET /api/csrf', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('returns token and csrfToken with the same value', async () => {
|
|
20
|
+
mockRequireCSRFToken.mockResolvedValueOnce('test-csrf-value');
|
|
21
|
+
const response = await GET();
|
|
22
|
+
expect(response.status).toBe(200);
|
|
23
|
+
const body = (await response.json()) as { token: string; csrfToken: string };
|
|
24
|
+
expect(body.token).toBe('test-csrf-value');
|
|
25
|
+
expect(body.csrfToken).toBe('test-csrf-value');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -4,7 +4,7 @@ import { NextResponse } from 'next/server';
|
|
|
4
4
|
export async function GET() {
|
|
5
5
|
try {
|
|
6
6
|
const token = await requireCSRFToken();
|
|
7
|
-
return NextResponse.json({ token }, { status: 200 });
|
|
7
|
+
return NextResponse.json({ token, csrfToken: token }, { status: 200 });
|
|
8
8
|
} catch (error) {
|
|
9
9
|
console.error('CSRF token generation error:', error);
|
|
10
10
|
return NextResponse.json({ error: 'Failed to generate CSRF token' }, { status: 500 });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { AuthError, AuthUser, AuthErrorCode } from '@mars-stack/core/auth/types';
|
|
2
2
|
export { validateEmail, validatePassword, validateRequired } from '@mars-stack/core/auth/validators';
|
|
3
|
-
export { passwordSchema
|
|
3
|
+
export { passwordSchema } from '@mars-stack/core/auth/password-schema';
|
|
4
|
+
export { hashPassword, verifyPassword } from '@mars-stack/core/auth/password-hash';
|