Skip to content

Commit aa3f752

Browse files
committed
chore: Add second user for milestone D4
Signed-off-by: SeeuSim <[email protected]>
1 parent 1ab506c commit aa3f752

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

backend/user/src/lib/db/seed.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import { generatePasswordHash } from '@/lib/passwords';
44

55
import { admin as adminTable, db, users as usersTable } from '.';
66

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+
];
1423

1524
const main = async () => {
1625
await db.transaction(async (tx) => {
@@ -27,15 +36,18 @@ const main = async () => {
2736

2837
await tx.delete(usersTable);
2938

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+
3951
await tx.insert(adminTable).values({ action: 'SEED' });
4052
} catch (error) {
4153
console.error('[Users]: An error occurred while seeding: ' + String(error));

0 commit comments

Comments
 (0)