guestShopApi.spec.js 1.4 KB

12345678910111213141516171819202122232425
  1. /* eslint-env jest */
  2. import request from '@/utils/request'
  3. import { fetchGuestProducts, fetchGuestCart, createGuestOrder } 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. })