Skip to content

Commit a88d18e

Browse files
koji98wopian
andcommitted
fix: re-add support for resource object-linkage for relationships (#552)
* Adding sub relationships for routes with 4 subpaths * test(kitsu): add coverage for fetching relationships of a resource * ci(codeclimate): move public identifier into workflow PRs from forks do not have access to the secret variable. According to CodeClimate, this is a public read-only token and doesn't need to be kept secret: https://docs.codeclimate.com/docs/finding-your-test-coverage-token#should-i-keep-my-test-reporter-id-secret * docs: fix jsdoc syntax Co-authored-by: wopian <wopian@wopian.me>
1 parent 7d88dbf commit a88d18e

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/kitsu/src/get.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ describe('kitsu', () => {
9292
expect(request).toEqual(getSingleWithNestedIncludes.kitsu)
9393
})
9494

95+
it('fetches relationships of a resource', async () => {
96+
expect.assertions(1)
97+
const response = {
98+
links: {
99+
self: 'https://api.example/media-relationships/1/relationships/destination',
100+
related: 'https://api.example/media-relationships/1/destination'
101+
},
102+
data: {
103+
type: 'anime',
104+
id: '1'
105+
}
106+
}
107+
const api = new Kitsu()
108+
mock.onGet('media-relationships/1/relationships/destination').reply(200, response)
109+
const request = await api.get('media-relationships/1/relationships/destination')
110+
expect(request).toEqual(response)
111+
})
112+
95113
it('returns a JSON:API error object for invalid queries', async () => {
96114
expect.assertions(5)
97115
const api = new Kitsu()

packages/kitsu/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@ export default class Kitsu {
197197
*/
198198
async get (model, params = {}, headers = {}) {
199199
try {
200-
const [ res, id, relationship ] = model.split('/')
200+
const [ res, id, relationship, subRelationship ] = model.split('/')
201201

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

206207
const { data } = await this.axios.get(url, {
207208
params,

0 commit comments

Comments
 (0)