|
| 1 | +import Axios from 'axios' |
| 2 | +import BaseProxy from '../core/BaseProxy' |
| 3 | +import PostProxy from '../core/PostPorxy' |
| 4 | +import MockAdapter from 'axios-mock-adapter' |
| 5 | +import BaseTransformer from '../core/BaseTransformer' |
| 6 | +import PaginationTransformer from '../core/PaginationTransformer' |
| 7 | + |
| 8 | +let proxy: PostProxy |
| 9 | +let mockAdapter: MockAdapter |
| 10 | + |
| 11 | +describe('PostProxy', () => { |
| 12 | + beforeEach(() => { |
| 13 | + const axios = Axios.create({ baseURL: 'https://mock-api.test' }) |
| 14 | + BaseProxy.$http = axios |
| 15 | + proxy = new PostProxy() |
| 16 | + mockAdapter = new MockAdapter(axios) |
| 17 | + mockAdapter.reset() |
| 18 | + }) |
| 19 | + |
| 20 | + it('it should get tags by post id', async () => { |
| 21 | + const items = { |
| 22 | + data: [{ name: 'Chantouch', post_id: 1 }], |
| 23 | + meta: { |
| 24 | + pagination: { count: 1, current_page: 1, perPage: 20 }, |
| 25 | + include: [], |
| 26 | + }, |
| 27 | + } |
| 28 | + mockAdapter.onGet('/posts/1/tags').reply(200, items) |
| 29 | + const { data, meta = {} } = await proxy.tags(1) |
| 30 | + const all = { |
| 31 | + items: BaseTransformer.fetchCollection(data), |
| 32 | + pagination: PaginationTransformer.fetch(meta), |
| 33 | + } |
| 34 | + expect(meta).toHaveProperty('pagination') |
| 35 | + expect(data.length).toEqual(1) |
| 36 | + expect(all.pagination.page).toEqual(1) |
| 37 | + }) |
| 38 | +}) |
0 commit comments