This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Remember to add this require | |
const { estimateShipping } = require("./estimateShipping"); | |
exports.resolvers = { | |
Product: { | |
__resolveReference(object) { | |
return { | |
...object, | |
...inventory.find(product => product.upc === object.upc) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("should be calculated with estimateShipping based on the price and weight", async () => { | |
const PRICE = 999; | |
const WEIGHT = 100; | |
const mocks = { Product: () => ({ price: PRICE, weight: WEIGHT }) }; | |
td.when(estimateShipping({ price: PRICE, weight: WEIGHT })).thenReturn(99); | |
const result = await executeGraphql({ | |
query, | |
service, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const td = require("testdouble"); | |
require("testdouble-jest")(td, jest); | |
const { gql } = require("apollo-server"); | |
const { executeGraphql } = require("federation-testing-tool"); | |
// This is the added line! Make sure it's above the line that requires resolvers. | |
const { estimateShipping } = td.replace("./estimateShipping"); | |
// | |
const { typeDefs } = require("./typeDefs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put these two lines at the top of inventory.test.js | |
const td = require("testdouble"); | |
require("testdouble-jest")(td, jest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.estimateShipping = ({price, weight}) => { | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("should be calculated as 1 dollar per 2 pounds for an item with a price of 1000 or below", async () => { | |
const mocks = { Product: () => ({ price: 999, weight: 100 }) }; | |
const result = await executeGraphql({ query, service, mocks }); | |
expect(result.data._getProduct.shippingEstimate).toEqual(50); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("should be 0 for an item with a price over 1000", async () => { | |
const mocks = { Product: () => ({ price: 1001 }) }; | |
const result = await executeGraphql({ query, service, mocks }); | |
expect(result.data._getProduct.shippingEstimate).toStrictEqual(0); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { executeGraphql } = require("federation-testing-tool"); | |
// ... | |
// Modify your first it.todo function callback, and remove .todo | |
it("should be 0 for an item with a price over 1000", async () => { | |
const result = await executeGraphql({ query, service }); | |
expect(result.data._getProduct.shippingEstimate).toEqual(0) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { gql } = require("apollo-server"); | |
const { typeDefs } = require("./typeDefs"); | |
const { resolvers } = require("./resolvers"); | |
const service = { typeDefs, resolvers } | |
// describe("Based on the data passed down from the gateway, the shippingEstimate", () => { | |
// .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { gql } = require("apollo-server"); | |
describe("Based on the data passed down from the gateway, the shippingEstimate", () => { | |
const query = gql` | |
{ | |
_getProduct { | |
shippingEstimate | |
} | |
} | |
`; |