Skip to content

Commit f31fb19

Browse files
committed
test: ✅ update test
1 parent 145048c commit f31fb19

File tree

7 files changed

+25
-36
lines changed

7 files changed

+25
-36
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
global: {
88
lines: 100,
99
functions: 100,
10-
branches: 89.44,
11-
statements: 99.36,
10+
branches: 91.25,
11+
statements: 99.68,
1212
},
1313
},
1414
testEnvironment: 'node',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@nuxt/types": "^2.15.8",
5151
"@types/escape-string-regexp": "^2.0.1",
5252
"@types/jest": "^27.0.1",
53-
"@types/lodash.merge": "^4.6.6",
5453
"@types/node": "^16.9.3",
5554
"@types/qs": "^6.9.7",
5655
"@typescript-eslint/eslint-plugin": "^4.31.1",

src/__tests__/object.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFile, cloneDeep } from '../util'
1+
import { isFile, cloneDeep, hasOwnProperty, merge } from '../util'
22

33
describe('Object Test', () => {
44
// const { window, File } = global
@@ -35,4 +35,14 @@ describe('cloneDeep', () => {
3535
const obj = [{ name: 'Chantouch' }]
3636
expect(cloneDeep(obj)).toBeInstanceOf(Object)
3737
})
38+
it('Has own property undefined', () => {
39+
const obj = [{ name: 'Chantouch' }]
40+
expect(hasOwnProperty(obj, undefined)).toBeFalsy()
41+
})
42+
it('Merge object into object', () => {
43+
const obj1 = { name: 'Chantouch' }
44+
const obj2 = { email: '[email protected]' }
45+
const merged = { email: '[email protected]', name: 'Chantouch' }
46+
expect(merge(obj1, obj2)).toEqual(merged)
47+
})
3848
})

src/core/BaseProxy.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type { Errors } from '..'
99
import Validator from './Validator'
1010
import { hasFiles, objectToFormData, removeDoubleSlash } from '../util'
1111
import qs, { IParseOptions } from 'qs'
12-
import merge from 'lodash.merge'
1312

1413
const validator = Validator
1514
const UNPROCESSABLE_ENTITY = 422
@@ -232,14 +231,7 @@ class BaseProxy {
232231
}
233232

234233
private static __validateRequestType(requestType: Method): Method {
235-
const requestTypes: string[] = [
236-
'get',
237-
'delete',
238-
'head',
239-
'post',
240-
'put',
241-
'patch',
242-
]
234+
const requestTypes = ['get', 'delete', 'head', 'post', 'put', 'patch']
243235
if (!requestTypes.includes(requestType)) {
244236
throw new Error(
245237
`\`${requestType}\` is not a valid request type, ` +
@@ -267,7 +259,7 @@ class BaseProxy {
267259
*/
268260
setParameter(parameter: string, value?: any): this {
269261
if (!value) {
270-
const options: IParseOptions = merge(this.$parsedQs, {
262+
const options: IParseOptions = Object.assign({}, this.$parsedQs, {
271263
comma: true,
272264
allowDots: true,
273265
ignoreQueryPrefix: true,

src/core/BaseTransformer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ import snakeCaseKeys from 'snakecase-keys'
22
import camelcaseKeys from 'camelcase-keys'
33

44
class BaseTransformer {
5-
static fetchCollection<T>(
5+
static fetchCollection<T = any>(
66
items: T[],
77
camelKey?: boolean,
88
): (Record<string, any> | T)[] {
99
return items.map((item: T) => this.fetch(item, camelKey))
1010
}
1111

12-
static sendCollection<T>(
12+
static sendCollection<T = any>(
1313
items: T[],
1414
snakeKey?: boolean,
1515
): ({ [p: string]: any } | T)[] {
1616
return items.map((item: T) => this.send(item, snakeKey))
1717
}
1818

19-
static fetch<T>(item: T, camelKey?: boolean): T | Record<string, any> {
19+
static fetch<T = any>(item: T, camelKey?: boolean): T | Record<string, any> {
2020
return camelKey ? camelcaseKeys(item, { deep: true }) : item
2121
}
2222

23-
static send<T>(item: T, snakeKey?: boolean) {
23+
static send<T = any>(item: T, snakeKey?: boolean) {
2424
return snakeKey ? snakeCaseKeys(item) : item
2525
}
2626
}

src/core/PaginationTransformer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BaseTransformer from './BaseTransformer'
2+
import { hasOwnProperty } from '../util'
23

34
export interface PaginationOptions {
45
perPage: number
@@ -25,14 +26,13 @@ export interface MetaOptions {
2526
class PaginationTransformer extends BaseTransformer {
2627
static fetch(meta: MetaOptions | Record<string, any>) {
2728
if (!meta) {
28-
meta = { pagination: {}, include: [] }
29+
meta = Object.assign({}, meta, { pagination: {}, include: [] })
2930
}
30-
if (!Object.prototype.hasOwnProperty.call(meta, 'pagination')) {
31+
if (!hasOwnProperty(meta, 'pagination')) {
3132
return super.fetch(meta, true)
3233
}
33-
const { pagination = {}, include } = meta
34-
const payload = {
35-
...pagination,
34+
const { pagination, include } = meta
35+
const payload: PaginationOptions = Object.assign({}, pagination, {
3636
perPage: pagination.per_page,
3737
totalPages: pagination.total_pages,
3838
currentPage: pagination.current_page || 1,
@@ -46,7 +46,7 @@ class PaginationTransformer extends BaseTransformer {
4646
pageStart: 0,
4747
pageStop: pagination.count,
4848
include,
49-
}
49+
})
5050

5151
return super.fetch(payload, true)
5252
}

yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,18 +1942,6 @@
19421942
resolved "https://registry.yarnpkg.com/@types/less/-/less-3.0.2.tgz#2761d477678c8374cb9897666871662eb1d1115e"
19431943
integrity sha512-62vfe65cMSzYaWmpmhqCMMNl0khen89w57mByPi1OseGfcV/LV03fO8YVrNj7rFQsRWNJo650WWyh6m7p8vZmA==
19441944

1945-
"@types/lodash.merge@^4.6.6":
1946-
version "4.6.6"
1947-
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
1948-
integrity sha512-IB90krzMf7YpfgP3u/EvZEdXVvm4e3gJbUvh5ieuI+o+XqiNEt6fCzqNRaiLlPVScLI59RxIGZMQ3+Ko/DJ8vQ==
1949-
dependencies:
1950-
"@types/lodash" "*"
1951-
1952-
"@types/lodash@*":
1953-
version "4.14.175"
1954-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.175.tgz#b78dfa959192b01fae0ad90e166478769b215f45"
1955-
integrity sha512-XmdEOrKQ8a1Y/yxQFOMbC47G/V2VDO1GvMRnl4O75M4GW/abC5tnfzadQYkqEveqRM1dEJGFFegfPNA2vvx2iw==
1956-
19571945
"@types/mime@^1":
19581946
version "1.3.2"
19591947
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"

0 commit comments

Comments
 (0)