Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
if: matrix.node_version == 16 && matrix.os == 'ubuntu-latest'
uses: paambaati/codeclimate-action@v2.7.5
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CC_TEST_REPORTER_ID: 7a4b78747587abb295ccb41439d7d067b9de2d885a766e7e88d5e8409599d2ea

build:
name: Build (${{ matrix.node_version}}-${{ matrix.os }})
Expand Down
19 changes: 18 additions & 1 deletion packages/kitsu/src/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,28 @@ describe('kitsu', () => {
expect.assertions(1)
const api = new Kitsu()
mock.onGet('anime/1', { params: { include: 'animeStaff' } }).reply(200, getSingleWithIncludes.jsonapi)
mock.onGet('*').reply(data => console.log(data))
const request = await api.get('anime/1', { params: { include: 'animeStaff' } })
expect(request).toEqual(getSingleWithIncludes.kitsu)
})

it('fetches relationships of a resource', async () => {
expect.assertions(1)
const response = {
links: {
self: 'https://api.example/media-relationships/1/relationships/destination',
related: 'https://api.example/media-relationships/1/destination'
},
data: {
type: 'anime',
id: '1'
}
}
const api = new Kitsu()
mock.onGet('media-relationships/1/relationships/destination').reply(200, response)
const request = await api.get('media-relationships/1/relationships/destination')
expect(request).toEqual(response)
})

it('returns a JSON:API error object for invalid queries', async () => {
expect.assertions(5)
const api = new Kitsu()
Expand Down
3 changes: 2 additions & 1 deletion packages/kitsu/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ export default class Kitsu {
try {
const headers = merge(this.headers, config.headers)
const params = merge({}, config.params)
const [ res, id, relationship ] = model.split('/')
const [ res, id, relationship, subRelationship ] = model.split('/')

let url = this.plural(this.resCase(res))
if (id) url += `/${id}`
if (relationship) url += `/${this.resCase(relationship)}`
if (subRelationship) url += `/${this.resCase(subRelationship)}`

const { data } = await this.axios.get(url, {
headers,
Expand Down