|
1 | 1 | import { describe, it, expect, beforeEach } from 'vitest' |
2 | 2 | import { setup, $fetch } from '@nuxt/test-utils' |
| 3 | +import { createUsersTable } from '../../src/runtime/server/utils/create-users-table' |
| 4 | +import { createPasswordResetTokensTable } from '../../src/runtime/server/utils/create-password-reset-tokens-table' |
| 5 | +import { addActiveToUsers } from '../../src/runtime/server/utils/add-active-to-users' |
| 6 | +import type { ModuleOptions } from '../../src/types' |
| 7 | +import { defaultOptions } from '../../src/module' |
| 8 | + |
| 9 | +async function setupDatabaseTables() { |
| 10 | + // Use the default options which match the playground configuration |
| 11 | + // The playground uses SQLite with path './data/users.sqlite3' by default |
| 12 | + const options: ModuleOptions = { |
| 13 | + ...defaultOptions, |
| 14 | + connector: { |
| 15 | + name: 'sqlite', |
| 16 | + options: { |
| 17 | + path: './data/users.sqlite3' |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + // Create all required tables |
| 23 | + await createUsersTable(options) |
| 24 | + await addActiveToUsers(options) |
| 25 | + await createPasswordResetTokensTable(options) |
| 26 | +} |
3 | 27 |
|
4 | 28 | describe('API: Registration', async () => { |
5 | 29 | await setup({ |
6 | 30 | rootDir: './playground' |
7 | 31 | }) |
8 | 32 |
|
9 | 33 | beforeEach(async () => { |
10 | | - // Clean up any existing test users |
11 | | - // Clean up any existing test users - we'll use a different approach |
12 | | - // since the DELETE method isn't available on the users endpoint |
| 34 | + // Set up database tables before each test |
| 35 | + await setupDatabaseTables() |
13 | 36 | }) |
14 | 37 |
|
15 | 38 | it('should register a new user successfully', async () => { |
|
0 commit comments