fix: merge conflicts

This commit is contained in:
zakariaelas committed 2021-09-30 20:29:58 +01:00
commit 632ad17e3f
134 files changed
+5517 -628

No files matched your search

@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/discounts creates store session correctly 1`] = `
Object {
"billing_address_id": null,
"created_at": Any<String>,
"deleted_at": null,
"email": "test@testesen.dk",
"first_name": "test",
"has_account": true,
"id": Any<String>,
"last_name": "testesen",
"metadata": null,
"orders": Array [],
"phone": "12345678",
"updated_at": Any<String>,
}
`;
@@ -8,6 +8,14 @@ Object {
}
`;
exports[`/store/carts POST /store/carts/:id fails to complete swap cart with items inventory not/partially covered 1`] = `
Object {
"code": "insufficient_inventory",
"message": "Variant with id: test-variant-2 does not have the required inventory",
"type": "not_allowed",
}
`;
exports[`/store/carts POST /store/carts/:id returns early, if cart is already completed 1`] = `
Object {
"code": "cart_incompatible_state",
@@ -101,6 +101,7 @@ Object {
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"tags": Array [
Object {
@@ -58,6 +58,7 @@ Object {
"mid_code": null,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"thumbnail": null,
"title": "test product",
@@ -91,6 +92,7 @@ Object {
"parent_order_id": "test-order",
"swap_id": StringMatching /\\^swap_\\*/,
},
"payment_authorized_at": null,
"payment_id": null,
"region_id": "test-region",
"shipping_address_id": "test-shipping-address",
@@ -227,6 +229,7 @@ Object {
"mid_code": null,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"thumbnail": null,
"title": "test product",
@@ -260,6 +263,7 @@ Object {
"parent_order_id": "test-order",
"swap_id": StringMatching /\\^swap_\\*/,
},
"payment_authorized_at": null,
"payment_id": null,
"region_id": "test-region",
"shipping_address_id": "test-shipping-address",
@@ -0,0 +1,64 @@
const path = require("path")
const { Region, DiscountRule, Discount } = require("@medusajs/medusa")
const setupServer = require("../../../helpers/setup-server")
const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const adminSeeder = require("../../helpers/admin-seeder")
const { exportAllDeclaration } = require("@babel/types")
jest.setTimeout(30000)
describe("/admin/auth", () => {
let medusaProcess
let dbConnection
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
})
it("creates store session correctly", async () => {
const api = useApi()
await api
.post("/store/customers", {
email: "test@testesen.dk",
password: "secret_password",
first_name: "test",
last_name: "testesen",
phone: "12345678",
})
.catch((err) => {
console.log(err)
})
const response = await api
.post("/store/auth", {
email: "test@testesen.dk",
password: "secret_password",
})
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.customer.password_hash).toEqual(undefined)
expect(response.data.customer).toMatchSnapshot({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: "12345678",
email: "test@testesen.dk",
})
})
})
+165 -10
View File
@@ -27,8 +27,12 @@ describe("/store/carts", () => {
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
try {
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
} catch (error) {
console.log(error)
}
})
afterAll(async () => {
@@ -103,6 +107,7 @@ describe("/store/carts", () => {
beforeEach(async () => {
try {
await cartSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
@@ -113,7 +118,26 @@ describe("/store/carts", () => {
await doAfterEach()
})
// We were experiencing some issues when having created a cart in a region
// containing multiple countries. At this point, the cart does not have a shipping
// address. Therefore, on subsequent requests to update the cart, the server
// would throw a 500 due to missing shipping address id on insertion.
it("updates a cart, that does not have a shipping address", async () => {
const api = useApi()
const response = await api.post("/store/carts", {
region_id: "test-region-multiple",
})
const getRes = await api.post(`/store/carts/${response.data.cart.id}`, {
region_id: "test-region",
})
expect(getRes.status).toEqual(200)
})
it("fails on apply discount if limit has been reached", async () => {
expect.assertions(2)
const api = useApi()
try {
@@ -128,6 +152,62 @@ describe("/store/carts", () => {
}
})
it("fails to apply expired discount", async () => {
expect.assertions(2)
const api = useApi()
try {
await api.post("/store/carts/test-cart", {
discounts: [{ code: "EXP_DISC" }],
})
} catch (error) {
expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual("Discount is expired")
}
})
it("fails on discount before start day", async () => {
expect.assertions(2)
const api = useApi()
try {
await api.post("/store/carts/test-cart", {
discounts: [{ code: "PREM_DISC" }],
})
} catch (error) {
expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual("Discount is not valid yet")
}
})
it("fails on apply invalid dynamic discount", async () => {
const api = useApi()
try {
await api.post("/store/carts/test-cart", {
discounts: [{ code: "INV_DYN_DISC" }],
})
} catch (error) {
expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual("Discount is expired")
}
})
it("Applies dynamic discount to cart correctly", async () => {
const api = useApi()
const cart = await api.post(
"/store/carts/test-cart",
{
discounts: [{ code: "DYN_DISC" }],
},
{ withCredentials: true }
)
expect(cart.data.cart.shipping_total).toBe(1000)
expect(cart.status).toEqual(200)
})
it("updates cart customer id", async () => {
const api = useApi()
@@ -279,9 +359,82 @@ describe("/store/carts", () => {
expect(e.response.status).toBe(409)
}
//check to see if payment has been cancelled
//check to see if payment has been cancelled and cart is not completed
const res = await api.get(`/store/carts/test-cart-2`)
expect(res.data.cart.payment.canceled_at).not.toBe(null)
expect(res.data.cart.completed_at).toBe(null)
})
it("fails to complete swap cart with items inventory not/partially covered", async () => {
const manager = dbConnection.manager
const li = manager.create(LineItem, {
id: "test-item",
title: "Line Item",
description: "Line Item Desc",
thumbnail: "https://test.js/1234",
unit_price: 8000,
quantity: 99,
variant_id: "test-variant-2",
cart_id: "swap-cart",
})
await manager.save(li)
await manager.query(
"UPDATE swap SET cart_id='swap-cart' where id='test-swap'"
)
const api = useApi()
try {
await api.post(`/store/carts/swap-cart/complete-cart`)
} catch (e) {
expect(e.response.data).toMatchSnapshot({
code: "insufficient_inventory",
})
expect(e.response.status).toBe(409)
}
//check to see if payment has been cancelled and cart is not completed
const res = await api.get(`/store/carts/swap-cart`)
expect(res.data.cart.payment_authorized_at).toBe(null)
expect(res.data.cart.payment.canceled_at).not.toBe(null)
})
it("successfully completes swap cart with items inventory not/partially covered due to backorder flag", async () => {
const manager = dbConnection.manager
const li = manager.create(LineItem, {
id: "test-item",
title: "Line Item",
description: "Line Item Desc",
thumbnail: "https://test.js/1234",
unit_price: 8000,
quantity: 99,
variant_id: "test-variant-2",
cart_id: "swap-cart",
})
await manager.save(li)
await manager.query(
"UPDATE swap SET cart_id='swap-cart' where id='test-swap'"
)
await manager.query(
"UPDATE swap SET allow_backorder=true where id='test-swap'"
)
await manager.query("DELETE FROM payment where swap_id='test-swap'")
const api = useApi()
try {
await api.post(`/store/carts/swap-cart/complete-cart`)
} catch (error) {
console.log(error)
}
//check to see if payment is authorized and cart is completed
const res = await api.get(`/store/carts/swap-cart`)
expect(res.data.cart.payment_authorized_at).not.toBe(null)
expect(res.data.cart.completed_at).not.toBe(null)
})
})
@@ -377,13 +530,15 @@ describe("/store/carts", () => {
)
// Add a 10% discount to the cart
const cartWithGiftcard = await api.post(
"/store/carts/test-cart",
{
discounts: [{ code: "10PERCENT" }],
},
{ withCredentials: true }
)
const cartWithGiftcard = await api
.post(
"/store/carts/test-cart",
{
discounts: [{ code: "10PERCENT" }],
},
{ withCredentials: true }
)
.catch((err) => console.log(err))
// Ensure that the discount is only applied to the standard item
expect(cartWithGiftcard.data.cart.total).toBe(1900) // 1000 (giftcard) + 900 (standard item with 10% discount)
@@ -5,6 +5,7 @@ const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const productSeeder = require("../../helpers/product-seeder")
const adminSeeder = require("../../helpers/admin-seeder")
jest.setTimeout(30000)
describe("/store/products", () => {
let medusaProcess
@@ -26,6 +27,7 @@ describe("/store/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
@@ -261,5 +263,38 @@ describe("/store/products", () => {
expect(product.variants.some((variant) => variant.options)).toEqual(false)
})
it("lists all published products", async () => {
const api = useApi()
//update test-product status to published
await api
.post(
"/admin/products/test-product",
{
status: "published",
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => {
console.log(err)
})
const response = await api.get("/store/products")
expect(response.status).toEqual(200)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product",
status: "published",
}),
])
)
})
})
})
@@ -26,16 +26,35 @@ describe("/store/return-reasons", () => {
describe("GET /store/return-reasons", () => {
let rrId;
let rrId_1;
let rrId_2;
beforeEach(async () => {
try {
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
value: "wrong_size",
label: "Wrong size",
});
const result = await dbConnection.manager.save(created);
rrId = result.id;
const created_child = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
parent_return_reason_id: rrId
});
const result_child = await dbConnection.manager.save(created_child);
rrId_1 = result_child.id;
const created_2 = dbConnection.manager.create(ReturnReason, {
value: "too_big_1",
label: "Too Big 1",
});
const result_2 = await dbConnection.manager.save(created_2);
rrId_2 = result_2.id;
} catch (err) {
console.log(err);
throw err;
@@ -59,7 +78,15 @@ describe("/store/return-reasons", () => {
expect(response.data.return_reasons).toEqual([
expect.objectContaining({
id: rrId,
value: "too_big",
value: "wrong_size",
return_reason_children:[expect.objectContaining({
id: rrId_1,
value: "too_big",
}),]
}),
expect.objectContaining({
id: rrId_2,
value: "too_big_1",
}),
]);
});
@@ -8,6 +8,7 @@ const {
Product,
ProductVariant,
ShippingOption,
FulfillmentProvider,
LineItem,
Discount,
DiscountRule,
@@ -37,6 +38,8 @@ describe("/store/carts", () => {
describe("POST /store/returns", () => {
let rrId;
let rrId_child;
let rrResult;
beforeEach(async () => {
const manager = dbConnection.manager;
@@ -44,13 +47,17 @@ describe("/store/carts", () => {
`ALTER SEQUENCE order_display_id_seq RESTART WITH 111`
);
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
await manager.insert(Region, {
id: "region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
});
await manager.insert(Customer, {
id: "cus_1234",
email: "test@email.com",
@@ -98,10 +105,6 @@ describe("/store/carts", () => {
await manager.save(ord);
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
});
await manager.insert(Product, {
id: "test-product",
title: "test product",
@@ -147,12 +150,23 @@ describe("/store/carts", () => {
});
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
value: "wrong_size",
label: "Wrong Size",
});
const result = await dbConnection.manager.save(created);
rrResult = result
rrId = result.id;
const created_1 = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
parent_return_reason_id: rrId,
});
const result_1 = await dbConnection.manager.save(created_1);
rrId_child = result_1.id;
});
afterEach(async () => {
@@ -181,6 +195,59 @@ describe("/store/carts", () => {
expect(response.data.return.refund_amount).toEqual(8000);
});
it("failes to create a return with a reason category", async () => {
const api = useApi();
const response = await api
.post("/store/returns", {
order_id: "order_test",
items: [
{
reason_id: rrId,
note: "TOO small",
item_id: "test-item",
quantity: 1,
},
],
})
.catch((err) => {
return err.response;
});
expect(response.status).toEqual(400);
expect(response.data.message).toEqual('Cannot apply return reason category')
});
it("creates a return with reasons", async () => {
const api = useApi();
const response = await api
.post("/store/returns", {
order_id: "order_test",
items: [
{
reason_id: rrId_child,
note: "TOO small",
item_id: "test-item",
quantity: 1,
},
],
})
.catch((err) => {
console.log(err.response)
return err.response;
});
expect(response.status).toEqual(200);
expect(response.data.return.items).toEqual([
expect.objectContaining({
reason_id: rrId_child,
note: "TOO small",
}),
]);
});
it("creates a return with discount and non-discountable item", async () => {
const api = useApi();
@@ -234,32 +301,5 @@ describe("/store/carts", () => {
expect(response.data.return.refund_amount).toEqual(7000);
});
it("creates a return with reasons", async () => {
const api = useApi();
const response = await api
.post("/store/returns", {
order_id: "order_test",
items: [
{
reason_id: rrId,
note: "TOO small",
item_id: "test-item",
quantity: 1,
},
],
})
.catch((err) => {
return err.response;
});
expect(response.status).toEqual(200);
expect(response.data.return.items).toEqual([
expect.objectContaining({
reason_id: rrId,
note: "TOO small",
}),
]);
});
});
});