-
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.
Merge pull request #50 from w3bdesign/backend
Upgrade packages
- Loading branch information
Showing
8 changed files
with
165 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
41 changes: 41 additions & 0 deletions
41
backend/src/database/migrations/1732141970009-ClearServices.spec.ts
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,41 @@ | ||
import { QueryRunner } from 'typeorm'; | ||
import { ClearServices1732141970009 } from './1732141970009-ClearServices'; | ||
|
||
describe('ClearServices1732141970009', () => { | ||
let migration: ClearServices1732141970009; | ||
let queryRunner: QueryRunner; | ||
|
||
beforeEach(() => { | ||
migration = new ClearServices1732141970009(); | ||
queryRunner = { | ||
query: jest.fn(), | ||
} as unknown as QueryRunner; | ||
}); | ||
|
||
describe('up', () => { | ||
it('should clear existing services and insert new Norwegian services', async () => { | ||
await migration.up(queryRunner); | ||
|
||
// Verify deletion queries | ||
expect(queryRunner.query).toHaveBeenCalledWith(`DELETE FROM "employee_services"`); | ||
expect(queryRunner.query).toHaveBeenCalledWith(`DELETE FROM "services"`); | ||
|
||
// Verify insertion of new services | ||
expect(queryRunner.query).toHaveBeenCalledWith(expect.stringContaining('INSERT INTO "services"')); | ||
expect(queryRunner.query).toHaveBeenCalledWith(expect.stringContaining('Standard Klipp')); | ||
expect(queryRunner.query).toHaveBeenCalledWith(expect.stringContaining('Styling Klipp')); | ||
expect(queryRunner.query).toHaveBeenCalledWith(expect.stringContaining('Skjegg Trim')); | ||
expect(queryRunner.query).toHaveBeenCalledWith(expect.stringContaining('Full Service')); | ||
}); | ||
}); | ||
|
||
describe('down', () => { | ||
it('should delete Norwegian services', async () => { | ||
await migration.down(queryRunner); | ||
|
||
expect(queryRunner.query).toHaveBeenCalledWith( | ||
`DELETE FROM "services" WHERE "name" IN ('Standard Klipp', 'Styling Klipp', 'Skjegg Trim', 'Full Service')` | ||
); | ||
}); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
backend/src/database/migrations/1732142680425-UpdateServices.spec.ts
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,48 @@ | ||
import { QueryRunner } from 'typeorm'; | ||
import { UpdateServices1732142680425 } from './1732142680425-UpdateServices'; | ||
|
||
describe('UpdateServices1732142680425', () => { | ||
let migration: UpdateServices1732142680425; | ||
let queryRunner: QueryRunner; | ||
let queryMock: jest.Mock; | ||
|
||
beforeEach(() => { | ||
queryMock = jest.fn(); | ||
queryRunner = { | ||
query: queryMock, | ||
} as unknown as QueryRunner; | ||
migration = new UpdateServices1732142680425(); | ||
}); | ||
|
||
describe('up', () => { | ||
it('should clear existing services and insert updated Norwegian services', async () => { | ||
await migration.up(queryRunner); | ||
|
||
// Verify deletion queries | ||
expect(queryRunner.query).toHaveBeenCalledWith(`DELETE FROM "employee_services"`); | ||
expect(queryRunner.query).toHaveBeenCalledWith(`DELETE FROM "services"`); | ||
|
||
// Verify insertion of updated services | ||
const insertQuery = queryMock.mock.calls[2][0]; | ||
expect(insertQuery).toContain('INSERT INTO "services"'); | ||
expect(insertQuery).toContain('Standard Klipp'); | ||
expect(insertQuery).toContain('299.00'); | ||
expect(insertQuery).toContain('Styling Klipp'); | ||
expect(insertQuery).toContain('399.00'); | ||
expect(insertQuery).toContain('Skjegg Trim'); | ||
expect(insertQuery).toContain('199.00'); | ||
expect(insertQuery).toContain('Full Service'); | ||
expect(insertQuery).toContain('549.00'); | ||
}); | ||
}); | ||
|
||
describe('down', () => { | ||
it('should delete updated Norwegian services', async () => { | ||
await migration.down(queryRunner); | ||
|
||
expect(queryRunner.query).toHaveBeenCalledWith( | ||
`DELETE FROM "services" WHERE "name" IN ('Standard Klipp', 'Styling Klipp', 'Skjegg Trim', 'Full Service')` | ||
); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { User } from './user.entity'; | ||
import * as bcrypt from 'bcrypt'; | ||
|
||
jest.mock('bcrypt'); | ||
|
||
describe('User Entity', () => { | ||
let user: User; | ||
|
||
beforeEach(() => { | ||
user = new User(); | ||
user.password = 'password123'; | ||
(bcrypt.genSalt as jest.Mock).mockResolvedValue('salt'); | ||
(bcrypt.hash as jest.Mock).mockResolvedValue('hashed_password'); | ||
(bcrypt.compare as jest.Mock).mockResolvedValue(true); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('hashPassword', () => { | ||
it('should hash the password before insert', async () => { | ||
await user.hashPassword(); | ||
|
||
expect(bcrypt.genSalt).toHaveBeenCalled(); | ||
expect(bcrypt.hash).toHaveBeenCalledWith('password123', 'salt'); | ||
expect(user.password).toBe('hashed_password'); | ||
}); | ||
|
||
it('should not hash the password if it has not been modified', async () => { | ||
user.password = undefined; | ||
await user.hashPassword(); | ||
|
||
expect(bcrypt.genSalt).not.toHaveBeenCalled(); | ||
expect(bcrypt.hash).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('validatePassword', () => { | ||
it('should return true for valid password', async () => { | ||
const isValid = await user.validatePassword('password123'); | ||
|
||
expect(bcrypt.compare).toHaveBeenCalledWith('password123', 'password123'); | ||
expect(isValid).toBe(true); | ||
}); | ||
|
||
it('should return false for invalid password', async () => { | ||
(bcrypt.compare as jest.Mock).mockResolvedValue(false); | ||
|
||
const isValid = await user.validatePassword('wrongpassword'); | ||
|
||
expect(bcrypt.compare).toHaveBeenCalledWith('wrongpassword', 'password123'); | ||
expect(isValid).toBe(false); | ||
}); | ||
}); | ||
}); |