Some checks failed
CI / skip-ci-check (pull_request) Successful in 1m19s
CI / lint-and-type-check (pull_request) Failing after 1m37s
CI / test (pull_request) Successful in 2m16s
CI / build (pull_request) Failing after 1m46s
CI / secret-scanning (pull_request) Successful in 1m20s
CI / dependency-scan (pull_request) Successful in 1m27s
CI / sast-scan (pull_request) Successful in 2m29s
CI / workflow-summary (pull_request) Successful in 1m18s
- Add duplicate photo detection (file hash and URL checking) - Add max attempts per photo with UI counter - Simplify penalty system (auto-enable when points > 0) - Prevent scores from going below 0 - Add admin photo deletion functionality - Improve navigation with always-visible logout - Prevent users from guessing their own photos
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { hashPassword, normalizeString } from '@/lib/utils'
|
|
import bcrypt from 'bcryptjs'
|
|
|
|
describe('lib/utils', () => {
|
|
describe('hashPassword', () => {
|
|
it('should hash a password', async () => {
|
|
const password = 'testpassword123'
|
|
const hash = await hashPassword(password)
|
|
|
|
expect(hash).toBeDefined()
|
|
expect(hash).not.toBe(password)
|
|
expect(hash.length).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('should produce different hashes for the same password', async () => {
|
|
const password = 'testpassword123'
|
|
const hash1 = await hashPassword(password)
|
|
const hash2 = await hashPassword(password)
|
|
|
|
// Hashes should be different (due to salt)
|
|
expect(hash1).not.toBe(hash2)
|
|
|
|
// But both should verify correctly
|
|
expect(await bcrypt.compare(password, hash1)).toBe(true)
|
|
expect(await bcrypt.compare(password, hash2)).toBe(true)
|
|
})
|
|
|
|
it('should verify passwords correctly', async () => {
|
|
const password = 'testpassword123'
|
|
const hash = await hashPassword(password)
|
|
|
|
expect(await bcrypt.compare(password, hash)).toBe(true)
|
|
expect(await bcrypt.compare('wrongpassword', hash)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('normalizeString', () => {
|
|
it('should trim whitespace', () => {
|
|
expect(normalizeString(' test ')).toBe('test')
|
|
expect(normalizeString(' test')).toBe('test')
|
|
expect(normalizeString('test ')).toBe('test')
|
|
})
|
|
|
|
it('should convert to lowercase', () => {
|
|
expect(normalizeString('TEST')).toBe('test')
|
|
expect(normalizeString('TeSt')).toBe('test')
|
|
expect(normalizeString('Test Name')).toBe('test name')
|
|
})
|
|
|
|
it('should handle empty strings', () => {
|
|
expect(normalizeString('')).toBe('')
|
|
expect(normalizeString(' ')).toBe('')
|
|
})
|
|
|
|
it('should handle special characters', () => {
|
|
expect(normalizeString(' Test-Name ')).toBe('test-name')
|
|
expect(normalizeString('John Doe')).toBe('john doe')
|
|
})
|
|
|
|
it('should handle mixed case with spaces', () => {
|
|
expect(normalizeString(' JOHN DOE ')).toBe('john doe')
|
|
expect(normalizeString('jOhN dOe')).toBe('john doe')
|
|
})
|
|
})
|
|
})
|