integration tests passing
This commit is contained in:
@@ -74,7 +74,6 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.product).toEqual(
|
||||
expect.objectContaining({
|
||||
title: "Test product",
|
||||
@@ -523,8 +522,6 @@ describe("/admin/products", () => {
|
||||
it("successfully creates soft-deleted product variant", async () => {
|
||||
const api = useApi()
|
||||
|
||||
console.log("test")
|
||||
|
||||
const product = await api
|
||||
.get("/admin/products/test-product", {
|
||||
headers: {
|
||||
@@ -534,7 +531,6 @@ describe("/admin/products", () => {
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
console.log(product.data.product)
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/products/test-product/variants/test-variant", {
|
||||
|
||||
@@ -69,19 +69,16 @@ module.exports = async (connection, data = {}) => {
|
||||
],
|
||||
})
|
||||
|
||||
const productOption = manager.create(ProductOption, {
|
||||
id: "test-option",
|
||||
title: "test-option",
|
||||
})
|
||||
|
||||
await manager.save(productOption)
|
||||
|
||||
p.options = [productOption]
|
||||
|
||||
p.images = [image]
|
||||
|
||||
await manager.save(p)
|
||||
|
||||
await manager.save(ProductOption, {
|
||||
id: "test-option",
|
||||
title: "test-option",
|
||||
product_id: "test-product",
|
||||
})
|
||||
|
||||
const variant1 = await manager.create(ProductVariant, {
|
||||
id: "test-variant",
|
||||
inventory_quantity: 10,
|
||||
@@ -93,21 +90,27 @@ module.exports = async (connection, data = {}) => {
|
||||
barcode: "test-barcode",
|
||||
product_id: "test-product",
|
||||
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
|
||||
// options: [{ id: "test-variant-option", value: "Default variant" }],
|
||||
options: [
|
||||
{
|
||||
id: "test-variant-option",
|
||||
value: "Default variant",
|
||||
option_id: "test-option",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const variantOption_1 = manager.create(ProductOptionValue, {
|
||||
id: "test-option-variant1",
|
||||
option_id: "test-option",
|
||||
value: "test-option1",
|
||||
variant_id: "test-variant",
|
||||
// product_id: "test-product",
|
||||
})
|
||||
// const variantOption_1 = manager.create(ProductOptionValue, {
|
||||
// id: "test-option-variant1",
|
||||
// option_id: "test-option",
|
||||
// value: "test-option1",
|
||||
// variant_id: "test-variant",
|
||||
// // product_id: "test-product",
|
||||
// })
|
||||
|
||||
// variant1.options = [variantOption_1]
|
||||
|
||||
await manager.save(variant1)
|
||||
await manager.save(variantOption_1)
|
||||
// await manager.save(variantOption_1)
|
||||
|
||||
const variant2 = await manager.create(ProductVariant, {
|
||||
id: "test-variant_1",
|
||||
@@ -120,19 +123,25 @@ module.exports = async (connection, data = {}) => {
|
||||
barcode: "test-barcode 1",
|
||||
product_id: "test-product",
|
||||
prices: [{ id: "test-price1", currency_code: "usd", amount: 100 }],
|
||||
// options: [{ id: "test-variant-option-1", value: "Default variant 1" }],
|
||||
options: [
|
||||
{
|
||||
id: "test-variant-option-1",
|
||||
value: "Default variant 1",
|
||||
option_id: "test-option",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const variantOption_2 = manager.create(ProductOptionValue, {
|
||||
id: "test-option-variant2",
|
||||
option_id: "test-option",
|
||||
value: "test-option2",
|
||||
variant_id: "test-variant_1",
|
||||
// product_id: "test-product",
|
||||
})
|
||||
// const variantOption_2 = manager.create(ProductOptionValue, {
|
||||
// id: "test-option-variant2",
|
||||
// option_id: "test-option",
|
||||
// value: "test-option2",
|
||||
// variant_id: "test-variant_1",
|
||||
// // product_id: "test-product",
|
||||
// })
|
||||
await manager.save(variant2)
|
||||
|
||||
await manager.save(variantOption_2)
|
||||
// await manager.save(variantOption_2)
|
||||
|
||||
// variant2.options = [variantOption_2]
|
||||
|
||||
@@ -146,28 +155,34 @@ module.exports = async (connection, data = {}) => {
|
||||
upc: "test-upc2",
|
||||
product_id: "test-product",
|
||||
prices: [{ id: "test-price2", currency_code: "usd", amount: 100 }],
|
||||
// options: [{ id: "test-variant-option-2", value: "Default variant 2" }],
|
||||
options: [
|
||||
{
|
||||
id: "test-variant-option-2",
|
||||
value: "Default variant 2",
|
||||
option_id: "test-option",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const variantOption_3 = manager.create(ProductOptionValue, {
|
||||
id: "test-option-variant3",
|
||||
option_id: "test-option",
|
||||
value: "test-option3",
|
||||
variant_id: "test-variant_2",
|
||||
// product_id: "test-product",
|
||||
})
|
||||
// const variantOption_3 = manager.create(ProductOptionValue, {
|
||||
// id: "test-option-variant3",
|
||||
// option_id: "test-option",
|
||||
// value: "test-option3",
|
||||
// variant_id: "test-variant_2",
|
||||
// // product_id: "test-product",
|
||||
// })
|
||||
|
||||
await manager.save(variant3)
|
||||
await manager.save(variantOption_3)
|
||||
// await manager.save(variantOption_3)
|
||||
|
||||
// variant3.options = [variantOption_3]
|
||||
|
||||
const moneyAmount = await manager.create(MoneyAmount, {
|
||||
id: "money_amount",
|
||||
amount: 100,
|
||||
currency_code: "usd",
|
||||
variant_id: "test-variant",
|
||||
})
|
||||
// const moneyAmount = await manager.create(MoneyAmount, {
|
||||
// id: "money_amount",
|
||||
// amount: 100,
|
||||
// currency_code: "usd",
|
||||
// variant_id: "test-variant",
|
||||
// })
|
||||
|
||||
await manager.save(moneyAmount)
|
||||
// await manager.save(moneyAmount)
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ describe("POST /admin/products", () => {
|
||||
})
|
||||
|
||||
it("returns created product draft", () => {
|
||||
console.log(subject.body)
|
||||
expect(subject.body.product.id).toEqual(IdMap.getId("product1"))
|
||||
})
|
||||
|
||||
|
||||
@@ -327,10 +327,6 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.create({ ...value, profile_id: shippingProfile.id })
|
||||
|
||||
// console.log(variants)
|
||||
// console.log(value)
|
||||
// console.log(newProduct)
|
||||
|
||||
if (variants) {
|
||||
for (const [i, variant] of variants.entries()) variant.rank = i
|
||||
|
||||
@@ -356,18 +352,13 @@ export default async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
// console.log("got to after variants")
|
||||
|
||||
const product = await productService.retrieve(newProduct.id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
// console.log(product)
|
||||
|
||||
res.json({ product })
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
|
||||
export class productVariantRank1630868939283 implements MigrationInterface {
|
||||
name = 'productVariantRank1630868939283'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "product_variant" ADD "rank" integer NOT NULL`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "product_variant" DROP COLUMN "rank"`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
|
||||
export class productVariantOptionCascade1630870102483 implements MigrationInterface {
|
||||
name = 'productVariantOptionCascade1630870102483'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01"`);
|
||||
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE cascade ON UPDATE NO ACTION`);
|
||||
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "product_option_value" DROP CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01"`);
|
||||
await queryRunner.query(`ALTER TABLE "product_option_value" ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY ("variant_id") REFERENCES "product_variant"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,8 @@ export class ProductOptionValue {
|
||||
|
||||
@ManyToOne(
|
||||
() => ProductVariant,
|
||||
variant => variant.options
|
||||
variant => variant.options,
|
||||
{ onDelete: "cascade" }
|
||||
)
|
||||
@JoinColumn({ name: "variant_id" })
|
||||
variant: ProductVariant
|
||||
|
||||
@@ -43,7 +43,7 @@ export class ProductVariant {
|
||||
@OneToMany(
|
||||
() => MoneyAmount,
|
||||
ma => ma.variant,
|
||||
{ cascade: true, onDelete: "CASCADE" }
|
||||
{ cascade: ["remove"] }
|
||||
)
|
||||
prices: MoneyAmount[]
|
||||
|
||||
|
||||
@@ -185,10 +185,11 @@ class ProductService extends BaseService {
|
||||
)
|
||||
}
|
||||
|
||||
if (product.variants)
|
||||
if (product.variants) {
|
||||
product.variants.sort(
|
||||
(variant1, variant2) => variant1.rank - variant2.rank
|
||||
)
|
||||
}
|
||||
|
||||
return product
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user