Files
supabase/apps/studio/lib/password-strength.test.ts
T
Alaister YoungandCharis a3e7cb7285 chore: move password check to frontend (#39927)
* chore: move password check to frontend

* remove barrel file export and fix test import

* move import inside function

* Update apps/studio/lib/password-strength.ts

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* fix test

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2025-10-28 23:24:35 +08:00

34 lines
1.4 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest'
import { passwordStrength } from './password-strength'
describe('passwordStrength', () => {
it('returns empty values for message, warning and strength for empty input', async () => {
const result = await passwordStrength('')
expect(result).toEqual({ message: '', warning: '', strength: 0 })
})
it('returns max length message, warning, and strength 0 for password longer than 99 characters', async () => {
const longPassword = 'a'.repeat(100)
const result = await passwordStrength(longPassword)
expect(result.message).toMatch(/maximum length/i)
expect(result.warning).toMatch(/less than 100 characters/i)
expect(result.strength).toBe(0)
})
it('returns strong score, suggestion, and empty warning for strong password', async () => {
const result = await passwordStrength('ActuallyAStrongPassword123!')
expect(result.message).toMatch(/strong/i)
expect(result.message).toContain('This password is strong')
expect(result.warning).toBe('')
expect(result.strength).toBe(4)
})
it('returns weak score, suggestion, and warning for weak password', async () => {
const result = await passwordStrength('weak')
expect(result.message).toMatch(/not secure/i)
expect(result.message).toContain('This password is not secure enough')
expect(result.warning).toMatch(/you need a stronger password/i)
expect(result.strength).toBe(1)
})
})