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:
@@ -163,4 +163,69 @@ suite('Members', { tags: ['members', 'crud'] }, (t) => {
|
||||
const res = await t.api.del(`/v1/members/${member.data.id}`)
|
||||
t.assert.status(res, 200)
|
||||
})
|
||||
|
||||
t.test('lists members for a specific account', { tags: ['read'] }, async () => {
|
||||
const acct1 = await t.api.post('/v1/accounts', { name: 'Scoped List A' })
|
||||
const acct2 = await t.api.post('/v1/accounts', { name: 'Scoped List B' })
|
||||
await t.api.post(`/v1/accounts/${acct1.data.id}/members`, { firstName: 'In', lastName: 'Scope' })
|
||||
await t.api.post(`/v1/accounts/${acct2.data.id}/members`, { firstName: 'Out', lastName: 'Scope' })
|
||||
|
||||
const res = await t.api.get(`/v1/accounts/${acct1.data.id}/members`)
|
||||
t.assert.status(res, 200)
|
||||
t.assert.equal(res.data.data.length, 1)
|
||||
t.assert.equal(res.data.data[0].firstName, 'In')
|
||||
})
|
||||
|
||||
t.test('derives isMinor from child DOB', { tags: ['create'] }, async () => {
|
||||
const acct = await t.api.post('/v1/accounts', { name: 'Minor DOB Test' })
|
||||
const res = await t.api.post(`/v1/accounts/${acct.data.id}/members`, {
|
||||
firstName: 'Young',
|
||||
lastName: 'Kid',
|
||||
dateOfBirth: '2020-01-01',
|
||||
})
|
||||
t.assert.status(res, 201)
|
||||
t.assert.equal(res.data.isMinor, true)
|
||||
})
|
||||
|
||||
t.test('derives isMinor as false from adult DOB', { tags: ['create'] }, async () => {
|
||||
const acct = await t.api.post('/v1/accounts', { name: 'Adult DOB Test' })
|
||||
const res = await t.api.post(`/v1/accounts/${acct.data.id}/members`, {
|
||||
firstName: 'Grown',
|
||||
lastName: 'Up',
|
||||
dateOfBirth: '1985-06-15',
|
||||
})
|
||||
t.assert.status(res, 201)
|
||||
t.assert.equal(res.data.isMinor, false)
|
||||
})
|
||||
|
||||
t.test('explicit isMinor overrides DOB calculation', { tags: ['create'] }, async () => {
|
||||
const acct = await t.api.post('/v1/accounts', { name: 'Override Minor' })
|
||||
const res = await t.api.post(`/v1/accounts/${acct.data.id}/members`, {
|
||||
firstName: 'Override',
|
||||
lastName: 'Test',
|
||||
dateOfBirth: '1985-06-15',
|
||||
isMinor: true,
|
||||
})
|
||||
t.assert.status(res, 201)
|
||||
t.assert.equal(res.data.isMinor, true)
|
||||
})
|
||||
|
||||
t.test('update recalculates isMinor when DOB changes', { tags: ['update'] }, async () => {
|
||||
const acct = await t.api.post('/v1/accounts', { name: 'Recalc Test' })
|
||||
const member = await t.api.post(`/v1/accounts/${acct.data.id}/members`, {
|
||||
firstName: 'Age',
|
||||
lastName: 'Change',
|
||||
dateOfBirth: '2020-01-01',
|
||||
})
|
||||
t.assert.equal(member.data.isMinor, true)
|
||||
|
||||
const res = await t.api.patch(`/v1/members/${member.data.id}`, { dateOfBirth: '1980-01-01' })
|
||||
t.assert.status(res, 200)
|
||||
t.assert.equal(res.data.isMinor, false)
|
||||
})
|
||||
|
||||
t.test('returns 404 for missing member', { tags: ['read'] }, async () => {
|
||||
const res = await t.api.get('/v1/members/a0000000-0000-0000-0000-999999999999')
|
||||
t.assert.status(res, 404)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user