merge develop and resolve conflicts

This commit is contained in:
zakariaelas
2021-10-14 15:44:58 +01:00
151 changed files with 3546 additions and 1239 deletions

View File

@@ -1,33 +1,33 @@
const { useApi } = require("../../helpers/use-api");
const { useApi } = require("../../helpers/use-api")
const header = {
headers: {
authorization: "Bearer test_token",
},
};
}
const resolveCall = async (path, payload, header) => {
const api = useApi();
let res;
const api = useApi()
let res
try {
const resp = await api.post(path, payload, header);
res = resp.status;
const resp = await api.post(path, payload, header)
res = resp.status
} catch (expectedException) {
try {
res = expectedException.response.status;
res = expectedException.response.status
} catch (_) {
console.error(expectedException);
console.error(expectedException)
}
}
return res;
};
return res
}
const determineFail = (actual, expected, path) => {
if (expected !== actual) {
console.log(`failed at path : ${path}`);
console.log(`failed at path : ${path}`)
}
expect(actual).toEqual(expected);
};
expect(actual).toEqual(expected)
}
/**
* Allows you to wrap a Call function so that you may reuse some input values.
@@ -36,8 +36,8 @@ const determineFail = (actual, expected, path) => {
* @returns
*/
module.exports.partial = function (fun, input = {}) {
return async (remaining) => await fun({ ...remaining, ...input });
};
return async (remaining) => await fun({ ...remaining, ...input })
}
/**
* Allows you to assert a specific code result from a POST call.
@@ -51,9 +51,9 @@ module.exports.expectPostCallToReturn = async function (
payload: {},
}
) {
const res = await resolveCall(input.path, input.payload, header);
determineFail(res, input.code, input.path);
};
const res = await resolveCall(input.path, input.payload, header)
determineFail(res, input.code, input.path)
}
/**
* Allows you to assert a specific code result from multiple POST
@@ -76,10 +76,10 @@ module.exports.expectAllPostCallsToReturn = async function (
input.pathf(i),
input.payloadf ? input.payloadf(i) : {},
header
);
determineFail(res, input.code, input.pathf(i));
)
determineFail(res, input.code, input.pathf(i))
}
};
}
/**
* Allows you to retrieve a specific object the response
@@ -92,9 +92,9 @@ module.exports.expectAllPostCallsToReturn = async function (
* to the get parameter provided.
*/
module.exports.callGet = async function ({ path, get }) {
const api = useApi();
const res = await api.get(path, header);
const api = useApi()
const res = await api.get(path, header)
determineFail(res.status, 200, path);
return res?.data[get];
};
determineFail(res.status, 200, path)
return res?.data[get]
}

View File

@@ -108,6 +108,28 @@ module.exports = async (connection, data = {}) => {
tenPercent.rule = tenPercentRule
await manager.save(tenPercent)
const dUsageLimit = await manager.create(Discount, {
id: "test-discount-usage-limit",
code: "SPENT",
is_dynamic: false,
is_disabled: false,
usage_limit: 10,
usage_count: 10,
})
const drUsage = await manager.create(DiscountRule, {
id: "test-discount-rule-usage-limit",
description: "Created",
type: "fixed",
value: 10000,
allocation: "total",
})
dUsageLimit.rule = drUsage
dUsageLimit.regions = [r]
await manager.save(dUsageLimit)
const d = await manager.create(Discount, {
id: "test-discount",
code: "CREATED",

View File

@@ -4,10 +4,10 @@ const {
LineItem,
Fulfillment,
Return,
} = require("@medusajs/medusa");
} = require("@medusajs/medusa")
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const manager = connection.manager
let orderWithClaim = manager.create(Order, {
id: "order-with-claim",
@@ -40,9 +40,9 @@ module.exports = async (connection, data = {}) => {
],
items: [],
...data,
});
})
await manager.save(orderWithClaim);
await manager.save(orderWithClaim)
const li = manager.create(LineItem, {
id: "test-item-co-2",
@@ -54,9 +54,9 @@ module.exports = async (connection, data = {}) => {
quantity: 1,
variant_id: "test-variant",
order_id: orderWithClaim.id,
});
})
await manager.save(li);
await manager.save(li)
const li2 = manager.create(LineItem, {
id: "test-item-co-3",
@@ -68,9 +68,9 @@ module.exports = async (connection, data = {}) => {
quantity: 4,
variant_id: "test-variant",
order_id: orderWithClaim.id,
});
})
await manager.save(li2);
await manager.save(li2)
const claimWithFulfillment = manager.create(ClaimOrder, {
id: "claim-w-f",
@@ -79,23 +79,23 @@ module.exports = async (connection, data = {}) => {
fulfillment_status: "not_fulfilled",
order_id: "order-with-claim",
...data,
});
})
const ful1 = manager.create(Fulfillment, {
id: "fulfillment-co-1",
data: {},
provider_id: "test-ful",
});
})
const ful2 = manager.create(Fulfillment, {
id: "fulfillment-co-2",
data: {},
provider_id: "test-ful",
});
})
claimWithFulfillment.fulfillments = [ful1, ful2];
claimWithFulfillment.fulfillments = [ful1, ful2]
await manager.save(claimWithFulfillment);
await manager.save(claimWithFulfillment)
const claimWithReturn = manager.create(ClaimOrder, {
id: "claim-w-r",
@@ -104,9 +104,9 @@ module.exports = async (connection, data = {}) => {
fulfillment_status: "not_fulfilled",
order_id: "order-with-claim",
...data,
});
})
await manager.save(claimWithReturn);
await manager.save(claimWithReturn)
await manager.insert(Return, {
id: "return-id-2",
@@ -114,5 +114,5 @@ module.exports = async (connection, data = {}) => {
status: "requested",
refund_amount: 0,
data: {},
});
};
})
}

