Skip to content

Commit

Permalink
Added dbcontroller test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeRenton committed May 7, 2024
1 parent 598aab2 commit 555a92c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/build/static/css/main.2f385a2d.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/build/static/js/main.0b5cbb4f.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ test("decipher map code with normal (\"advanced\") mode", () => {
const mapCode = '1A69B8588436798834058B';
const mapMode = "normal";

// const expectedOutput = {
// tiles: {
// '1': { png_num: '1', tile_num: 1 },
// '2': { png_num: 'A', tile_num: 4 },
// '3': { png_num: '6', tile_num: 6 },
// '4': { png_num: '9', tile_num: 3 },
// '5': { png_num: 'B', tile_num: 5 },
// '6': { png_num: '8', tile_num: 2 },
// },
// pieces: {
// white_standing_stone: { row: '5', col: '8' },
// green_standing_stone: { row: '8', col: '4' },
// blue_standing_stone: { row: '3', col: '6' },
// black_standing_stone: { row: '7', col: '9' },
// white_shack: { row: '8', col: '8' },
// green_shack: { row: '3', col: '4' },
// blue_shack: { row: '0', col: '5' },
// black_shack: { row: '8', col: 'B' },
// },
// };
const expectedOutput = {
tiles: {
'1': { png_num: '1', tile_num: 1 },
'2': { png_num: 'A', tile_num: 4 },
'3': { png_num: '6', tile_num: 6 },
'4': { png_num: '9', tile_num: 3 },
'5': { png_num: 'B', tile_num: 5 },
'6': { png_num: '8', tile_num: 2 },
},
pieces: {
white_standing_stone: { row: '5', col: '8' },
green_standing_stone: { row: '8', col: '4' },
blue_standing_stone: { row: '3', col: '6' },
black_standing_stone: { row: '7', col: '9' },
white_shack: { row: '8', col: '8' },
green_shack: { row: '3', col: '4' },
blue_shack: { row: '0', col: '5' },
black_shack: { row: '8', col: 'B' },
},
};

const output = controller.deciferMapCode(mapCode, mapMode);
expect(1).toEqual(1);
expect(expectedOutput).toEqual(output);
});
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);
});

0 comments on commit 555a92c

Please sign in to comment.