Skip to content

Commit

Permalink
Example of includes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Herrera-Rendon authored and olosegres committed Nov 22, 2022
1 parent edeb362 commit 6549a51
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/Jsona.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {
resourceIdObjMetaMock,
differentAttrsInDataAndIncludedMock,
circularWithMeta,
userWithIdlessSpecialties,
idlessSpecialty1,
idlessSpecialty2,
} from './mocks';

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

it('should build json with collection, with included resources that do not have ids', () => {
const jsonBody = jsona.serialize({stuff: userWithIdlessSpecialties.model, includeNames: ['specialty']});
expect(jsonBody.included).to.be.deep.equal([idlessSpecialty1.json, idlessSpecialty2.json]);
});

it('should build json and save null relationships', () => {
const jsonBody = jsona.serialize({stuff: withNullRelationsMock.collection});
expect(jsonBody.data).to.be.deep.equal(withNullRelationsMock.json);
Expand Down
37 changes: 37 additions & 0 deletions tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ export const specialty2 = {
}
};

export const idlessSpecialty1 = {
model: {
type: 'specialty',
title: 'mycategory1'
},
json: {
type: 'specialty',
attributes: {
title: 'mycategory1'
}
}
};

export const idlessSpecialty2 = {
model: {
type: 'specialty',
title: 'mycategory2'
},
json: {
type: 'specialty',
attributes: {
title: 'mycategory2'
}
}
};

export const user1 = {
model: {
type: 'user',
Expand Down Expand Up @@ -212,6 +238,17 @@ export const user2 = {
}
};

export const userWithIdlessSpecialties = {
model: {
type: 'user',
id: '2',
name: 'myName2',
active: true,
specialty: [idlessSpecialty1.model, idlessSpecialty2.model],
[RELATIONSHIP_NAMES_PROP]: ['specialty']
},
};

export const article1 = {
model: {
type: 'article',
Expand Down

0 comments on commit 6549a51

Please sign in to comment.