View File

@@ -14,35 +14,35 @@ const {
Discount,
DiscountRule,
Payment,
} = require("@medusajs/medusa");
} = require("@medusajs/medusa")
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const manager = connection.manager
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
})
await manager.insert(Product, {
id: "test-product",
title: "test product",
profile_id: defaultProfile.id,
options: [{ id: "test-option", title: "Size" }],
});
})
await manager.insert(Address, {
id: "oli-shipping",
first_name: "oli",
last_name: "test",
country_code: "us",
});
})
await manager.insert(Product, {
id: "test-product-2",
title: "test product 2",
profile_id: defaultProfile.id,
options: [{ id: "test-option-color", title: "Color" }],
});
})
await manager.insert(ProductVariant, {
id: "test-variant",
@@ -55,7 +55,7 @@ module.exports = async (connection, data = {}) => {
value: "Size",
},
],
});
})
await manager.insert(ProductVariant, {
id: "test-variant-2",
@@ -68,22 +68,22 @@ module.exports = async (connection, data = {}) => {
value: "Color",
},
],
});
})
const ma = manager.create(MoneyAmount, {
variant_id: "test-variant",
currency_code: "usd",
amount: 8000,
});
await manager.save(ma);
})
await manager.save(ma)
const ma2 = manager.create(MoneyAmount, {
variant_id: "test-variant-2",
currency_code: "usd",
amount: 10000,
});
})
await manager.save(ma2);
await manager.save(ma2)
await manager.insert(Region, {
id: "test-region",
@@ -96,7 +96,7 @@ module.exports = async (connection, data = {}) => {
is_installed: true,
},
],
});
})
await manager.insert(Region, {
id: "test-region-2",
@@ -109,7 +109,7 @@ module.exports = async (connection, data = {}) => {
is_installed: true,
},
],
});
})
await manager.insert(DiscountRule, {
id: "discount_rule_id",
@@ -117,7 +117,7 @@ module.exports = async (connection, data = {}) => {
value: 10,
allocation: "total",
type: "percentage",
});
})
const d = manager.create(Discount, {
id: "test-discount",
@@ -125,7 +125,7 @@ module.exports = async (connection, data = {}) => {
is_dynamic: false,
is_disabled: false,
rule_id: "discount_rule_id",
});
})
d.regions = [
{
@@ -134,27 +134,27 @@ module.exports = async (connection, data = {}) => {
currency_code: "usd",
tax_rate: 0,
},
];
]
await manager.save(d);
await manager.save(d)
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
);
)
await manager.query(
`UPDATE "country" SET region_id='test-region-2' WHERE iso_2 = 'de'`
);
)
await manager.insert(Customer, {
id: "oli-test",
email: "oli@test.dk",
});
})
await manager.insert(Customer, {
id: "lebron-james",
email: "lebron@james.com",
});
})
await manager.insert(ShippingOption, {
id: "test-option",
@@ -165,7 +165,7 @@ module.exports = async (connection, data = {}) => {
price_type: "flat_rate",
amount: 1000,
data: {},
});
})
await manager.insert(ShippingOption, {
id: "test-option-req",
@@ -176,14 +176,14 @@ module.exports = async (connection, data = {}) => {
price_type: "flat_rate",
amount: 1000,
data: {},
});
})
await manager.insert(ShippingOptionRequirement, {
id: "option-req",
shipping_option_id: "test-option-req",
type: "min_subtotal",
amount: 10,
});
})
const c = manager.create(Cart, {
id: "test-cart",
@@ -207,7 +207,7 @@ module.exports = async (connection, data = {}) => {
],
type: "draft_order",
metadata: { draft_order_id: "test-draft-order" },
});
})
const pay = manager.create(Payment, {
id: "test-payment",
@@ -216,13 +216,13 @@ module.exports = async (connection, data = {}) => {
amount_refunded: 0,
provider_id: "test-pay",
data: {},
});
})
await manager.save(pay);
await manager.save(pay)
c.payment = pay;
c.payment = pay
await manager.save(c);
await manager.save(c)
await manager.insert(PaymentSession, {
id: "test-session",
@@ -231,7 +231,7 @@ module.exports = async (connection, data = {}) => {
is_selected: true,
data: {},
status: "authorized",
});
})
const draftOrder = manager.create(DraftOrder, {
id: "test-draft-order",
@@ -255,7 +255,7 @@ module.exports = async (connection, data = {}) => {
region_id: "test-region",
discounts: [],
...data,
});
})
await manager.save(draftOrder);
};
await manager.save(draftOrder)
}

