97 lines
2.2 KiB
TypeScript
97 lines
2.2 KiB
TypeScript
import type {
|
|
AuthUser,
|
|
Hoa,
|
|
HoaId,
|
|
Membership,
|
|
MembershipId,
|
|
Unit,
|
|
UnitId,
|
|
UserId,
|
|
} from '@dwellops/types';
|
|
|
|
let _idCounter = 1;
|
|
|
|
/**
|
|
* Generates a deterministic test ID string.
|
|
* Resets on module re-import; do not rely on specific values across test files.
|
|
*/
|
|
function nextId(prefix: string): string {
|
|
return `${prefix}_test_${String(_idCounter++).padStart(4, '0')}`;
|
|
}
|
|
|
|
/**
|
|
* Resets the ID counter. Call in beforeEach if deterministic IDs matter.
|
|
*/
|
|
export function resetIdCounter(): void {
|
|
_idCounter = 1;
|
|
}
|
|
|
|
/**
|
|
* Creates a mock AuthUser. All fields are overridable.
|
|
*
|
|
* @param overrides - Partial AuthUser fields to override.
|
|
*/
|
|
export function makeUser(overrides: Partial<AuthUser> = {}): AuthUser {
|
|
return {
|
|
id: nextId('user') as UserId,
|
|
email: 'test@example.com',
|
|
name: 'Test User',
|
|
emailVerified: true,
|
|
image: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a mock Hoa record.
|
|
*
|
|
* @param overrides - Partial Hoa fields to override.
|
|
*/
|
|
export function makeHoa(overrides: Partial<Hoa> = {}): Hoa {
|
|
const id = nextId('hoa') as HoaId;
|
|
return {
|
|
id,
|
|
name: 'Test HOA',
|
|
slug: `test-hoa-${id}`,
|
|
description: null,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a mock Unit record.
|
|
*
|
|
* @param overrides - Partial Unit fields to override.
|
|
*/
|
|
export function makeUnit(overrides: Partial<Unit> = {}): Unit {
|
|
return {
|
|
id: nextId('unit') as UnitId,
|
|
hoaId: nextId('hoa') as HoaId,
|
|
identifier: '101',
|
|
address: null,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a mock Membership record.
|
|
*
|
|
* @param overrides - Partial Membership fields to override.
|
|
*/
|
|
export function makeMembership(overrides: Partial<Membership> = {}): Membership {
|
|
return {
|
|
id: nextId('membership') as MembershipId,
|
|
userId: nextId('user') as UserId,
|
|
hoaId: nextId('hoa') as HoaId,
|
|
unitId: null,
|
|
role: 'OWNER',
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
...overrides,
|
|
};
|
|
}
|