Skip to content

Commit

Permalink
Merge pull request #37 from garusis/bc-36
Browse files Browse the repository at this point in the history
#36 Fix issue with whereRelated when there isn't current resources
  • Loading branch information
mfpiccolo authored Oct 16, 2019
2 parents dd480f5 + a296ba0 commit 28b359c
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 0 deletions.
234 changes: 234 additions & 0 deletions __testHelpers__/fixtures/specDetailNoComs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
export default {
index: {
specs: [
"220"
],
specDetailRoomTypes: [
"220"
],
specDetails: [
"220"
]
},
specs: {
"220": {
id: "220",
type: "specs",
attributes: {
createdAt: "2019-10-15T18:25:52.906Z",
updatedAt: "2019-10-15T18:25:52.906Z",
projectId: "1",
parentId: null,
areaId: "23",
specCategoryId: "2",
fileCareWarrantyId: null,
fileDesignerSpecsId: null,
customNumber: "C20",
description: "Regular Swivel Chair with long description including details about its aspect, dimentions and price",
priceCurrency: "USD",
unitOfMeasure: "EA",
atticStock: 43,
baseQuantity: 60,
priceCents: 85492,
clientBudgetCents: 1600,
overagePercent: 85,
isPlaceholder: false,
bidGroupId: null,
purchaseOrderId: "1",
specDetailIdSequence: [
"1976",
"1979",
"1981",
"6051"
],
vendorId: null,
quoteFileId: null,
invoiceFileId: null,
shopDrawingsFileId: null,
careWarrantyFileId: null,
designedSpecsFileId: null,
isCommitted: false,
overageValue: 51,
totalQuantity: 154,
price: 854.92,
totalPrice: 131657.68,
totalForecast: 131657.68,
totalQuantityWithoutOverage: 103
},
relationships: {
specDetails: {
data: [
{
id: "6051",
type: "specDetails"
},
{
id: "1981",
type: "specDetails"
},
{
id: "1979",
type: "specDetails"
},
{
id: "1976",
type: "specDetails"
}
]
}
}
}
},
specDetailRoomTypes: {
"1": {
id: "1",
type: "specDetailRoomTypes",
attributes: {
specDetailId: "6051",
name: "AreaRoom 9",
roomCount: 9,
perRoom: 4,
par: 4,
createdAt: "2019-10-15T18:28:53.435Z",
updatedAt: "2019-10-15T18:28:53.435Z"
}
},
"2": {
id: "2",
type: "specDetailRoomTypes",
attributes: {
specDetailId: "6051",
name: "AreaRoom 8",
roomCount: 6,
perRoom: 5,
par: 6,
createdAt: "2019-10-15T18:28:53.435Z",
updatedAt: "2019-10-15T18:28:53.435Z"
},
},
"3": {
id: "3",
type: "specDetailRoomTypes",
attributes: {
specDetailId: "6051",
name: "AreaRoom 7",
roomCount: 6,
perRoom: 5,
par: 6,
createdAt: "2019-10-15T18:28:53.435Z",
updatedAt: "2019-10-15T18:28:53.435Z"
},
}
},
specDetails: {
"1976": {
id: "1976",
type: "specDetails",
attributes: {
specId: "220",
title: "Score Fifteen",
description: "Fallen Pet Thee About Health",
unitsNeeded: 10,
unitsPerCase: 11,
createdAt: "2019-10-15T18:25:53.749Z",
updatedAt: "2019-10-15T18:25:53.749Z",
imageSrc: null,
locked: false,
type: "Description"
},
relationships: {
roomTypes: {
data: []
},
specDetailComs: {
data: []
}
}
},
"1979": {
id: "1979",
type: "specDetails",
attributes: {
specId: "220",
title: "Herd Somebody",
description: "Small Partly Near Climb Actual",
unitsNeeded: 10,
unitsPerCase: 11,
createdAt: "2019-10-15T18:25:53.749Z",
updatedAt: "2019-10-15T18:25:53.749Z",
imageSrc: null,
locked: false,
type: "Description"
},
relationships: {
roomTypes: {
data: []
},
specDetailComs: {
data: []
}
}
},
"1981": {
id: "1981",
type: "specDetails",
attributes: {
specId: "220",
title: "Itself Machinery",
description: "Larger Dead Fewer Valley Selection",
unitsNeeded: 10,
unitsPerCase: 11,
createdAt: "2019-10-15T18:25:53.749Z",
updatedAt: "2019-10-15T18:25:53.749Z",
imageSrc: null,
locked: false,
type: "Description"
},
relationships: {
roomTypes: {
data: []
},
specDetailComs: {
data: []
}
}
},
"6051": {
id: "6051",
type: "specDetails",
attributes: {
specId: "220",
title: null,
description: null,
unitsNeeded: null,
unitsPerCase: 4,
createdAt: "2019-10-15T18:28:53.422Z",
updatedAt: "2019-10-15T18:28:53.422Z",
imageSrc: null,
locked: false,
type: "QCParBased"
},
relationships: {
roomTypes: {
data: [
{
id: "1",
type: "specDetailRoomTypes"
},
{
id: "2",
type: "specDetailRoomTypes"
},
{
id: "3",
type: "specDetailRoomTypes"
}
]
},
specDetailComs: {
data: []
}
}
}
}
};
9 changes: 9 additions & 0 deletions __tests__/WhereRelated.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import resources from "../__testHelpers__/fixtures/patientsAndSettingsOfUseNormalized";
import resourcesNoRelationshipData from "../__testHelpers__/fixtures/patientsNoRelationshipDataNormalized";
import specDetailNoComs from "../__testHelpers__/fixtures/specDetailNoComs";
import Patient from "../__testHelpers__/models/Patient";
import Spec from "../__testHelpers__/models/Spec";
import Indication from "../__testHelpers__/models/Indication";

