mirror of
https://github.com/whekin/household-bot.git
synced 2026-04-01 00:14:03 +00:00
feat(WHE-18): implement money, billing period, and typed domain ids
This commit is contained in:
34
packages/domain/src/ids.test.ts
Normal file
34
packages/domain/src/ids.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
|
||||
import { DOMAIN_ERROR_CODE, DomainError } from './errors'
|
||||
import { BillingCycleId, HouseholdId, MemberId, PurchaseEntryId } from './ids'
|
||||
|
||||
describe('IDs', () => {
|
||||
test('creates and compares typed ids', () => {
|
||||
const left = MemberId.from('member_1')
|
||||
const right = MemberId.from('member_1')
|
||||
|
||||
expect(left.equals(right)).toBe(true)
|
||||
expect(left.toString()).toBe('member_1')
|
||||
})
|
||||
|
||||
test('typed ids with same value and different type are not equal', () => {
|
||||
const member = MemberId.from('abc')
|
||||
const household = HouseholdId.from('abc')
|
||||
|
||||
expect(member.equals(household)).toBe(false)
|
||||
})
|
||||
|
||||
test('rejects invalid id values', () => {
|
||||
expect(() => BillingCycleId.from('')).toThrow(
|
||||
new DomainError(DOMAIN_ERROR_CODE.INVALID_ENTITY_ID, 'BillingCycleId cannot be empty')
|
||||
)
|
||||
|
||||
expect(() => PurchaseEntryId.from('bad value with space')).toThrow(
|
||||
new DomainError(
|
||||
DOMAIN_ERROR_CODE.INVALID_ENTITY_ID,
|
||||
'PurchaseEntryId contains invalid characters: bad value with space'
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user