Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Use Factory to mock FulfillmentMethod #5988

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const shopName = "Test Shop";

const groups = ["Standard", "Priority", "Next-Day"];

const mockShippingMethod = {
const mockFulfillmentMethodInput = {
name: "mockMethod",
label: `${groups[0]} mockMethod`,
handling: 9.5,
Expand Down Expand Up @@ -67,7 +67,7 @@ test("user can not create flat rate fulfillment method if admin is not logged in
await createFlatRateFulfillmentMethod({
input: {
shopId: opaqueShopId,
method: mockShippingMethod
method: mockFulfillmentMethodInput
}
});
} catch (errors) {
Expand All @@ -84,15 +84,15 @@ test("user can create flat rate fulfillment method if admin is logged in", async
result = await createFlatRateFulfillmentMethod({
input: {
shopId: opaqueShopId,
method: mockShippingMethod
method: mockFulfillmentMethodInput
}
});
} catch (error) {
expect(error).toBeUndefined();
return;
}

expect(result.createFlatRateFulfillmentMethod.method).toEqual(mockShippingMethod);
expect(result.createFlatRateFulfillmentMethod.method).toEqual(mockFulfillmentMethodInput);
});


Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; // reaction/shop:123
const shopName = "Test Shop";

const groups = ["Standard", "Priority", "Next-Day"];
const mockFulfillmentMethodId = "mockMethod";
const opaqueMockFulfillmentMethodId = encodeOpaqueId("reaction/fulfillmentMethod", mockFulfillmentMethodId);

const mockShippingMethod = {
const mockFulfillmentMethodData = {
name: "mockMethod",
label: `${groups[0]} mockMethod`,
handling: 9.5,
Expand All @@ -24,8 +26,11 @@ const mockShippingMethod = {
group: groups[0]
};

const mockShippingMethodId = "mockMethod";
const opaqueMockShippingMethodId = encodeOpaqueId("reaction/fulfillmentMethod", mockShippingMethodId);
const mockFulfillmentMethod = Factory.FulfillmentMethod.makeOne({
...mockFulfillmentMethodData,
_id: mockFulfillmentMethodId,
shopId: internalShopId
});

const mockCustomerAccount = Factory.Account.makeOne({
roles: {
Expand All @@ -52,9 +57,9 @@ beforeAll(async () => {

await testApp.collections.Shipping.insertOne({
methods: [{
_id: mockShippingMethodId,
_id: mockFulfillmentMethodId,
shopId: internalShopId,
...mockShippingMethod
...mockFulfillmentMethod
}],
shopId: internalShopId
});
Expand All @@ -79,7 +84,7 @@ test("user can not delete flat rate fulfillment method if admin is not logged in
try {
await deleteFlatRateFulfillmentMethod({
input: {
methodId: opaqueMockShippingMethodId,
methodId: opaqueMockFulfillmentMethodId,
shopId: opaqueShopId
}
});
Expand All @@ -96,7 +101,7 @@ test("user can delete flat rate fulfillment method if admin is logged in", async
try {
result = await deleteFlatRateFulfillmentMethod({
input: {
methodId: opaqueMockShippingMethodId,
methodId: opaqueMockFulfillmentMethodId,
shopId: opaqueShopId
}
});
Expand All @@ -106,8 +111,8 @@ test("user can delete flat rate fulfillment method if admin is logged in", async
}

expect(result.deleteFlatRateFulfillmentMethod.method).toEqual({
_id: opaqueMockShippingMethodId,
...mockShippingMethod
_id: opaqueMockFulfillmentMethodId,
...mockFulfillmentMethodData
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ const opaqueShopId = "cmVhY3Rpb24vc2hvcDoxMjM="; // reaction/shop:123
const shopName = "Test Shop";

const groups = ["Standard", "Priority", "Next-Day"];
const mockFulfillmentMethodId = "mockMethod";
const opaqueMockFulfillmentMethodId = encodeOpaqueId("reaction/fulfillmentMethod", mockFulfillmentMethodId);

const mockShippingMethod = {
const mockFulfillmentMethod = Factory.FulfillmentMethod.makeOne({
_id: mockFulfillmentMethodId,
shopId: internalShopId,
name: "mockMethod",
label: `${groups[0]} mockMethod`,
handling: 9.5,
Expand All @@ -22,10 +26,18 @@ const mockShippingMethod = {
isEnabled: true,
fulfillmentTypes: ["shipping"],
group: groups[0]
};
});

const mockShippingMethodId = "mockMethod";
const opaqueMockShippingMethodId = encodeOpaqueId("reaction/fulfillmentMethod", mockShippingMethodId);
const mockFulfillmentMethodInput = {
name: "mockMethod2",
label: `${groups[1]} mockMethod`,
handling: 19.5,
rate: 80,
cost: 8,
isEnabled: false,
fulfillmentTypes: ["shipping"],
group: groups[1]
};

const mockCustomerAccount = Factory.Account.makeOne({
roles: {
Expand All @@ -51,11 +63,7 @@ beforeAll(async () => {
await testApp.insertPrimaryShop({ _id: internalShopId, name: shopName });

await testApp.collections.Shipping.insertOne({
methods: [{
_id: mockShippingMethodId,
shopId: internalShopId,
...mockShippingMethod
}],
methods: [mockFulfillmentMethod],
shopId: internalShopId
});
});
Expand All @@ -79,13 +87,9 @@ test("user can not update flat rate fulfillment method if admin is not logged in
try {
await updateFlatRateFulfillmentMethod({
input: {
methodId: opaqueMockShippingMethodId,
methodId: opaqueMockFulfillmentMethodId,
shopId: opaqueShopId,
method: {
...mockShippingMethod,
label: `${groups[1]} mockMethod`,
group: groups[1]
}
method: mockFulfillmentMethodInput
}
});
} catch (errors) {
Expand All @@ -101,13 +105,9 @@ test("user can update flat rate fulfillment method if admin is logged in", async
try {
result = await updateFlatRateFulfillmentMethod({
input: {
methodId: opaqueMockShippingMethodId,
methodId: opaqueMockFulfillmentMethodId,
shopId: opaqueShopId,
method: {
...mockShippingMethod,
label: `${groups[1]} mockMethod`,
group: groups[1]
}
method: mockFulfillmentMethodInput
}
});
} catch (error) {
Expand All @@ -116,10 +116,8 @@ test("user can update flat rate fulfillment method if admin is logged in", async
}

expect(result.updateFlatRateFulfillmentMethod.method).toEqual({
...mockShippingMethod,
_id: opaqueMockShippingMethodId,
label: `${groups[1]} mockMethod`,
group: groups[1]
...mockFulfillmentMethodInput,
_id: opaqueMockFulfillmentMethodId
});
});

Expand Down
3 changes: 3 additions & 0 deletions tests/util/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ import {

import { AddressValidationRule } from "../../src/core-services/address/simpleSchemas.js";

import FulfillmentMethod from "../../src/plugins/shipping-rates/util/methodSchema.js";

import Restriction from "../../src/plugins/shipping-rates/util/restrictionSchema.js";

const schemasToAddToFactory = {
Expand All @@ -109,6 +111,7 @@ const schemasToAddToFactory = {
Discounts,
Email,
EmailTemplates,
FulfillmentMethod,
Group,
NavigationItem,
NavigationTree,
Expand Down