/* eslint-env jest */ import request from '@/utils/request' import { fetchGuestProducts, fetchGuestCart, createGuestOrder, fetchGuestOrderDetail, downloadGuestOrder, downloadOrder } from '@/api/shop' import { getGuestRegionList, getRegionList } from '@/api/config' jest.mock('@/utils/request', () => jest.fn()) it.each([[fetchGuestProducts, '/v1/shop/no-login-reconsume'], [fetchGuestCart, '/v1/shop/no-login-show-cart']])('calls the anonymous GET endpoint without modifying the country ID', (api, url) => { const params = { countryId: '620699181539139643' } api(params) expect(request).toHaveBeenLastCalledWith({ url, method: 'get', params }) }) it('posts the guest order to its own endpoint', () => { const data = { countryId: '620699181539139643', goodsId: ['P1'], goodsNum: [1] } createGuestOrder(data) expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/no-login-reconsume-sure-order', method: 'post', data }) }) it.each(['620699181539139625', '620699181539139643'])('queries anonymous regions with countryId %s', countryId => { const params = { countryId } getGuestRegionList(params) expect(request).toHaveBeenLastCalledWith({ url: '/v1/config/no-login-region-list', method: 'get', params }) }) it('keeps member region queries on the original endpoint', () => { const params = { countryId: '620699181539139625' } getRegionList(params) expect(request).toHaveBeenLastCalledWith({ url: '/v1/config/region-list', method: 'get', params }) }) it('queries anonymous order details using orderSn', () => { const params = { orderSn: 'SAMPLE-ORDER' } fetchGuestOrderDetail(params) expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/no-login-order-detail', method: 'get', params }) }) it('uses anonymous receipt export while handling an anonymous 401 on the page', () => { downloadGuestOrder('SAMPLE/ORDER') const config = request.mock.calls[request.mock.calls.length - 1][0] expect(config).toMatchObject({ url: '/v1/shop/no-login-order-export/SAMPLE%2FORDER', method: 'get', params: {}}) expect(config.validateStatus(200)).toBe(true) expect(config.validateStatus(401)).toBe(true) expect(config.validateStatus(500)).toBe(false) }) it('keeps signed-in receipt export on its original endpoint', () => { downloadOrder('SAMPLE-ORDER') expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/order-export/SAMPLE-ORDER', method: 'get', params: {}}) })