View File

@@ -12,21 +12,21 @@ const {
Payment,
Order,
Swap,
} = require("@medusajs/medusa");
} = require("@medusajs/medusa")
module.exports = async (connection, data = {}) => {
const manager = connection.manager;
const manager = connection.manager
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
})
await manager.insert(Product, {
id: "test-product",
title: "test product",
profile_id: defaultProfile.id,
options: [{ id: "test-option", title: "Size" }],
});
})
await manager.insert(ProductVariant, {
id: "test-variant",
@@ -39,7 +39,7 @@ module.exports = async (connection, data = {}) => {
value: "Size",
},
],
});
})
await manager.insert(ProductVariant, {
id: "test-variant-2",
@@ -52,37 +52,37 @@ module.exports = async (connection, data = {}) => {
value: "Large",
},
],
});
})
const ma2 = manager.create(MoneyAmount, {
variant_id: "test-variant-2",
currency_code: "usd",
amount: 8000,
});
await manager.save(ma2);
})
await manager.save(ma2)
const ma = manager.create(MoneyAmount, {
variant_id: "test-variant",
currency_code: "usd",
amount: 8000,
});
await manager.save(ma);
})
await manager.save(ma)
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
})
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
);
)
await manager.insert(Customer, {
id: "test-customer",
email: "test@email.com",
});
})
await manager.insert(ShippingOption, {
id: "test-option",
@@ -93,7 +93,7 @@ module.exports = async (connection, data = {}) => {
price_type: "flat_rate",
amount: 1000,
data: {},
});
})
await manager.insert(ShippingOption, {
id: "test-return-option",
@@ -105,7 +105,7 @@ module.exports = async (connection, data = {}) => {
price_type: "flat_rate",
amount: 1000,
is_return: true,
});
})
const order = manager.create(Order, {
id: "test-order",
@@ -157,9 +157,9 @@ module.exports = async (connection, data = {}) => {
],
items: [],
...data,
});
})
await manager.save(order);
await manager.save(order)
const li = manager.create(LineItem, {
id: "test-item",
@@ -172,9 +172,9 @@ module.exports = async (connection, data = {}) => {
quantity: 1,
variant_id: "test-variant",
order_id: "test-order",
});
})
await manager.save(li);
await manager.save(li)
await manager.insert(ShippingMethod, {
id: "test-method",
@@ -183,7 +183,7 @@ module.exports = async (connection, data = {}) => {
order_id: "test-order",
price: 1000,
data: {},
});
})
const orderTemplate = () => {
return {
@@ -195,8 +195,8 @@ module.exports = async (connection, data = {}) => {
currency_code: "usd",
tax_rate: 0,
...data,
};
};
}
}
const paymentTemplate = () => {
return {
@@ -204,8 +204,8 @@ module.exports = async (connection, data = {}) => {
currency_code: "usd",
provider_id: "test-pay",
data: {},
};
};
}
}
const orderWithClaim = manager.create(Order, {
id: "test-order-w-c",
@@ -219,59 +219,59 @@ module.exports = async (connection, data = {}) => {
},
],
...orderTemplate(),
});
})
await manager.save(orderWithClaim);
await manager.save(orderWithClaim)
await manager.insert(Payment, {
order_id: "test-order-w-c",
id: "o-pay1",
...paymentTemplate(),
});
})
const orderWithSwap = manager.create(Order, {
id: "test-order-w-s",
...orderTemplate(),
});
})
await manager.save(orderWithSwap);
await manager.save(orderWithSwap)
await manager.insert(Payment, {
order_id: "test-order-w-s",
id: "o-pay2",
...paymentTemplate(),
});
})
const swap1 = manager.create(Swap, {
id: "swap-1",
order_id: "test-order-w-s",
fulfillment_status: "not_fulfilled",
payment_status: "not_paid",
});
})
const pay1 = manager.create(Payment, {
id: "pay1",
...paymentTemplate(),
});
})
swap1.payment = pay1;
swap1.payment = pay1
const swap2 = manager.create(Swap, {
id: "swap-2",
order_id: "test-order-w-s",
fulfillment_status: "not_fulfilled",
payment_status: "not_paid",
});
})
const pay2 = manager.create(Payment, {
id: "pay2",
...paymentTemplate(),
});
})
swap2.payment = pay2;
swap2.payment = pay2
await manager.save(swap1);
await manager.save(swap2);
await manager.save(swap1)
await manager.save(swap2)
const orderWithFulfillment = manager.create(Order, {
id: "test-order-w-f",
@@ -288,15 +288,15 @@ module.exports = async (connection, data = {}) => {
},
],
...orderTemplate(),
});
})
await manager.save(orderWithFulfillment);
await manager.save(orderWithFulfillment)
await manager.insert(Payment, {
order_id: "test-order-w-f",
id: "o-pay3",
...paymentTemplate(),
});
})
const orderWithReturn = manager.create(Order, {
id: "test-order-w-r",
@@ -311,13 +311,13 @@ module.exports = async (connection, data = {}) => {
},
],
...orderTemplate(),
});
})
await manager.save(orderWithReturn);
await manager.save(orderWithReturn)
await manager.insert(Payment, {
order_id: "test-order-w-r",
id: "o-pay4",
...paymentTemplate(),
});
};
})
}

