@@ -4,13 +4,22 @@ import { generatePasswordHash } from '@/lib/passwords';
4
4
5
5
import { admin as adminTable , db , users as usersTable } from '.' ;
6
6
7
- const TEST_USER_CREDENTIALS = {
8
- username : 'testuser01' ,
9
-
10
- firstName : 'test' ,
11
- lastName : 'user' ,
12
- password : '12345678' , // For local testing purposes
13
- } ;
7
+ const TEST_USER_CREDENTIALS = [
8
+ {
9
+ username : 'testuser01' ,
10
+
11
+ firstName : 'test' ,
12
+ lastName : 'user01' ,
13
+ password : '12345678' , // For local testing purposes
14
+ } ,
15
+ {
16
+ username : 'testuser02' ,
17
+
18
+ firstName : 'test' ,
19
+ lastName : 'user02' ,
20
+ password : '123456789' , // For local testing purposes
21
+ } ,
22
+ ] ;
14
23
15
24
const main = async ( ) => {
16
25
await db . transaction ( async ( tx ) => {
@@ -27,15 +36,18 @@ const main = async () => {
27
36
28
37
await tx . delete ( usersTable ) ;
29
38
30
- const password = generatePasswordHash ( TEST_USER_CREDENTIALS . password ) ;
31
- // Insert
32
- await tx
33
- . insert ( usersTable )
34
- . values ( {
35
- ...TEST_USER_CREDENTIALS ,
36
- password,
37
- } )
38
- . onConflictDoNothing ( ) ;
39
+ for ( const { password : ptPass , ...creds } of TEST_USER_CREDENTIALS ) {
40
+ const password = generatePasswordHash ( ptPass ) ;
41
+ // Insert
42
+ await tx
43
+ . insert ( usersTable )
44
+ . values ( {
45
+ ...creds ,
46
+ password,
47
+ } )
48
+ . onConflictDoNothing ( ) ;
49
+ }
50
+
39
51
await tx . insert ( adminTable ) . values ( { action : 'SEED' } ) ;
40
52
} catch ( error ) {
41
53
console . error ( '[Users]: An error occurred while seeding: ' + String ( error ) ) ;
0 commit comments