-
Notifications
You must be signed in to change notification settings - Fork 0
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
598aab2
commit 555a92c
Showing
4 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
server/__tests__/controller_tests/dbController_tests/dbController.test.js
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,27 @@ | ||
const dbController = require('../../../controllers/dbController'); | ||
|
||
test("addUser function", async () => { | ||
const client = { | ||
query: jest.fn().mockResolvedValue({ rows: [{ username: 'test', password: 'test' }] }), | ||
}; | ||
const username = 'test'; | ||
const password = 'test'; | ||
|
||
const result = await dbController.addUser(client, username, password); | ||
|
||
expect(client.query).toHaveBeenCalledWith('INSERT INTO users (username, password) VALUES ($1, $2) RETURNING *;', [username, password]); | ||
expect(result).toEqual({ username: 'test', password: 'test' }); | ||
}); | ||
|
||
test("validateUserLogin function", async () => { | ||
const client = { | ||
query: jest.fn().mockResolvedValue({ rows: [{ username: 'test', password: 'test' }] }), | ||
}; | ||
const username = 'test'; | ||
const password = 'test'; | ||
|
||
const result = await dbController.validateUserLogin(client, username, password); | ||
|
||
expect(client.query).toHaveBeenCalledWith('SELECT * FROM users WHERE username = $1 AND password = $2;', [username, password]); | ||
expect(result).toBe(true); | ||
}); |