View File

@@ -25,6 +25,22 @@ module.exports = async (connection, data = {}) => {
await manager.save(coll)
const coll1 = manager.create(ProductCollection, {
id: "test-collection1",
handle: "test-collection1",
title: "Test collection 1",
})
await manager.save(coll1)
const coll2 = manager.create(ProductCollection, {
id: "test-collection2",
handle: "test-collection2",
title: "Test collection 2",
})
await manager.save(coll2)
const tag = manager.create(ProductTag, {
id: "tag1",
value: "123",
@@ -32,6 +48,20 @@ module.exports = async (connection, data = {}) => {
await manager.save(tag)
const tag3 = manager.create(ProductTag, {
id: "tag3",
value: "123",
})
await manager.save(tag3)
const tag4 = manager.create(ProductTag, {
id: "tag4",
value: "123",
})
await manager.save(tag4)
const type = manager.create(ProductType, {
id: "test-type",
value: "test-type",
@@ -199,4 +229,46 @@ module.exports = async (connection, data = {}) => {
})
await manager.save(variant5)
const product1 = manager.create(Product, {
id: "test-product_filtering_1",
handle: "test-product_filtering_1",
title: "Test product filtering 1",
profile_id: defaultProfile.id,
description: "test-product-description",
type: { id: "test-type", value: "test-type" },
collection_id: "test-collection1",
status: "proposed",
tags: [{ id: "tag3", value: "123" }],
})
await manager.save(product1)
const product2 = manager.create(Product, {
id: "test-product_filtering_2",
handle: "test-product_filtering_2",
title: "Test product filtering 2",
profile_id: defaultProfile.id,
description: "test-product-description",
type: { id: "test-type", value: "test-type" },
collection_id: "test-collection2",
status: "published",
tags: [{ id: "tag3", value: "123" }],
})
await manager.save(product2)
const product3 = manager.create(Product, {
id: "test-product_filtering_3",
handle: "test-product_filtering_3",
title: "Test product filtering 3",
profile_id: defaultProfile.id,
description: "test-product-description",
type: { id: "test-type", value: "test-type" },
collection_id: "test-collection1",
status: "draft",
tags: [{ id: "tag4", value: "1234" }],
})
await manager.save(product3)
}