|
|
@@ -0,0 +1,79 @@
|
|
|
+import MockAdapter from 'axios-mock-adapter'
|
|
|
+import axios from '@/utils/request'
|
|
|
+import {
|
|
|
+ listIndicatorDefinitions,
|
|
|
+ saveIndicatorCorrelation,
|
|
|
+ listIndicatorCorrelations,
|
|
|
+ calibrateIndicatorCorrelations,
|
|
|
+ importIndicatorMappings,
|
|
|
+ listIndicatorMappings
|
|
|
+} from '@/api/indicator'
|
|
|
+
|
|
|
+let mock
|
|
|
+
|
|
|
+beforeEach(() => {
|
|
|
+ mock = new MockAdapter(axios)
|
|
|
+})
|
|
|
+
|
|
|
+afterEach(() => {
|
|
|
+ mock.restore()
|
|
|
+})
|
|
|
+
|
|
|
+describe('indicator admin API', () => {
|
|
|
+ test('listIndicatorDefinitions sends POST to /api/admin/indicator/list', async () => {
|
|
|
+ mock.onPost('/api/admin/indicator/list').reply(200, { code: 200, data: [{ id: 1, name: '乳酸菌' }] })
|
|
|
+ const res = await listIndicatorDefinitions({ domain: 'gut', status: 1 })
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(res.data).toEqual([{ id: 1, name: '乳酸菌' }])
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/list')
|
|
|
+ expect(mock.history.post[0].method).toBe('post')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('saveIndicatorCorrelation sends POST with body', async () => {
|
|
|
+ const body = { definitionIdA: 1, definitionIdB: 2, direction: 'positive', manualStrength: 0.6, description: 'x', manualLocked: false, sourceNote: 'y' }
|
|
|
+ mock.onPost('/api/admin/indicator/correlation/save').reply(200, { code: 200, data: true })
|
|
|
+ const res = await saveIndicatorCorrelation(body)
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/correlation/save')
|
|
|
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject(body)
|
|
|
+ })
|
|
|
+
|
|
|
+ test('listIndicatorCorrelations sends POST with page/size', async () => {
|
|
|
+ mock.onPost('/api/admin/indicator/correlation/list').reply(200, { code: 200, data: { records: [{ id: 1 }], total: 1 } })
|
|
|
+ const res = await listIndicatorCorrelations({ page: 1, size: 10 })
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(res.data.records).toEqual([{ id: 1 }])
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/correlation/list')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('calibrateIndicatorCorrelations sends POST with empty body', async () => {
|
|
|
+ mock.onPost('/api/admin/indicator/correlation/calibrate').reply(200, { code: 200, message: '校准完成,共更新 0 对' })
|
|
|
+ const res = await calibrateIndicatorCorrelations({})
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/correlation/calibrate')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('calibrateIndicatorCorrelations sends pairId in body', async () => {
|
|
|
+ mock.onPost('/api/admin/indicator/correlation/calibrate').reply(200, { code: 200, message: '校准完成,共更新 1 对' })
|
|
|
+ const res = await calibrateIndicatorCorrelations({ pairId: 1 })
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({ pairId: 1 })
|
|
|
+ })
|
|
|
+
|
|
|
+ test('importIndicatorMappings sends POST with seeds', async () => {
|
|
|
+ const body = { sourceType: 'gut', seeds: [{ rawName: '乳酸菌', definitionId: 3 }] }
|
|
|
+ mock.onPost('/api/admin/indicator/mapping/import').reply(200, { code: 200, message: '导入完成,共 1 条' })
|
|
|
+ const res = await importIndicatorMappings(body)
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/mapping/import')
|
|
|
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject(body)
|
|
|
+ })
|
|
|
+
|
|
|
+ test('listIndicatorMappings sends POST with status/sourceType', async () => {
|
|
|
+ mock.onPost('/api/admin/indicator/mapping/list').reply(200, { code: 200, data: { records: [], total: 0 } })
|
|
|
+ const res = await listIndicatorMappings({ page: 1, size: 10, status: 0, sourceType: 'gut' })
|
|
|
+ expect(res.code).toBe(200)
|
|
|
+ expect(JSON.parse(mock.history.post[0].data)).toMatchObject({ page: 1, size: 10, status: 0, sourceType: 'gut' })
|
|
|
+ expect(mock.history.post[0].url).toBe('/api/admin/indicator/mapping/list')
|
|
|
+ })
|
|
|
+})
|