Skip to content

Commit a973b00

Browse files
wopianbenchaikin
andauthored
feat(kitsu)!: upgrade axios to v1 (#1075)
* feat(kitsu): upgrading to latest version of axios * Reformatting long return value for readability * refactor: apply code style changes to rest of return values --------- Co-authored-by: Ben <ben@talentllama.com> Co-authored-by: Benjamin Chaikin <benchaikin@users.noreply.github.com>
1 parent 1fade70 commit a973b00

10 files changed

Lines changed: 1478 additions & 1433 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist
44
coverage
55
**/env.js
66
*.log*
7+
.idea

packages/kitsu/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@
4949
"build": "yarn rollup"
5050
},
5151
"dependencies": {
52-
"axios": "^0.30.0",
52+
"axios": "^1.8.4",
5353
"kitsu-core": "^10.2.1",
5454
"pluralize": "^8.0.0"
5555
},
5656
"size-limit": [
5757
{
5858
"path": "./dist/index.js",
59-
"limit": "14 kb",
59+
"limit": "18 kb",
6060
"brotli": true
6161
},
6262
{
6363
"path": "./dist/index.mjs",
64-
"limit": "14 kb",
64+
"limit": "18 kb",
6565
"brotli": true
6666
}
6767
],

packages/kitsu/src/delete.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ describe('kitsu', () => {
2222
expect.assertions(2)
2323
const api = new Kitsu({ headers: { Authorization: true } })
2424
mock.onDelete('/anime/1').reply(config => {
25-
expect(config.headers).toEqual({
25+
expect(config.headers).toMatchObject({
2626
Accept: 'application/vnd.api+json',
2727
'Content-Type': 'application/vnd.api+json',
28-
Authorization: true,
29-
extra: true
28+
Authorization: 'true',
29+
extra: 'true'
3030
})
3131
return [ 200, undefined, {
3232
Accept: 'application/vnd.api+json'
3333
} ]
3434
})
35-
expect(await api.delete('anime', 1, { headers: { extra: true } })).toEqual({
35+
expect(await api.delete('anime', 1, { headers: { extra: true } })).toMatchObject({
3636
headers: {
3737
Accept: 'application/vnd.api+json'
3838
},

packages/kitsu/src/get.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ describe('kitsu', () => {
3131
expect.assertions(2)
3232
const api = new Kitsu({ headers: { init: true } })
3333
mock.onGet('/anime').reply(config => {
34-
expect(config.headers).toEqual({
34+
expect(config.headers).toMatchObject({
3535
Accept: 'application/vnd.api+json',
3636
'Content-Type': 'application/vnd.api+json',
37-
init: true,
38-
extra: true
37+
init: 'true',
38+
extra: 'true'
3939
})
4040
return [ 200, { data: [] }, {
4141
Accept: 'application/vnd.api+json',
@@ -44,12 +44,12 @@ describe('kitsu', () => {
4444
} ]
4545
})
4646
const response = await api.get('anime', { headers: { extra: true } })
47-
await expect(await response).toEqual({
47+
await expect(await response).toMatchObject({
4848
data: [],
4949
headers: {
5050
Accept: 'application/vnd.api+json',
5151
'Content-Type': 'application/vnd.api+json',
52-
extra: true
52+
extra: 'true'
5353
},
5454
status: 200
5555
})

packages/kitsu/src/index.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,14 @@ export default class Kitsu {
239239
...config.axiosOptions
240240
})
241241

242-
return { ...deserialise(data), status, ...(responseHeaders ? { headers: responseHeaders } : {}) }
242+
return {
243+
...deserialise(data),
244+
status,
245+
...(responseHeaders && Object.keys(responseHeaders).length
246+
? { headers: responseHeaders }
247+
: {}
248+
)
249+
}
243250
} catch (E) {
244251
throw error(E)
245252
}
@@ -302,7 +309,14 @@ export default class Kitsu {
302309
}
303310
)
304311

305-
return { ...deserialise(data), status, ...(responseHeaders ? { headers: responseHeaders } : {}) }
312+
return {
313+
...deserialise(data),
314+
status,
315+
...(responseHeaders && Object.keys(responseHeaders).length
316+
? { headers: responseHeaders }
317+
: {}
318+
)
319+
}
306320
} catch (E) {
307321
throw error(E)
308322
}
@@ -362,7 +376,14 @@ export default class Kitsu {
362376
}
363377
)
364378

365-
return { ...deserialise(data), status, ...(responseHeaders ? { headers: responseHeaders } : {}) }
379+
return {
380+
...deserialise(data),
381+
status,
382+
...(responseHeaders && Object.keys(responseHeaders).length
383+
? { headers: responseHeaders }
384+
: {}
385+
)
386+
}
366387
} catch (E) {
367388
throw error(E)
368389
}
@@ -415,7 +436,14 @@ export default class Kitsu {
415436
...config.axiosOptions
416437
})
417438

418-
return { ...deserialise(data), status, ...(responseHeaders ? { headers: responseHeaders } : {}) }
439+
return {
440+
...deserialise(data),
441+
status,
442+
...(responseHeaders && Object.keys(responseHeaders).length
443+
? { headers: responseHeaders }
444+
: {}
445+
)
446+
}
419447
} catch (E) {
420448
throw error(E)
421449
}
@@ -448,7 +476,7 @@ export default class Kitsu {
448476
const headers = { ...this.headers, ...config.headers }
449477
const params = { ...config.params, ...{ filter: { self: true } } }
450478
const res = await this.get('users', { ...{ headers }, ...{ params }, ...config.axiosOptions })
451-
return res.headers ? { ...{ data: res.data[0] }, ...{ headers: res.headers } } : { data: res.data[0] }
479+
return { ...(res.headers && { headers: res.headers }), ...(res.data?.[0] && { data: res.data[0] }) }
452480
} catch (E) {
453481
throw error(E)
454482
}
@@ -524,7 +552,14 @@ export default class Kitsu {
524552
...axiosOptions
525553
})
526554

527-
return { ...deserialise(data), status, ...(responseHeaders ? { headers: responseHeaders } : {}) }
555+
return {
556+
...deserialise(data),
557+
status,
558+
...(responseHeaders && Object.keys(responseHeaders).length
559+
? { headers: responseHeaders }
560+
: {}
561+
)
562+
}
528563
} catch (E) {
529564
throw error(E)
530565
}

packages/kitsu/src/patch.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ describe('kitsu', () => {
2626
expect.assertions(2)
2727
const api = new Kitsu({ headers: { Authorization: true } })
2828
mock.onPatch('/anime/1').reply(config => {
29-
expect(config.headers).toEqual({
29+
expect(config.headers).toMatchObject({
3030
Accept: 'application/vnd.api+json',
3131
'Content-Type': 'application/vnd.api+json',
32-
Authorization: true,
33-
extra: true
32+
Authorization: 'true',
33+
extra: 'true'
3434
})
3535
return [ 200, undefined, {
3636
Accept: 'application/vnd.api+json'
3737
} ]
3838
})
39-
await expect(await api.patch('anime', { id: '1', type: 'anime' }, { headers: { extra: true } })).toEqual({
39+
await expect(await api.patch('anime', { id: '1', type: 'anime' }, { headers: { extra: true } })).toMatchObject({
4040
headers: {
4141
Accept: 'application/vnd.api+json'
4242
},

packages/kitsu/src/post.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ describe('kitsu', () => {
2222
expect.assertions(2)
2323
const api = new Kitsu({ headers: { Authorization: true } })
2424
mock.onPost('/anime').reply(config => {
25-
expect(config.headers).toEqual({
25+
expect(config.headers).toMatchObject({
2626
Accept: 'application/vnd.api+json',
2727
'Content-Type': 'application/vnd.api+json',
28-
Authorization: true,
29-
extra: true
28+
Authorization: 'true',
29+
extra: 'true'
3030
})
3131
return [ 200, undefined, {
3232
Accept: 'application/vnd.api+json'
3333
} ]
3434
})
35-
await expect(await api.post('anime', { id: '1', type: 'anime' }, { headers: { extra: true } })).toEqual({
35+
await expect(await api.post('anime', { id: '1', type: 'anime' }, { headers: { extra: true } })).toMatchObject({
3636
headers: {
3737
Accept: 'application/vnd.api+json'
3838
},

packages/kitsu/src/request.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ describe('kitsu', () => {
4141
expect.assertions(2)
4242
const api = new Kitsu({ headers: { Authorization: true } })
4343
mock.onGet('/users').reply(config => {
44-
expect(config.headers).toEqual({
44+
expect(config.headers).toMatchObject({
4545
Accept: 'application/vnd.api+json',
4646
'Content-Type': 'application/vnd.api+json',
47-
Authorization: true,
48-
extra: true
47+
Authorization: 'true',
48+
extra: 'true'
4949
})
5050
return [ 200, { data: [] }, { Accept: 'application/vnd.api+json' } ]
5151
})
@@ -54,7 +54,7 @@ describe('kitsu', () => {
5454
url: 'users',
5555
model: 'users',
5656
headers: { extra: true }
57-
})).toEqual({ data: [], headers: { Accept: 'application/vnd.api+json' }, status: 200 })
57+
})).toMatchObject({ data: [], headers: { Accept: 'application/vnd.api+json' }, status: 200 })
5858
})
5959

6060
it('sends parameters', async () => {

packages/kitsu/src/self.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ describe('kitsu', () => {
2525
expect.assertions(2)
2626
const api = new Kitsu({ headers: { Authorization: true } })
2727
mock.onGet('/users', { filter: { self: true } }).reply(config => {
28-
expect(config.headers).toEqual({
28+
expect(config.headers).toMatchObject({
2929
Accept: 'application/vnd.api+json',
3030
'Content-Type': 'application/vnd.api+json',
31-
Authorization: true,
32-
extra: true
31+
Authorization: 'true',
32+
extra: 'true'
3333
})
3434
return [ 200, { data: [] }, { Accept: 'application/vnd.api+json' } ]
3535
})
36-
await expect(await api.self({ headers: { extra: true } })).toEqual({
36+
await expect(await api.self({ headers: { extra: true } })).toMatchObject({
3737
headers: { Accept: 'application/vnd.api+json' }
3838
})
3939
})

0 commit comments

Comments
 (0)