Add comprehensive account and member API tests
12 new tests: search by email/phone, pagination params, sort order, billing mode, scoped member list, isMinor from DOB, DOB override, isMinor recalculation on update, 404 for missing member. Total: 36.
This commit is contained in:
@@ -100,4 +100,61 @@ suite('Accounts', { tags: ['accounts', 'crud'] }, (t) => {
|
||||
const refreshed = await t.api.get(`/v1/accounts/${acct.data.id}`)
|
||||
t.assert.equal(refreshed.data.primaryMemberId, first.data.id)
|
||||
})
|
||||
|
||||
t.test('searches by email', { tags: ['search'] }, async () => {
|
||||
await t.api.post('/v1/accounts', { name: 'Email Search', email: 'findme-unique@test.com' })
|
||||
|
||||
const res = await t.api.get('/v1/accounts', { q: 'findme-unique@test' })
|
||||
t.assert.status(res, 200)
|
||||
t.assert.ok(res.data.data.some((a: { email: string }) => a.email === 'findme-unique@test.com'))
|
||||
})
|
||||
|
||||
t.test('searches by phone', { tags: ['search'] }, async () => {
|
||||
await t.api.post('/v1/accounts', { name: 'Phone Search', phone: '555-UNIQUE-9876' })
|
||||
|
||||
const res = await t.api.get('/v1/accounts', { q: '555-UNIQUE-9876' })
|
||||
t.assert.status(res, 200)
|
||||
t.assert.ok(res.data.data.some((a: { phone: string }) => a.phone === '555-UNIQUE-9876'))
|
||||
})
|
||||
|
||||
t.test('paginates with page and limit', { tags: ['read', 'pagination'] }, async () => {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await t.api.post('/v1/accounts', { name: `Paginate ${i}` })
|
||||
}
|
||||
|
||||
const page1 = await t.api.get('/v1/accounts', { page: 1, limit: 2 })
|
||||
t.assert.status(page1, 200)
|
||||
t.assert.equal(page1.data.data.length, 2)
|
||||
t.assert.greaterThan(page1.data.pagination.totalPages, 1)
|
||||
|
||||
const page2 = await t.api.get('/v1/accounts', { page: 2, limit: 2 })
|
||||
t.assert.status(page2, 200)
|
||||
t.assert.equal(page2.data.data.length, 2)
|
||||
t.assert.notEqual(page1.data.data[0].id, page2.data.data[0].id)
|
||||
})
|
||||
|
||||
t.test('sorts by name descending', { tags: ['read', 'sort'] }, async () => {
|
||||
await t.api.post('/v1/accounts', { name: 'AAA Sort First' })
|
||||
await t.api.post('/v1/accounts', { name: 'ZZZ Sort Last' })
|
||||
|
||||
const res = await t.api.get('/v1/accounts', { sort: 'name', order: 'desc', limit: 100 })
|
||||
t.assert.status(res, 200)
|
||||
const names = res.data.data.map((a: { name: string }) => a.name)
|
||||
const zIdx = names.findIndex((n: string) => n.includes('ZZZ'))
|
||||
const aIdx = names.findIndex((n: string) => n.includes('AAA'))
|
||||
t.assert.ok(zIdx < aIdx, 'ZZZ should come before AAA in desc order')
|
||||
})
|
||||
|
||||
t.test('creates account with billing mode split', { tags: ['create'] }, async () => {
|
||||
const res = await t.api.post('/v1/accounts', { name: 'Split Billing', billingMode: 'split' })
|
||||
t.assert.status(res, 201)
|
||||
t.assert.equal(res.data.billingMode, 'split')
|
||||
})
|
||||
|
||||
t.test('updates billing mode', { tags: ['update'] }, async () => {
|
||||
const created = await t.api.post('/v1/accounts', { name: 'Change Billing' })
|
||||
const res = await t.api.patch(`/v1/accounts/${created.data.id}`, { billingMode: 'split' })
|
||||
t.assert.status(res, 200)
|
||||
t.assert.equal(res.data.billingMode, 'split')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user