-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b18bd1a
commit b1bfded
Showing
7 changed files
with
24 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE users ADD COLUMN email VARCHAR(255) NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE users DROP COLUMN email; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,25 +47,29 @@ async function truncateTables (connection: Connection) { | |
} | ||
|
||
async function seedUsers (connection: Connection) { | ||
const usernames = ['basic', 'moderator', 'admin'] | ||
const users = [ | ||
{ username: 'basic', email: '[email protected]' }, | ||
{ username: 'moderator', email: '[email protected]' }, | ||
{ username: 'admin', email: '[email protected]' } | ||
] | ||
const hash = await scryptHash('password123$') | ||
|
||
// The goal here is to create a role hierarchy | ||
// E.g. an admin should have all the roles | ||
const rolesAccumulator: number[] = [] | ||
|
||
for (const username of usernames) { | ||
for (const user of users) { | ||
const [userResult] = await connection.execute(` | ||
INSERT INTO users (username, password) | ||
VALUES (?, ?) | ||
`, [username, hash]) | ||
INSERT INTO users (username, email, password) | ||
VALUES (?, ?, ?) | ||
`, [user.username, user.email, hash]) | ||
|
||
const userId = (userResult as { insertId: number }).insertId | ||
|
||
const [roleResult] = await connection.execute(` | ||
INSERT INTO roles (name) | ||
VALUES (?) | ||
`, [username]) | ||
`, [user.username]) | ||
|
||
const newRoleId = (roleResult as { insertId: number }).insertId | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ async function login (this: FastifyInstance, username: string) { | |
url: '/api/auth/login', | ||
payload: { | ||
username, | ||
email: '[email protected]', | ||
password: 'password123$' | ||
} | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import os from 'os' | |
|
||
async function createUser ( | ||
app: FastifyInstance, | ||
userData: Partial<{ username: string; password: string }> | ||
userData: Partial<{ username: string; email: string; password: string }> | ||
) { | ||
const [id] = await app.knex('users').insert(userData) | ||
return id | ||
|
@@ -52,10 +52,12 @@ describe('Tasks api (logged user only)', () => { | |
|
||
userId1 = await createUser(app, { | ||
username: 'user1', | ||
email: '[email protected]', | ||
password: 'password1' | ||
}) | ||
userId2 = await createUser(app, { | ||
username: 'user2', | ||
email: '[email protected]', | ||
password: 'password2' | ||
}) | ||
|
||
|