This commit is contained in:
2026-08-07 19:23:43 +08:00
parent 38a0ffd3e3
commit 28d0b81c5a
12 changed files with 627 additions and 470 deletions
+54
View File
@@ -0,0 +1,54 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const http = vi.hoisted(() => ({
get: vi.fn(),
put: vi.fn(),
}))
vi.mock('@/shared/api/http', () => ({
http,
unwrapApiResponse: <T>(response: { data: T }) => response.data,
}))
import {
getCustomerDimensionConfig,
updateCustomerDimensionConfig,
} from './api'
const rawConfig = {
tenantId: 9007199254740993n.toString(),
edgeAdditionCm: 2,
version: 3,
updatedAt: '2026-08-07T10:20:00',
}
describe('customer dimension config api', () => {
beforeEach(() => vi.clearAllMocks())
it('loads the current customer config and keeps long ids as strings', async () => {
http.get.mockResolvedValue({ data: rawConfig })
const result = await getCustomerDimensionConfig('9007199254740993')
expect(http.get).toHaveBeenCalledWith('/platform/v1/first-leg/customer-dimension-config', {
params: { tenantId: '9007199254740993' },
})
expect(result).toEqual(rawConfig)
})
it('sends the current version when updating the edge addition', async () => {
http.put.mockResolvedValue({ data: { ...rawConfig, edgeAdditionCm: 3, version: 4 } })
const result = await updateCustomerDimensionConfig('9007199254740993', {
edgeAdditionCm: 3,
version: 3,
})
expect(http.put).toHaveBeenCalledWith(
'/platform/v1/first-leg/customer-dimension-config',
{ edgeAdditionCm: 3, version: 3 },
{ params: { tenantId: '9007199254740993' } },
)
expect(result).toMatchObject({ tenantId: '9007199254740993', edgeAdditionCm: 3, version: 4 })
})
})
+35
View File
@@ -0,0 +1,35 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import type {
CustomerDimensionConfig,
UpdateCustomerDimensionConfigRequest,
} from './types'
const dimensionConfigPath = '/platform/v1/first-leg/customer-dimension-config'
type RawDimensionConfig = Omit<CustomerDimensionConfig, 'tenantId'> & {
tenantId: string | number
}
function normalizeConfig(config: RawDimensionConfig): CustomerDimensionConfig {
return {
...config,
tenantId: String(config.tenantId),
}
}
export async function getCustomerDimensionConfig(tenantId: string): Promise<CustomerDimensionConfig> {
const response = await http.get<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, {
params: { tenantId },
})
return normalizeConfig(unwrapApiResponse(response))
}
export async function updateCustomerDimensionConfig(
tenantId: string,
request: UpdateCustomerDimensionConfigRequest,
): Promise<CustomerDimensionConfig> {
const response = await http.put<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, request, {
params: { tenantId },
})
return normalizeConfig(unwrapApiResponse(response))
}
+10
View File
@@ -0,0 +1,10 @@
export {
getCustomerDimensionConfig,
updateCustomerDimensionConfig,
} from './api'
export type {
CustomerDimensionConfig,
CustomerDimensionConfigFormModel,
UpdateCustomerDimensionConfigRequest,
} from './types'
+15
View File
@@ -0,0 +1,15 @@
export interface CustomerDimensionConfig {
tenantId: string
edgeAdditionCm: number
version: number
updatedAt: string | null
}
export interface UpdateCustomerDimensionConfigRequest {
edgeAdditionCm: number
version: number
}
export interface CustomerDimensionConfigFormModel {
edgeAdditionCm: number
}