Skip to content

Commit e60729e

Browse files
authored
Merge pull request #318 from chantouchsek/feat/remove-transformer-files
Feat/remove transformer files
2 parents b1f2ba2 + 367d853 commit e60729e

File tree

9 files changed

+28
-278
lines changed

9 files changed

+28
-278
lines changed

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const config: InitialOptionsTsJest = {
77
global: {
88
lines: 100,
99
functions: 100,
10-
branches: 93.44,
11-
statements: 99.39,
10+
branches: 92.72,
11+
statements: 99.33,
1212
},
1313
},
1414
testEnvironment: 'node',

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@vue/test-utils": "^1.2.2",
6060
"axios": "^0.26.1",
6161
"axios-mock-adapter": "^1.20.0",
62-
"eslint": "^8.6.0",
62+
"eslint": "^8.13.0",
6363
"eslint-config-prettier": "^8.3.0",
6464
"eslint-plugin-import": "^2.24.2",
6565
"eslint-plugin-prettier": "^4.0.0",
@@ -81,9 +81,7 @@
8181
"nuxt"
8282
],
8383
"dependencies": {
84-
"camelcase-keys": "^7.0.1",
85-
"qs": "^6.10.2",
86-
"snakecase-keys": "^5.1.2"
84+
"qs": "^6.10.2"
8785
},
8886
"lint-staged": {
8987
"*.{js,ts}": "eslint --cache",

src/__tests__/base-proxy.test.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import MockAdapter from 'axios-mock-adapter'
44
import PostProxy from '../util/PostPorxy'
55
import type { ValidatorType } from '../core/Validator'
66
import Validator from '../core/Validator'
7-
import BaseTransformer from '../core/BaseTransformer'
8-
import PaginationTransformer from '../core/PaginationTransformer'
97
import { merge } from '../util'
108

119
let proxy: PostProxy
@@ -39,10 +37,10 @@ describe('BaseProxy', () => {
3937
pagination: { count: 1, page: 1, perPage: 20 },
4038
}
4139
mockAdapter.onGet('/posts').reply(200, items)
42-
const { data, pagination = {} } = await proxy.removeParameters().all()
40+
const { data, pagination } = await proxy.removeParameters().all()
4341
const all = {
44-
items: BaseTransformer.fetchCollection(data),
45-
pagination: PaginationTransformer.fetch(pagination),
42+
pagination,
43+
items: data,
4644
}
4745
expect(all).toHaveProperty('pagination')
4846
expect(data).toEqual(all.items)
@@ -53,35 +51,19 @@ describe('BaseProxy', () => {
5351
const items = {
5452
data: [{ first_name: 'Chantouch', last_name: 'Sek' }],
5553
meta: {
56-
pagination: { count: 1, current_page: 1, perPage: 20 },
54+
pagination: { count: 1, page: 1, perPage: 20 },
5755
include: [],
5856
},
5957
}
6058
mockAdapter.onGet('/posts').reply(200, items)
61-
const { data, meta = {} } = await proxy.removeParameters().all()
62-
const all = {
63-
items: BaseTransformer.fetchCollection(data),
64-
pagination: PaginationTransformer.fetch(meta),
59+
const { data, meta } = await proxy.removeParameters().all()
60+
const item = {
61+
items: data,
62+
pagination: meta.pagination,
6563
}
6664
expect(meta).toHaveProperty('pagination')
6765
expect(data.length).toEqual(1)
68-
expect(all.pagination.page).toEqual(1)
69-
})
70-
71-
it('should assign default object meta if it is null or undefined', async () => {
72-
const items = {
73-
data: [{ first_name: 'Chantouch', last_name: 'Sek' }],
74-
meta: undefined,
75-
}
76-
mockAdapter.onGet('/posts').reply(200, items)
77-
const { data, meta } = await proxy.removeParameters([]).all()
78-
const all = {
79-
items: BaseTransformer.fetchCollection(data),
80-
pagination: PaginationTransformer.fetch(meta),
81-
}
82-
expect(meta).toBeUndefined()
83-
expect(data.length).toEqual(1)
84-
expect(all.pagination.currentPage).toEqual(1)
66+
expect(item.pagination.page).toEqual(1)
8567
})
8668

8769
it('will fetch all records', async () => {

src/__tests__/base-transformer.test.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/__tests__/post-proxy.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Axios from 'axios'
22
import BaseProxy from '../core/BaseProxy'
33
import PostProxy from '../util/PostPorxy'
44
import MockAdapter from 'axios-mock-adapter'
5-
import BaseTransformer from '../core/BaseTransformer'
6-
import PaginationTransformer from '../core/PaginationTransformer'
75

86
let proxy: PostProxy
97
let mockAdapter: MockAdapter
@@ -21,25 +19,26 @@ describe('PostProxy', () => {
2119
const items = {
2220
data: [{ name: 'Chantouch', post_id: 1 }],
2321
meta: {
24-
pagination: { count: 1, current_page: 1, perPage: 20 },
22+
pagination: { count: 1, page: 1, perPage: 20 },
2523
include: [],
2624
},
2725
}
2826
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),
27+
const { data, meta } = await proxy.tags(1)
28+
const item = {
29+
items: data,
30+
pagination: meta.pagination,
3331
}
32+
console.warn('meta', item.pagination)
3433
expect(meta).toHaveProperty('pagination')
3534
expect(data.length).toEqual(1)
36-
expect(all.pagination.page).toEqual(1)
35+
expect(item.pagination.page).toEqual(1)
3736
})
3837
it('it should throw exception if method is not inlist', async () => {
3938
const items = {
4039
data: [{ name: 'Chantouch', post_id: 1 }],
4140
meta: {
42-
pagination: { count: 1, current_page: 1, perPage: 20 },
41+
pagination: { count: 1, page: 1, perPage: 20 },
4342
include: [],
4443
},
4544
}

src/core/BaseTransformer.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/core/PaginationTransformer.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { ValidatorType } from './core/Validator'
22
import BaseProxy from './core/BaseProxy'
33
import Validator from './core/Validator'
4-
import BaseTransformer from './core/BaseTransformer'
5-
import PaginationTransformer from './core/PaginationTransformer'
64
import { merge } from './util'
75
import _Vue from 'vue'
86

@@ -51,12 +49,6 @@ class AxiosHttp {
5149
})
5250
}
5351
}
54-
export {
55-
Validator,
56-
BaseProxy,
57-
BaseTransformer,
58-
PaginationTransformer,
59-
BaseProxy as BaseService,
60-
}
52+
export { Validator, BaseProxy, BaseProxy as BaseService }
6153
export * from './util'
6254
export default new AxiosHttp()

0 commit comments

Comments
 (0)