Skip to content

Commit 6549a51

Browse files
Marco Herrera-Rendonolosegres
authored andcommitted
Example of includes bug
1 parent edeb362 commit 6549a51

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/Jsona.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import {
2020
resourceIdObjMetaMock,
2121
differentAttrsInDataAndIncludedMock,
2222
circularWithMeta,
23+
userWithIdlessSpecialties,
24+
idlessSpecialty1,
25+
idlessSpecialty2,
2326
} from './mocks';
2427

2528
chai.config.showDiff = true;
@@ -51,6 +54,11 @@ describe('Jsona', () => {
5154
expect(jsonBody.included).to.be.deep.equal([specialty1.json, specialty2.json, town2.json, country2.json]);
5255
});
5356

57+
it('should build json with collection, with included resources that do not have ids', () => {
58+
const jsonBody = jsona.serialize({stuff: userWithIdlessSpecialties.model, includeNames: ['specialty']});
59+
expect(jsonBody.included).to.be.deep.equal([idlessSpecialty1.json, idlessSpecialty2.json]);
60+
});
61+
5462
it('should build json and save null relationships', () => {
5563
const jsonBody = jsona.serialize({stuff: withNullRelationsMock.collection});
5664
expect(jsonBody.data).to.be.deep.equal(withNullRelationsMock.json);

tests/mocks.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,32 @@ export const specialty2 = {
110110
}
111111
};
112112

113+
export const idlessSpecialty1 = {
114+
model: {
115+
type: 'specialty',
116+
title: 'mycategory1'
117+
},
118+
json: {
119+
type: 'specialty',
120+
attributes: {
121+
title: 'mycategory1'
122+
}
123+
}
124+
};
125+
126+
export const idlessSpecialty2 = {
127+
model: {
128+
type: 'specialty',
129+
title: 'mycategory2'
130+
},
131+
json: {
132+
type: 'specialty',
133+
attributes: {
134+
title: 'mycategory2'
135+
}
136+
}
137+
};
138+
113139
export const user1 = {
114140
model: {
115141
type: 'user',
@@ -212,6 +238,17 @@ export const user2 = {
212238
}
213239
};
214240

241+
export const userWithIdlessSpecialties = {
242+
model: {
243+
type: 'user',
244+
id: '2',
245+
name: 'myName2',
246+
active: true,
247+
specialty: [idlessSpecialty1.model, idlessSpecialty2.model],
248+
[RELATIONSHIP_NAMES_PROP]: ['specialty']
249+
},
250+
};
251+
215252
export const article1 = {
216253
model: {
217254
type: 'article',

0 commit comments

Comments
 (0)