File tree Expand file tree Collapse file tree
packages/kitsu-core/src/filterIncludes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { 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 */
1233export function filterIncludes ( included , { id, type } ) {
1334 try {
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments