Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
da2100d
feat: initial commit fulfillment base
sujithvn Nov 1, 2022
5848903
feat: initial commit fulfillment base
sujithvn Oct 17, 2022
b57ea4a
Merge remote-tracking branch 'origin/01-fulfillment-base' into 01-ful…
sujithvn Oct 18, 2022
0de0992
fix: pnpm-lock
sujithvn Oct 18, 2022
18c9870
fix: to generate function name in camel-case
sujithvn Oct 19, 2022
3a2fa08
feat: createFFType test
sujithvn Oct 24, 2022
4acb9e1
feat: ff-type tests
sujithvn Oct 24, 2022
b5edb37
fix: review comment fixes
sujithvn Oct 26, 2022
ebd684c
fix: removed string concatenation logic
sujithvn Oct 27, 2022
3ecab7d
fix: use queries.getCartById delete /util version
sujithvn Oct 28, 2022
fd9d72c
fix: fixed broken test
sujithvn Oct 31, 2022
5a09c25
feat: fulfillment type pickup and method store
sujithvn Oct 19, 2022
5dbcb91
fix: review comments fixes
sujithvn Oct 27, 2022
ef301ba
fix: import fix
sujithvn Oct 29, 2022
d202e97
fix: pnpm-lock update without snyk
sujithvn Nov 3, 2022
e0c056e
feat: fftype-shipping with methods flatrate ups
sujithvn Oct 18, 2022
d5252f5
fix: updated test cases
sujithvn Oct 19, 2022
3156bae
fix: filename fixed
sujithvn Oct 24, 2022
0c30b61
fix: review comment fixes
sujithvn Oct 27, 2022
2d9044d
fix: picked up the fix #6578 from old plugin
sujithvn Nov 3, 2022
37e3dd6
fix: renamed collection in test.js
sujithvn Oct 28, 2022
70bb0b9
fix: import fix
sujithvn Oct 29, 2022
975ea93
fix: renamed top-level folder ups to dynamic-rate
sujithvn Oct 29, 2022
2d543a3
fix: pnpm-lock without snyk
sujithvn Nov 3, 2022
2da2803
feat: changes related to carts plugin
sujithvn Oct 20, 2022
d2d37ec
feat: changes related to catalogs plugin
sujithvn Oct 20, 2022
b455518
feat: changes related to orders plugin
sujithvn Oct 20, 2022
d8f2465
feat: changes related to products plugin
sujithvn Oct 20, 2022
25a91b6
feat: integration test updates
sujithvn Oct 20, 2022
7314195
feat: switch from old shipments to fulfillment
sujithvn Nov 3, 2022
b047c03
feat: test setFulfillmentTypeForItems
sujithvn Oct 24, 2022
0ddcaa4
fix: package and plugin.json update
sujithvn Oct 29, 2022
d88a878
fix: review comment combine destructure
sujithvn Nov 3, 2022
1cdfafe
feat: new validateOrder and placeOrder refactor
sujithvn Oct 20, 2022
0520273
feat: first set of tests placeOrder refactor
sujithvn Oct 25, 2022
07c5436
fix: review comments fixes
sujithvn Oct 27, 2022
adf38b0
fix: export getCartById as query
sujithvn Nov 3, 2022
867434c
fix: pnpm-lock update without snyk
sujithvn Nov 3, 2022
79eac5e
feat: data migration for fulfillment feature
sujithvn Nov 4, 2022
c5ab64e
feat: migrate shopsetting for default ff-type
sujithvn Oct 4, 2022
a6356cb
fix: migration script fix
sujithvn Oct 6, 2022
3d016d7
fix: review comment fixes
sujithvn Oct 13, 2022
3acaeb4
fix: typo in 2.js
sujithvn Oct 13, 2022
bc2974d
fix: review comment fixes2
sujithvn Nov 7, 2022
3404407
fix: pnpm-lock without snyk
sujithvn Nov 7, 2022
278c8d4
fix: review comment fixes 1
sujithvn Nov 10, 2022
346460d
fix: review comment fixes 2
sujithvn Nov 15, 2022
da70978
fix: review comment fix 3
sujithvn Nov 15, 2022
5deec1c
fix: fix validatePermission
sujithvn Nov 16, 2022
7dfa566
fix: fix validatePermissions
sujithvn Nov 16, 2022
6e1c711
fix: review comment fixes
sujithvn Nov 17, 2022
ddca358
fix: review comment fixes
sujithvn Nov 17, 2022
3862d7b
fix: review comment fixes
sujithvn Nov 21, 2022
1e21608
fix: review comment fixes
sujithvn Mar 10, 2023
c774be7
Merge branch 'feat/fulfillment-types' into 00-fulfillment-base
sujithvn Mar 10, 2023
37536fa
fix: test errors and pnpm-lock
sujithvn Mar 10, 2023
7ed401f
Merge 00-fulfillment-base into new-fulfillment-type-shipping
sujithvn Mar 10, 2023
9f16175
fix: review comment updates
sujithvn Mar 10, 2023
e9497a0
Merge 00-fulfillment-base into new-fulfillment-type-pickup
sujithvn Mar 10, 2023
22b0c79
fix: unit test fix
sujithvn Mar 10, 2023
24a3202
fix: review comments
sujithvn Mar 10, 2023
edaa82b
fix: review comment updates
sujithvn Mar 10, 2023
13caba9
Merge branch 'feat/fulfillment-types' into new-fulfillment-impacted-p…
sujithvn Mar 10, 2023
61bc0a3
fix: unit test update
sujithvn Mar 11, 2023
3e6b7d2
fix: variable reuse
sujithvn Mar 12, 2023
a2bc593
Merge branch '00-fulfillment-base' into new-fulfillment-impacted-plugins
sujithvn Mar 13, 2023
bf821f7
Merge branch 'new-fulfillment-type-shipping' into new-fulfillment-imp…
sujithvn Mar 13, 2023
1e8b011
Merge fulfillment-pickup into impacted plugins
sujithvn Mar 13, 2023
a1cfcd7
fix: integration test updates
sujithvn Mar 13, 2023
1d94aa6
fix: filename case change
sujithvn Mar 13, 2023
059e4f0
fix: filename case 2
sujithvn Mar 13, 2023
ff3d042
Merge branch '00-fulfillment-base' into new-placeOrder-refactor-valid…
sujithvn Mar 13, 2023
3806ed8
Merge branch 'new-fulfillment-type-shipping' into new-placeOrder-refa…
sujithvn Mar 13, 2023
e7b3d23
Merge branch 'new-fulfillment-type-pickup' into new-placeOrder-refact…
sujithvn Mar 13, 2023
0117580
fix: pnpm-lock merge
sujithvn Mar 13, 2023
68d8313
Merge branch 'new-fulfillment-impacted-plugins' into new-placeOrder-r…
sujithvn Mar 13, 2023
8cf2151
fix: failing test fixes
sujithvn Mar 13, 2023
17909c3
fix: missed out review comment
sujithvn Mar 13, 2023
141145c
Merge pull request #6613 from reactioncommerce/new-fulfillment-type-p…
sujithvn May 18, 2023
c7a719d
Merge branch '00-fulfillment-base' of github.com:reactioncommerce/rea…
sujithvn May 18, 2023
f790476
Merge branch '00-fulfillment-base' into new-fulfillment-type-shipping
sujithvn May 18, 2023
fe15a55
fix: fixed test errors
sujithvn May 18, 2023
97946d6
Merge pull request #6614 from reactioncommerce/new-fulfillment-type-s…
sujithvn May 18, 2023
bf77d11
Merge branch '00-fulfillment-base' of github.com:reactioncommerce/rea…
sujithvn May 18, 2023
761bd13
Merge branch '00-fulfillment-base' into new-fulfillment-impacted-plugins
sujithvn May 18, 2023
5fed7d5
Merge pull request #6615 from reactioncommerce/new-fulfillment-impact…
sujithvn May 18, 2023
258e551
Merge branch '00-fulfillment-base' of github.com:reactioncommerce/rea…
sujithvn May 18, 2023
5b36b12
Merge branch '00-fulfillment-base' into new-placeOrder-refactor-valid…
sujithvn May 18, 2023
344bbf6
Merge pull request #6616 from reactioncommerce/new-placeOrder-refacto…
sujithvn May 18, 2023
1b09f81
Merge branch '00-fulfillment-base' of github.com:reactioncommerce/rea…
sujithvn May 18, 2023
9193072
Merge branch '00-fulfillment-base' into new-data-migration-fulfillment
sujithvn May 18, 2023
13bab48
fix: linter error
sujithvn May 18, 2023
1ec99f9
Merge pull request #6633 from reactioncommerce/new-data-migration-ful…
sujithvn May 18, 2023
ddff28d
Merge branch '00-fulfillment-base' of github.com:reactioncommerce/rea…
sujithvn May 18, 2023
df5ed5e
fix: changes picked from closed pr 6543
sujithvn May 18, 2023
7503a64
fix: picked chgs from closed pr 6545
sujithvn May 18, 2023
6d7b785
Merge pull request #6610 from reactioncommerce/00-fulfillment-base
sujithvn May 18, 2023
ca155a6
Merge branch 'feat/fulfillment-types' of github.com:reactioncommerce/…
sujithvn May 19, 2023
a90dc01
fix: change set
sujithvn May 19, 2023
d4c0607
fix: cartVersion to fulfillmentCartVersion
sujithvn May 19, 2023
95e84af
Merge branch 'release-5' of github.com:reactioncommerce/reaction into…
sujithvn May 23, 2023
10c2150
Merge branch 'release-5' into feat/fulfillment-types
sujithvn May 23, 2023
401b46e
feat: node18 changes fulfillment types
sujithvn May 23, 2023
7096d50
feat: decode changes fulfillment types
sujithvn May 23, 2023
a0804b5
fix: linter fixes
sujithvn May 23, 2023
000917d
fix: linter fixes
sujithvn May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const inputSchema = new SimpleSchema({
* @summary Creates a fulfillment method
* @param {Object} context - an object containing the per-request state
* @param {Object} input - Input
* @param {Number} cost - optional cost
* @param {String[]} fulfillmentTypes - fulfillment type retained for backward compatibility
* @param {String} group - Group to which fulfillment method belong
* @param {Number} handling - handling charges
* @param {Boolean} enabled - status of fulfillment method
* @param {String} label - displayed on the UI
* @param {String} fulfillmentMethod - used by application, not user editable
* @param {String} displayMessageMethod - used to display additional message on UI specific to ff-method
* @param {Number} rate - ratefor themethod
* @param {Number} input.cost - optional cost
* @param {String[]} input.fulfillmentTypes - fulfillment type retained for backward compatibility
* @param {String} input.group - Group to which fulfillment method belong
* @param {Number} input.handling - handling charges
* @param {Boolean} input.enabled - status of fulfillment method
* @param {String} input.label - displayed on the UI
* @param {String} input.fulfillmentMethod - used by application, not user editable
* @param {String} input.displayMessageMethod - used to display additional message on UI specific to ff-method
* @param {Number} input.rate - rate for the method
* @returns {Promise<Object>} An object with a `method` property containing the created method
*/
export default async function createFulfillmentMethodMutation(context, input) {
Expand All @@ -35,18 +35,14 @@ export default async function createFulfillmentMethodMutation(context, input) {

await context.validatePermissions("reaction:legacy:fulfillmentMethods", "create", { shopId });

const ffTypeRecord = await Fulfillment.findOne({ _id: fulfillmentTypeId, shopId });
if (!ffTypeRecord) throw new ReactionError("server-error", "Unable to create fulfillment method without defined type");
const fulfillmentType = await Fulfillment.findOne({ _id: fulfillmentTypeId, shopId });
if (!fulfillmentType) throw new ReactionError("server-error", "Unable to create fulfillment method without defined type");

const ffTypeMethodRecord = await Fulfillment.findOne({
_id: fulfillmentTypeId,
shopId,
methods: { $elemMatch: { fulfillmentMethod: method.fulfillmentMethod } }
});
if (ffTypeMethodRecord) throw new ReactionError("server-error", "Fulfillment Method already exists");
const fulfillmentMethod = fulfillmentType.methods?.find((currMethod) => currMethod.fulfillmentMethod === method.fulfillmentMethod);
if (fulfillmentMethod) throw new ReactionError("server-error", "Fulfillment Method already exists");

method._id = Random.id();
method.fulfillmentTypes = [ffTypeRecord.fulfillmentType];
method.fulfillmentTypes = [fulfillmentType.fulfillmentType];

const { matchedCount } = await Fulfillment.updateOne({
shopId,
Expand All @@ -59,5 +55,5 @@ export default async function createFulfillmentMethodMutation(context, input) {

if (matchedCount === 0) throw new ReactionError("server-error", "Unable to create fulfillment method");

return { group: method };
return { method };
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ test("throws if required fields are not supplied", async () => {
shopId: "SHOP_ID"
};

await expect(createFulfillmentMethodMutation(mockContext, fulfillmentMethodInput)).rejects.toThrowErrorMatchingSnapshot();
const expectedError = "Fulfillment types is required";
await expect(createFulfillmentMethodMutation(mockContext, fulfillmentMethodInput)).rejects.toThrow(expectedError);
});

test("add a new fulfillment method", async () => {
Expand Down Expand Up @@ -55,7 +56,7 @@ test("add a new fulfillment method", async () => {
});

expect(result).toEqual({
group: {
method: {
_id: expect.any(String),
cost: 99,
handling: 99,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ import { FulfillmentTypeSchema } from "../simpleSchemas.js";
* @param {ProviderSchema} input.provider - Provider details
* @param {String} input.fulfillmentType - fulfillment type
* @param {String} input.displayMessageType - displayMessage for fulfillment type
* @param {FulfillmentMethodSchema[]} input.methods - ff-method array
* @returns {Promise<Object>} An object with the updated type
*/
export default async function createFulfillmentType(context, input) {
const cleanedInput = FulfillmentTypeSchema.clean(input);
if (!cleanedInput.provider) cleanedInput.provider = {};
cleanedInput.provider.name = cleanedInput.name;
if (cleanedInput.provider) cleanedInput.provider.name = cleanedInput.name;

if (cleanedInput.method) {
cleanedInput.method._id = Random.id();
cleanedInput.method.fulfillmentTypes = [cleanedInput.fulfillmentType];
// Although allowed by schema, we do not add the ff-method while creating a new ff-type
// FulfillmentMethods are expected to be added using the mutation createFulfillmentMethod
// (as it makes sense to add a new ff-method only by a new plugin implementation).
if (cleanedInput.methods) {
delete cleanedInput.methods;
}
const createdAt = new Date();
cleanedInput.createdAt = createdAt;
cleanedInput.updatedAt = createdAt;
FulfillmentTypeSchema.validate(cleanedInput);

const { collections: { Fulfillment } } = context;
const { shopId, fulfillmentType } = cleanedInput;

const ffTypeRecord = await Fulfillment.findOne({ shopId, fulfillmentType });
if (ffTypeRecord) throw new ReactionError("invalid-parameter", "Fulfillment Type already exists");
const existingFulfillmentType = await Fulfillment.findOne({ shopId, fulfillmentType });
if (existingFulfillmentType) throw new ReactionError("invalid-parameter", "Fulfillment Type already exists");

await context.validatePermissions("reaction:legacy:fulfillmentTypes", "create", { shopId });

Expand All @@ -40,5 +43,5 @@ export default async function createFulfillmentType(context, input) {
});
if (insertedCount === 0) throw new ReactionError("server-error", "Unable to create fulfillment type");

return { group: { name: cleanedInput.name, fulfillmentType: cleanedInput.fulfillmentType } };
return { fulfillmentType: { name: cleanedInput.name, fulfillmentType: cleanedInput.fulfillmentType } };
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ mockContext.validatePermissions.mockReturnValueOnce(Promise.resolve(null));

test("throws if required fields are not supplied", async () => {
const fulfillmentTypeInput = {
shopId: "SHOP_ID",
name: "fulfillmentType123"
shopId: "SHOP_ID"
// name: "fulfillmentType123"
};

await expect(createFulfillmentTypeMutation(mockContext, fulfillmentTypeInput)).rejects.toThrowErrorMatchingSnapshot();
const expectedError = "Name is required";
await expect(createFulfillmentTypeMutation(mockContext, fulfillmentTypeInput)).rejects.toThrow(expectedError);
});

test("throws if the fulfillmentType added already exists", async () => {
Expand Down Expand Up @@ -61,7 +62,7 @@ test("add a new fulfillment type", async () => {
const result = await createFulfillmentTypeMutation(mockContext, fulfillmentTypeInput);

expect(result).toEqual({
group: {
fulfillmentType: {
name: "fulfillmentType123",
fulfillmentType: "shipping"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ test("selects an existing shipping method", async () => {
});

test("throws if there is no fulfillment group with the given ID", async () => {
const expectedError = "Fulfillment group with ID group2 not found in cart with ID cartId";
await expect(selectFulfillmentOptionForGroup(mockContext, {
cartId: "cartId",
fulfillmentGroupId: "group2",
fulfillmentMethodId: "valid-method"
})).rejects.toThrowErrorMatchingSnapshot();
})).rejects.toThrow(expectedError);
});

test("throws if there is no fulfillment method with the given ID among the options", async () => {
const expectedError = "Fulfillment option with method ID invalid-method not found in cart with ID cartId";
await expect(selectFulfillmentOptionForGroup(mockContext, {
cartId: "cartId",
fulfillmentGroupId: "group1",
fulfillmentMethodId: "invalid-method"
})).rejects.toThrowErrorMatchingSnapshot();
})).rejects.toThrow(expectedError);
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import { FulfillmentMethodSchema } from "../simpleSchemas.js";
import { UserEditableFulfillmentMethodSchema } from "../simpleSchemas.js";


const inputSchema = new SimpleSchema({
method: FulfillmentMethodSchema,
method: UserEditableFulfillmentMethodSchema,
fulfillmentTypeId: String,
methodId: String,
shopId: String
Expand All @@ -14,7 +15,7 @@ const inputSchema = new SimpleSchema({
* @summary updates Fulfillment method
* @param {Object} context - an object containing the per-request state
* @param {Object} input - Input object
* @param {FulfillmentMethodSchema} input.method - fulfillment method object
* @param {UserEditableFulfillmentMethodSchema} input.method - fulfillment method object with only user editable fields
* @param {String} input.fulfillmentTypeId - id of fulfillment type
* @param {String} input.methodId - ff-method Id
* @param {String} input.shopId - Shop Id
Expand All @@ -28,30 +29,18 @@ export default async function updateFulfillmentMethodMutation(context, input) {
const { collections: { Fulfillment } } = context;
const method = { ...inputMethod };

if (!fulfillmentTypeId) throw new ReactionError("invalid-parameter", "Fulfillment Type ID to be updated not provided");
if (!methodId) throw new ReactionError("invalid-parameter", "Method ID to be updated not provided");

await context.validatePermissions(`reaction:legacy:fulfillmentMethods:${methodId}`, "update", { shopId });
await context.validatePermissions("reaction:legacy:fulfillmentMethods", "update", { shopId });

const ffTypeMethodRecord = await Fulfillment.findOne({
const fulfillmentType = await Fulfillment.findOne({
"_id": fulfillmentTypeId,
shopId,
"methods._id": methodId
});
if (!ffTypeMethodRecord) throw new ReactionError("server-error", "Fulfillment Method does not exist");
if (!fulfillmentType) throw new ReactionError("server-error", "Fulfillment Type / Method does not exist");

// Do not update the fulfillmentType, fulfillmentMethod, group, name & _id fields
// Find the matching fulfillmentMethod object and use those values to over-write
const currentFulfillmentMethod = (ffTypeMethodRecord.methods || []).find((meth) => meth._id === methodId);
const currentFulfillmentMethod = (fulfillmentType.methods || []).find((meth) => meth._id === methodId);
if (!currentFulfillmentMethod) throw new ReactionError("server-error", "Fulfillment Method does not exist");
const updatedMethod = {
...method,
_id: methodId,
name: currentFulfillmentMethod.name,
group: currentFulfillmentMethod.group,
fulfillmentMethod: currentFulfillmentMethod.fulfillmentMethod,
fulfillmentType: [ffTypeMethodRecord.fulfillmentType]
};
const updatedMethod = { ...currentFulfillmentMethod, ...method }; // update only provided user editable fields

const { matchedCount } = await Fulfillment.updateOne({
"_id": fulfillmentTypeId,
Expand All @@ -64,5 +53,5 @@ export default async function updateFulfillmentMethodMutation(context, input) {
});
if (matchedCount === 0) throw new ReactionError("not-found", "Fulfillment type to be updated not found");

return { group: updatedMethod };
return { method: updatedMethod };
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test("throws if required fields are not supplied", async () => {
}
};

await expect(updateFulfillmentMethodMutation(mockContext, fulfillmentMethodInput)).rejects.toThrowErrorMatchingSnapshot();
const expectedError = "Method ID is required";
await expect(updateFulfillmentMethodMutation(mockContext, fulfillmentMethodInput)).rejects.toThrow(expectedError);
});

test("throws if the fulfillmentType does not exists", async () => {
Expand All @@ -42,7 +43,7 @@ test("throws if the fulfillmentType does not exists", async () => {
rate: 99
}
};
const expectedError = new ReactionError("server-error", "Fulfillment Method does not exist");
const expectedError = new ReactionError("server-error", "Fulfillment Type / Method does not exist");
await expect(updateFulfillmentMethodMutation(mockContext, fulfillmentMethodInput)).rejects.toThrow(expectedError);
});

Expand Down Expand Up @@ -116,11 +117,10 @@ test("should update an existing fulfillment method", async () => {
};

const expectedOutput = {
group: {
method: {
_id: "fulfillmentMethodId01",
enabled: true,
fulfillmentMethod: "ups",
fulfillmentType: ["Shipping"],
fulfillmentTypes: ["Shipping"],
group: "Ground",
handling: 99,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default async function updateFulfillmentOptionsForGroup(context, input) {

const commonOrder = await context.queries.getCommonOrderForCartGroup(context, { cart, fulfillmentGroupId: fulfillmentGroup._id });
// In the future we want to do this async and subscribe to the results
const rates = await context.queries.getFulfillmentMethodsWithQuotes(commonOrder, context);
const rates = await context.queries.fulfillmentMethodsWithQuotes(commonOrder, context);

const { shipmentQuotes, shipmentQuotesQueryStatus } = getShipmentQuotesQueryStatus(rates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import updateFulfillmentOptionsForGroup from "./updateFulfillmentOptionsForGroup

const fakeCart = Factory.Cart.makeOne();
const fakeQuote = Factory.ShipmentQuote.makeOne();
const mockGetFulfillmentMethodsWithQuotes = jest.fn().mockName("getFulfillmentMethodsWithQuotes");
const mockFulfillmentMethodsWithQuotes = jest.fn().mockName("fulfillmentMethodsWithQuotes");
const mockGetCommonOrderForCartGroup = jest.fn().mockName("getCommonOrderForCartGroup");

beforeAll(() => {
mockContext.queries = {
getFulfillmentMethodsWithQuotes: mockGetFulfillmentMethodsWithQuotes,
fulfillmentMethodsWithQuotes: mockFulfillmentMethodsWithQuotes,
getCommonOrderForCartGroup: mockGetCommonOrderForCartGroup
};
if (!mockContext.mutations.saveCart) {
Expand All @@ -22,7 +22,7 @@ beforeAll(() => {
});

beforeEach(() => {
mockGetFulfillmentMethodsWithQuotes.mockClear();
mockFulfillmentMethodsWithQuotes.mockClear();

mockContext.queries.getCartById = jest.fn().mockName("getCartById").mockReturnValueOnce(Promise.resolve({
_id: "cartId",
Expand All @@ -47,7 +47,7 @@ beforeEach(() => {
});

test("updates cart properly for empty rates", async () => {
mockGetFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([]));
mockFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([]));
mockContext.collections.Cart.findOne.mockReturnValueOnce(Promise.resolve(fakeCart));

const result = await updateFulfillmentOptionsForGroup(mockContext, {
Expand Down Expand Up @@ -83,7 +83,7 @@ test("updates cart properly for empty rates", async () => {
});

test("updates cart properly for error rates", async () => {
mockGetFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([{
mockFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([{
requestStatus: "error",
shippingProvider: "all",
message: "All requests for shipping methods failed."
Expand Down Expand Up @@ -126,7 +126,7 @@ test("updates cart properly for error rates", async () => {
});

test("updates cart properly for success rates", async () => {
mockGetFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([fakeQuote]));
mockFulfillmentMethodsWithQuotes.mockReturnValueOnce(Promise.resolve([fakeQuote]));
mockContext.collections.Cart.findOne.mockReturnValueOnce(Promise.resolve(fakeCart));

const result = await updateFulfillmentOptionsForGroup(mockContext, {
Expand Down Expand Up @@ -165,8 +165,9 @@ test("updates cart properly for success rates", async () => {
});

test("throws if there is no fulfillment group with the given ID", async () => {
const expectedError = "Fulfillment group with ID group2 not found in cart with ID cartId";
await expect(updateFulfillmentOptionsForGroup(mockContext, {
cartId: "cartId",
fulfillmentGroupId: "group2"
})).rejects.toThrowErrorMatchingSnapshot();
})).rejects.toThrow(expectedError);
});
Loading