guestShopApi.spec.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-env jest */
  2. import request from '@/utils/request'
  3. import { fetchGuestProducts, fetchGuestCart, createGuestOrder, fetchGuestOrderDetail, downloadGuestOrder, downloadOrder } from '@/api/shop'
  4. import { getGuestRegionList, getRegionList } from '@/api/config'
  5. jest.mock('@/utils/request', () => jest.fn())
  6. 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) => {
  7. const params = { countryId: '620699181539139643' }
  8. api(params)
  9. expect(request).toHaveBeenLastCalledWith({ url, method: 'get', params })
  10. })
  11. it('posts the guest order to its own endpoint', () => {
  12. const data = { countryId: '620699181539139643', goodsId: ['P1'], goodsNum: [1] }
  13. createGuestOrder(data)
  14. expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/no-login-reconsume-sure-order', method: 'post', data })
  15. })
  16. it.each(['620699181539139625', '620699181539139643'])('queries anonymous regions with countryId %s', countryId => {
  17. const params = { countryId }
  18. getGuestRegionList(params)
  19. expect(request).toHaveBeenLastCalledWith({ url: '/v1/config/no-login-region-list', method: 'get', params })
  20. })
  21. it('keeps member region queries on the original endpoint', () => {
  22. const params = { countryId: '620699181539139625' }
  23. getRegionList(params)
  24. expect(request).toHaveBeenLastCalledWith({ url: '/v1/config/region-list', method: 'get', params })
  25. })
  26. it('queries anonymous order details using orderSn', () => {
  27. const params = { orderSn: 'SAMPLE-ORDER' }
  28. fetchGuestOrderDetail(params)
  29. expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/no-login-order-detail', method: 'get', params })
  30. })
  31. it('uses anonymous receipt export while handling an anonymous 401 on the page', () => {
  32. downloadGuestOrder('SAMPLE/ORDER')
  33. const config = request.mock.calls[request.mock.calls.length - 1][0]
  34. expect(config).toMatchObject({ url: '/v1/shop/no-login-order-export/SAMPLE%2FORDER', method: 'get', params: {}})
  35. expect(config.validateStatus(200)).toBe(true)
  36. expect(config.validateStatus(401)).toBe(true)
  37. expect(config.validateStatus(500)).toBe(false)
  38. })
  39. it('keeps signed-in receipt export on its original endpoint', () => {
  40. downloadOrder('SAMPLE-ORDER')
  41. expect(request).toHaveBeenLastCalledWith({ url: '/v1/shop/order-export/SAMPLE-ORDER', method: 'get', params: {}})
  42. })