describe("Where related tests", () => {
Expand Down Expand Up @@ -38,4 +40,11 @@ describe("Where related tests", () => {
.toObjects();
expect(patients).toMatchSnapshot();
});
test("Should return all the available relationships", () => {
const specs = Spec.query(specDetailNoComs)
.includes(["specDetails.[specDetailComs.spec, roomTypes]"])
.where({id: ["220"]})
.toObjects();
expect(specs).toMatchSnapshot();
});
});
133 changes: 133 additions & 0 deletions __tests__/__snapshots__/WhereRelated.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,139 @@ Array [
]
`;

exports[`Where related tests Should return all the available relationships 1`] = `
Array [
Object {
"areaId": "23",
"atticStock": 43,
"baseQuantity": 60,
"bidGroupId": null,
"careWarrantyFileId": null,
"clientBudgetCents": 1600,
"createdAt": "2019-10-15T18:25:52.906Z",
"customNumber": "C20",
"description": "Regular Swivel Chair with long description including details about its aspect, dimentions and price",
"designedSpecsFileId": null,
"fileCareWarrantyId": null,
"fileDesignerSpecsId": null,
"id": "220",
"invoiceFileId": null,
"isCommitted": false,
"isPlaceholder": false,
"overagePercent": 85,
"overageValue": 51,
"parentId": null,
"price": 854.92,
"priceCents": 85492,
"priceCurrency": "USD",
"projectId": "1",
"purchaseOrderId": "1",
"quoteFileId": null,
"shopDrawingsFileId": null,
"specCategoryId": "2",
"specDetailIdSequence": Array [
"1976",
"1979",
"1981",
"6051",
],
"specDetails": Array [
Object {
"createdAt": "2019-10-15T18:28:53.422Z",
"description": null,
"id": "6051",
"imageSrc": null,
"locked": false,
"roomTypes": Array [
Object {
"createdAt": "2019-10-15T18:28:53.435Z",
"id": "1",
"name": "AreaRoom 9",
"par": 4,
"perRoom": 4,
"roomCount": 9,
"specDetailId": "6051",
"updatedAt": "2019-10-15T18:28:53.435Z",
},
Object {
"createdAt": "2019-10-15T18:28:53.435Z",
"id": "2",
"name": "AreaRoom 8",
"par": 6,
"perRoom": 5,
"roomCount": 6,
"specDetailId": "6051",
"updatedAt": "2019-10-15T18:28:53.435Z",
},
Object {
"createdAt": "2019-10-15T18:28:53.435Z",
"id": "3",
"name": "AreaRoom 7",
"par": 6,
"perRoom": 5,
"roomCount": 6,
"specDetailId": "6051",
"updatedAt": "2019-10-15T18:28:53.435Z",
},
],
"specId": "220",
"title": null,
"type": "QCParBased",
"unitsNeeded": null,
"unitsPerCase": 4,
"updatedAt": "2019-10-15T18:28:53.422Z",
},
Object {
"createdAt": "2019-10-15T18:25:53.749Z",
"description": "Larger Dead Fewer Valley Selection",
"id": "1981",
"imageSrc": null,
"locked": false,
"specId": "220",
"title": "Itself Machinery",
"type": "Description",
"unitsNeeded": 10,
"unitsPerCase": 11,
"updatedAt": "2019-10-15T18:25:53.749Z",
},
Object {
"createdAt": "2019-10-15T18:25:53.749Z",
"description": "Small Partly Near Climb Actual",
"id": "1979",
"imageSrc": null,
"locked": false,
"specId": "220",
"title": "Herd Somebody",
"type": "Description",
"unitsNeeded": 10,
"unitsPerCase": 11,
"updatedAt": "2019-10-15T18:25:53.749Z",
},
Object {
"createdAt": "2019-10-15T18:25:53.749Z",
"description": "Fallen Pet Thee About Health",
"id": "1976",
"imageSrc": null,
"locked": false,
"specId": "220",
"title": "Score Fifteen",
"type": "Description",
"unitsNeeded": 10,
"unitsPerCase": 11,
"updatedAt": "2019-10-15T18:25:53.749Z",
},
],
"totalForecast": 131657.68,
"totalPrice": 131657.68,
"totalQuantity": 154,
"totalQuantityWithoutOverage": 103,
"unitOfMeasure": "EA",
"updatedAt": "2019-10-15T18:25:52.906Z",
"vendorId": null,
},
]
`;

exports[`Where related tests Should return empty array for uninitialized relationships queries 1`] = `Array []`;

exports[`Where related tests Single id 1`] = `
Expand Down
Loading

0 comments on commit 28b359c

Please sign in to comment.