-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathe2e.ts
More file actions
44 lines (39 loc) · 1.46 KB
/
e2e.ts
File metadata and controls
44 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { promises as fs } from 'fs';
import { Command } from 'commander';
import { type Context } from './types.js';
import { createTestDbSession, createE2eAuthContext } from '@gsa-tts/forms-auth';
export const addE2eCommands = (ctx: Context, cli: Command) => {
const cmd = cli
.command('e2e')
.description('End to end testing commands');
cmd
.command('create-test-session')
.description('Prepare the database and auth context for testing')
.requiredOption(
'-p, --path <string>',
'Path to the SQLite database file to prepare',
)
.requiredOption(
'-o, --output <string>',
'Path to output the .env file used for testing',
)
.action(async (options) => {
const dbPath = options.path;
const outputFile = options.output;
try {
console.log('Preparing database at:', dbPath);
const ctx = await createE2eAuthContext(dbPath);
const session = await createTestDbSession(ctx, 'test@example.com');
if(session && session.id) {
const envContent = `AUTH_SESSION=${session.id}\nE2E_ENDPOINT=http://localhost:4321\n`;
await fs.writeFile(outputFile, envContent, 'utf8');
console.log(`.env file written to: ${outputFile}`);
}
console.log('Auth Context & Database Prepared Successfully!');
} catch (error) {
console.error('Error preparing the database:', (error as Error).message);
} finally {
process.exit();
}
});
};