fix(site): 清理经营租户请求中的旧分销参数
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const apiClient = vi.hoisted(() => ({
|
||||
get: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/client', () => ({ apiClient }))
|
||||
|
||||
import { fetchListingsPage } from './listings'
|
||||
|
||||
describe('listing API site scope', () => {
|
||||
beforeEach(() => {
|
||||
apiClient.get.mockResolvedValue({
|
||||
data: {
|
||||
data: { items: [], total: 0, page: 1, page_size: 20, zone_counts: {} },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sessionStorage.clear()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('经营租户不向列表请求透传显式旧分销站点编码', async () => {
|
||||
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
|
||||
|
||||
await fetchListingsPage({
|
||||
page: 1,
|
||||
distribution_site_code: 'legacy_jieyou',
|
||||
})
|
||||
|
||||
const params = apiClient.get.mock.calls[0][1].params
|
||||
expect(params).not.toHaveProperty('distribution_site_code')
|
||||
})
|
||||
|
||||
it('旧分销站点仍保留显式站点编码', async () => {
|
||||
sessionStorage.setItem('hfb_site_code', 'session_site')
|
||||
|
||||
await fetchListingsPage({
|
||||
page: 1,
|
||||
distribution_site_code: 'explicit_site',
|
||||
})
|
||||
|
||||
expect(apiClient.get.mock.calls[0][1].params).toMatchObject({
|
||||
distribution_site_code: 'explicit_site',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import type { ListingReviewStatus, ListingStatus } from '@/shared/types/status'
|
||||
|
||||
export interface Listing {
|
||||
@@ -112,8 +112,11 @@ export async function fetchListings(query: PublicListingQuery = {}) {
|
||||
}
|
||||
|
||||
export async function fetchListingsPage(query: PublicListingQuery = {}) {
|
||||
const siteCode = query.distribution_site_code || getEffectiveSiteCode() || undefined
|
||||
const effectiveQuery = siteCode ? { distribution_site_code: siteCode, ...query } : query
|
||||
const { distribution_site_code: explicitSiteCode, ...queryWithoutSiteCode } = query
|
||||
const siteCode = resolveEffectiveSiteCode(explicitSiteCode)
|
||||
const effectiveQuery = siteCode
|
||||
? { ...queryWithoutSiteCode, distribution_site_code: siteCode }
|
||||
: queryWithoutSiteCode
|
||||
const params = Object.fromEntries(
|
||||
Object.entries(effectiveQuery).filter(
|
||||
([, value]) => value !== '' && value !== undefined && value !== null
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import type { PublicListingItem } from '@/features/listings/api/listings'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
function getHistoryKey() {
|
||||
const code = getEffectiveSiteCode()
|
||||
const code = resolveEffectiveSiteCode()
|
||||
return code ? `hfb.listing.view.history.${code}` : 'hfb.listing.view.history'
|
||||
}
|
||||
|
||||
function getFavoriteKey() {
|
||||
const code = getEffectiveSiteCode()
|
||||
const code = resolveEffectiveSiteCode()
|
||||
return code ? `hfb.listing.favorites.${code}` : 'hfb.listing.favorites'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user