Files
zero-fucks-given/apps/backend/tests/functional/custom_fields/custom_fields_api.spec.ts
T
2026-09-02 09:19:43 +03:00

44 lines
1.3 KiB
TypeScript

import { test } from '@japa/runner'
import testUtils from '@adonisjs/core/services/test_utils'
import CustomField from '#base_modules/CustomField/model/custom_field'
import Tenant from '#base_modules/Tenant/model/tenant'
import { createAdminWithToken } from '#tests/utils/auth'
test.group('Custom fields API', (group) => {
group.each.setup(() => testUtils.db().withGlobalTransaction())
test('rejects an unauthenticated list request', async ({ client }) => {
const response = await client.get('/api/custom-fields')
response.assertStatus(401)
})
test('lists fields owned by the resolved tenant', async ({ assert, client }) => {
const { admin, token } = await createAdminWithToken([])
const tenant = await Tenant.create({
name: 'Metadata GmbH',
slug: 'metadata-gmbh',
status: 'active',
})
await tenant.related('admins').attach([admin.id])
await CustomField.create({
tenantId: tenant.id,
entityType: 'contact',
name: 'Customer tier',
key: 'customer_tier',
fieldType: 'text',
required: false,
options: null,
status: 'active',
})
const response = await client
.get('/api/custom-fields')
.header('X-Tenant-Id', String(tenant.id))
.bearerToken(token)
response.assertStatus(200)
assert.equal(response.body().data[0].key, 'customer_tier')
})
})