Merge pull request #373 from medusajs/feat/product-variant-rank

Feat: Add product variant rank
This commit is contained in:
pKorsholm
2021-09-09 09:58:27 +02:00
committed by GitHub
15 changed files with 1229 additions and 153 deletions

View File

@@ -0,0 +1,382 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/products GET /admin/products returns a list of products with child entities 1`] = `
Array [
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description",
"discountable": true,
"handle": "test-product",
"height": null,
"hs_code": null,
"id": StringMatching /\\^test-\\*/,
"images": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"url": "test-image.png",
},
],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"product_id": StringMatching /\\^test-\\*/,
"title": "test-option",
"updated_at": Any<String>,
},
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": "test-barcode",
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean",
"height": null,
"hs_code": null,
"id": "test-variant",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku",
"title": "Test variant",
"upc": "test-upc",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean2",
"height": null,
"hs_code": null,
"id": "test-variant_2",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 2",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku2",
"title": "Test variant rank (2)",
"upc": "test-upc2",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": "test-barcode 1",
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean1",
"height": null,
"hs_code": null,
"id": "test-variant_1",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 1",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku1",
"title": "Test variant rank (1)",
"upc": "test-upc1",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description1",
"discountable": true,
"handle": "test-product1",
"height": null,
"hs_code": null,
"id": StringMatching /\\^test-\\*/,
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product1",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean4",
"height": null,
"hs_code": null,
"id": "test-variant_4",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 3",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku4",
"title": "Test variant rank (2)",
"upc": "test-upc4",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean3",
"height": null,
"hs_code": null,
"id": "test-variant_3",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 3",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku3",
"title": "Test variant rank (2)",
"upc": "test-upc3",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
]
`;

View File

@@ -1,49 +1,266 @@
const path = require("path");
const path = require("path")
const setupServer = require("../../../helpers/setup-server");
const { useApi } = require("../../../helpers/use-api");
const { initDb, useDb } = require("../../../helpers/use-db");
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 productSeeder = require("../../helpers/product-seeder");
const adminSeeder = require("../../helpers/admin-seeder")
const productSeeder = require("../../helpers/product-seeder")
jest.setTimeout(30000);
jest.setTimeout(30000)
describe("/admin/products", () => {
let medusaProcess;
let dbConnection;
let medusaProcess
let dbConnection
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."));
dbConnection = await initDb({ cwd });
medusaProcess = await setupServer({ cwd });
});
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd, verbose: true })
})
afterAll(async () => {
const db = useDb();
await db.shutdown();
const db = useDb()
await db.shutdown()
medusaProcess.kill();
});
medusaProcess.kill()
})
describe("GET /admin/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("returns a list of products with child entities", async () => {
const api = useApi()
const response = await api
.get("/admin/products", {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(response.data.products).toMatchSnapshot([
{
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
options: [
{
id: expect.stringMatching(/^test-*/),
product_id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
images: [
{
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
variants: [
{
id: "test-variant", //expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_2", //expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_1", // expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
],
tags: [
{
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
type: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
collection: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
options: [],
variants: [
{
id: "test-variant_4", //expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_3", //expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
],
tags: [
{
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
type: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
collection: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
])
})
})
describe("POST /admin/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection);
await adminSeeder(dbConnection);
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err);
throw err;
console.log(err)
throw err
}
});
})
afterEach(async () => {
const db = useDb();
await db.teardown();
});
const db = useDb()
await db.teardown()
})
it("creates a product", async () => {
const api = useApi();
const api = useApi()
const payload = {
title: "Test product",
@@ -61,7 +278,7 @@ describe("/admin/products", () => {
options: [{ value: "large" }, { value: "green" }],
},
],
};
}
const response = await api
.post("/admin/products", payload, {
@@ -70,11 +287,10 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
expect(response.status).toEqual(200);
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
title: "Test product",
@@ -133,11 +349,77 @@ describe("/admin/products", () => {
}),
],
})
);
});
)
})
it("Sets variant ranks when creating a product", async () => {
const api = useApi()
const payload = {
title: "Test product - 1",
description: "test-product-description 1",
type: { value: "test-type 1" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant 1",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
{
title: "Test variant 2",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
],
}
const creationResponse = await api
.post("/admin/products", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(creationResponse.status).toEqual(200)
const productId = creationResponse.data.product.id
const response = await api
.get(`/admin/products/${productId}`, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(response.data.product).toEqual(
expect.objectContaining({
title: "Test product - 1",
variants: [
expect.objectContaining({
title: "Test variant 1",
}),
expect.objectContaining({
title: "Test variant 2",
}),
],
})
)
})
it("creates a giftcard", async () => {
const api = useApi();
const api = useApi()
const payload = {
title: "Test Giftcard",
@@ -151,7 +433,7 @@ describe("/admin/products", () => {
options: [{ value: "100" }],
},
],
};
}
const response = await api
.post("/admin/products", payload, {
@@ -160,21 +442,21 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
title: "Test Giftcard",
discountable: false,
})
);
});
)
})
it("updates a product (update prices, tags, delete collection, delete type, replaces images)", async () => {
const api = useApi();
const api = useApi()
const payload = {
collection_id: null,
@@ -182,13 +464,19 @@ describe("/admin/products", () => {
variants: [
{
id: "test-variant",
prices: [{ currency_code: "usd", amount: 100, sale_amount: 75 }],
prices: [
{
currency_code: "usd",
amount: 100,
sale_amount: 75,
},
],
},
],
tags: [{ value: "123" }],
images: ["test-image-2.png"],
type: { value: "test-type-2" },
};
}
const response = await api
.post("/admin/products/test-product", payload, {
@@ -197,10 +485,10 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
@@ -231,15 +519,69 @@ describe("/admin/products", () => {
value: "test-type-2",
}),
})
);
});
)
})
it("updates a product (variant ordering)", async () => {
const api = useApi()
const payload = {
collection_id: null,
type: null,
variants: [
{
id: "test-variant",
},
{
id: "test-variant_1",
},
{
id: "test-variant_2",
},
],
}
const response = await api
.post("/admin/products/test-product", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
title: "Test product",
variants: [
expect.objectContaining({
id: "test-variant",
title: "Test variant",
}),
expect.objectContaining({
id: "test-variant_1",
title: "Test variant rank (1)",
}),
expect.objectContaining({
id: "test-variant_2",
title: "Test variant rank (2)",
}),
],
type: null,
collection: null,
})
)
})
it("add option", async () => {
const api = useApi();
const api = useApi()
const payload = {
title: "should_add",
};
}
const response = await api
.post("/admin/products/test-product/options", payload, {
@@ -248,41 +590,41 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
options: [
options: expect.arrayContaining([
expect.objectContaining({
title: "should_add",
product_id: "test-product",
}),
],
]),
})
);
});
});
)
})
})
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection);
await adminSeeder(dbConnection);
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err);
throw err;
console.log(err)
throw err
}
});
})
afterEach(async () => {
const db = useDb();
await db.teardown();
});
const db = useDb()
await db.teardown()
})
it("successfully deletes a product", async () => {
const api = useApi();
const api = useApi()
const response = await api
.delete("/admin/products/test-product", {
@@ -291,21 +633,21 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.status).toEqual(200)
expect(response.data).toEqual(
expect.objectContaining({
id: "test-product",
deleted: true,
})
);
});
)
})
it("successfully creates product with soft-deleted product handle", async () => {
const api = useApi();
const api = useApi()
// First we soft-delete the product
const response = await api
@@ -315,11 +657,11 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.data.id).toEqual("test-product");
expect(response.status).toEqual(200)
expect(response.data.id).toEqual("test-product")
// Lets try to create a product with same handle as deleted one
const payload = {
@@ -339,20 +681,20 @@ describe("/admin/products", () => {
options: [{ value: "large" }, { value: "green" }],
},
],
};
}
const res = await api.post("/admin/products", payload, {
headers: {
Authorization: "Bearer test_token",
},
});
})
expect(res.status).toEqual(200);
expect(res.data.product.handle).toEqual("test-product");
});
expect(res.status).toEqual(200)
expect(res.data.product.handle).toEqual("test-product")
})
it("successfully deletes product collection", async () => {
const api = useApi();
const api = useApi()
// First we soft-delete the product collection
const response = await api
@@ -362,15 +704,15 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.data.id).toEqual("test-collection");
});
expect(response.status).toEqual(200)
expect(response.data.id).toEqual("test-collection")
})
it("successfully creates soft-deleted product collection", async () => {
const api = useApi();
const api = useApi()
const response = await api
.delete("/admin/collections/test-collection", {
@@ -379,30 +721,40 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.data.id).toEqual("test-collection");
expect(response.status).toEqual(200)
expect(response.data.id).toEqual("test-collection")
// Lets try to create a product collection with same handle as deleted one
const payload = {
title: "Another test collection",
handle: "test-collection",
};
}
const res = await api.post("/admin/collections", payload, {
headers: {
Authorization: "Bearer test_token",
},
});
})
expect(res.status).toEqual(200);
expect(res.data.collection.handle).toEqual("test-collection");
});
expect(res.status).toEqual(200)
expect(res.data.collection.handle).toEqual("test-collection")
})
it("successfully creates soft-deleted product variant", async () => {
const api = useApi();
const api = useApi()
const product = await api
.get("/admin/products/test-product", {
headers: {
Authorization: "bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
const response = await api
.delete("/admin/products/test-product/variants/test-variant", {
@@ -411,11 +763,11 @@ describe("/admin/products", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.data.variant_id).toEqual("test-variant");
expect(response.status).toEqual(200)
expect(response.data.variant_id).toEqual("test-variant")
// Lets try to create a product collection with same handle as deleted one
const payload = {
@@ -430,19 +782,18 @@ describe("/admin/products", () => {
amount: 100,
},
],
};
options: [{ option_id: "test-option", value: "inserted value" }],
}
const res = await api.post(
"/admin/products/test-product/variants",
payload,
{
const res = await api
.post("/admin/products/test-product/variants", payload, {
headers: {
Authorization: "Bearer test_token",
},
}
);
})
.catch((err) => console.log(err))
expect(res.status).toEqual(200);
expect(res.status).toEqual(200)
expect(res.data.product.variants).toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -453,7 +804,7 @@ describe("/admin/products", () => {
barcode: "test-barcode",
}),
])
);
});
});
});
)
})
})
})