Skip to content

Commit 66b5a6f

Browse files
committed
docs(kitsu-core): add examples for filterIncludes
1 parent cb40de1 commit 66b5a6f

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

packages/kitsu-core/src/filterIncludes/index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
import { error } from '../error'
22

33
/**
4-
* Filters includes for the specific relationship
4+
* Filters includes for the specific relationship requested
55
*
66
* @param {Object} included The response included object
7-
* @param {Object} opts
8-
* @param {string} opts.id The relationship ID
9-
* @param {string} opts.type The relationship type
7+
* @param {Object} relationship
8+
* @param {string} relationship.id The relationship ID
9+
* @param {string} relationship.type The relationship type
1010
* @returns {Array} The matched includes
11+
*
12+
* @example
13+
* const includes = [
14+
* {
15+
* id: '1',
16+
* type: 'users',
17+
* attributes: { name: 'Emma' }
18+
* },
19+
* {
20+
* id: '2',
21+
* type: 'users',
22+
* attributes: { name: 'Josh' }
23+
* }
24+
* ]
25+
* const relationship = { id: '1', type: 'users' }
26+
* const response = filterIncludes(includes, relationship)
27+
* // {
28+
* // id: '1',
29+
* // type: 'users',
30+
* // attributes: { name: 'Emma' }
31+
* // }
1132
*/
1233
export function filterIncludes (included, { id, type }) {
1334
try {

packages/kitsu-core/src/filterIncludes/index.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,37 @@ describe('kitsu-core', () => {
1919
const response = filterIncludes([], { })
2020
expect(response).toEqual({ })
2121
})
22+
23+
it('filters included relationships', () => {
24+
expect.assertions(1)
25+
const includes = [
26+
{
27+
id: '1',
28+
type: 'users',
29+
attributes: {
30+
name: 'Emma'
31+
}
32+
},
33+
{
34+
id: '2',
35+
type: 'users',
36+
attributes: {
37+
name: 'Josh'
38+
}
39+
}
40+
]
41+
const relationship = {
42+
id: '1',
43+
type: 'users'
44+
}
45+
const response = filterIncludes(includes, relationship)
46+
expect(response).toEqual({
47+
id: '1',
48+
type: 'users',
49+
attributes: {
50+
name: 'Emma'
51+
}
52+
})
53+
})
2254
})
2355
})

0 commit comments

Comments
 (0)