integration tests passing
This commit is contained in:
@@ -74,7 +74,6 @@ describe("/admin/products", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
expect(response.data.product).toEqual(
|
expect(response.data.product).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
title: "Test product",
|
title: "Test product",
|
||||||
@@ -523,8 +522,6 @@ describe("/admin/products", () => {
|
|||||||
it("successfully creates soft-deleted product variant", async () => {
|
it("successfully creates soft-deleted product variant", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
console.log("test")
|
|
||||||
|
|
||||||
const product = await api
|
const product = await api
|
||||||
.get("/admin/products/test-product", {
|
.get("/admin/products/test-product", {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -534,7 +531,6 @@ describe("/admin/products", () => {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
console.log(product.data.product)
|
|
||||||
|
|
||||||
const response = await api
|
const response = await api
|
||||||
.delete("/admin/products/test-product/variants/test-variant", {
|
.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]
|
p.images = [image]
|
||||||
|
|
||||||
await manager.save(p)
|
await manager.save(p)
|
||||||
|
|
||||||
|
await manager.save(ProductOption, {
|
||||||
|
id: "test-option",
|
||||||
|
title: "test-option",
|
||||||
|
product_id: "test-product",
|
||||||
|
})
|
||||||
|
|
||||||
const variant1 = await manager.create(ProductVariant, {
|
const variant1 = await manager.create(ProductVariant, {
|
||||||
id: "test-variant",
|
id: "test-variant",
|
||||||
inventory_quantity: 10,
|
inventory_quantity: 10,
|
||||||
@@ -93,21 +90,27 @@ module.exports = async (connection, data = {}) => {
|
|||||||
barcode: "test-barcode",
|
barcode: "test-barcode",
|
||||||
product_id: "test-product",
|
product_id: "test-product",
|
||||||
prices: [{ id: "test-price", currency_code: "usd", amount: 100 }],
|
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, {
|
// const variantOption_1 = manager.create(ProductOptionValue, {
|
||||||
id: "test-option-variant1",
|
// id: "test-option-variant1",
|
||||||
option_id: "test-option",
|
// option_id: "test-option",
|
||||||
value: "test-option1",
|
// value: "test-option1",
|
||||||
variant_id: "test-variant",
|
// variant_id: "test-variant",
|
||||||
// product_id: "test-product",
|
// // product_id: "test-product",
|
||||||
})
|
// })
|
||||||
|
|
||||||
// variant1.options = [variantOption_1]
|
// variant1.options = [variantOption_1]
|
||||||
|
|
||||||
await manager.save(variant1)
|
await manager.save(variant1)
|
||||||
await manager.save(variantOption_1)
|
// await manager.save(variantOption_1)
|
||||||
|
|
||||||
const variant2 = await manager.create(ProductVariant, {
|
const variant2 = await manager.create(ProductVariant, {
|
||||||
id: "test-variant_1",
|
id: "test-variant_1",
|
||||||
@@ -120,19 +123,25 @@ module.exports = async (connection, data = {}) => {
|
|||||||
barcode: "test-barcode 1",
|
barcode: "test-barcode 1",
|
||||||
product_id: "test-product",
|
product_id: "test-product",
|
||||||
prices: [{ id: "test-price1", currency_code: "usd", amount: 100 }],
|
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, {
|
// const variantOption_2 = manager.create(ProductOptionValue, {
|
||||||
id: "test-option-variant2",
|
// id: "test-option-variant2",
|
||||||
option_id: "test-option",
|
// option_id: "test-option",
|
||||||
value: "test-option2",
|
// value: "test-option2",
|
||||||
variant_id: "test-variant_1",
|
// variant_id: "test-variant_1",
|
||||||
// product_id: "test-product",
|
// // product_id: "test-product",
|
||||||
})
|
// })
|
||||||
await manager.save(variant2)
|
await manager.save(variant2)
|
||||||
|
|
||||||
await manager.save(variantOption_2)
|
// await manager.save(variantOption_2)
|
||||||
|
|
||||||
// variant2.options = [variantOption_2]
|
// variant2.options = [variantOption_2]
|
||||||
|
|
||||||
@@ -146,28 +155,34 @@ module.exports = async (connection, data = {}) => {
|
|||||||
upc: "test-upc2",
|
upc: "test-upc2",
|
||||||
product_id: "test-product",
|
product_id: "test-product",
|
||||||
prices: [{ id: "test-price2", currency_code: "usd", amount: 100 }],
|
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, {
|
// const variantOption_3 = manager.create(ProductOptionValue, {
|
||||||
id: "test-option-variant3",
|
// id: "test-option-variant3",
|
||||||
option_id: "test-option",
|
// option_id: "test-option",
|
||||||
value: "test-option3",
|
// value: "test-option3",
|
||||||
variant_id: "test-variant_2",
|
// variant_id: "test-variant_2",
|
||||||
// product_id: "test-product",
|
// // product_id: "test-product",
|
||||||
})
|
// })
|
||||||
|
|
||||||
await manager.save(variant3)
|
await manager.save(variant3)
|
||||||
await manager.save(variantOption_3)
|
// await manager.save(variantOption_3)
|
||||||
|
|
||||||
// variant3.options = [variantOption_3]
|
// variant3.options = [variantOption_3]
|
||||||
|
|
||||||
const moneyAmount = await manager.create(MoneyAmount, {
|
// const moneyAmount = await manager.create(MoneyAmount, {
|
||||||
id: "money_amount",
|
// id: "money_amount",
|
||||||
amount: 100,
|
// amount: 100,
|
||||||
currency_code: "usd",
|
// currency_code: "usd",
|
||||||
variant_id: "test-variant",
|
// 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", () => {
|
it("returns created product draft", () => {
|
||||||
console.log(subject.body)
|
|
||||||
expect(subject.body.product.id).toEqual(IdMap.getId("product1"))
|
expect(subject.body.product.id).toEqual(IdMap.getId("product1"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -327,10 +327,6 @@ export default async (req, res) => {
|
|||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.create({ ...value, profile_id: shippingProfile.id })
|
.create({ ...value, profile_id: shippingProfile.id })
|
||||||
|
|
||||||
// console.log(variants)
|
|
||||||
// console.log(value)
|
|
||||||
// console.log(newProduct)
|
|
||||||
|
|
||||||
if (variants) {
|
if (variants) {
|
||||||
for (const [i, variant] of variants.entries()) variant.rank = i
|
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, {
|
const product = await productService.retrieve(newProduct.id, {
|
||||||
select: defaultFields,
|
select: defaultFields,
|
||||||
relations: defaultRelations,
|
relations: defaultRelations,
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log(product)
|
|
||||||
|
|
||||||
res.json({ product })
|
res.json({ product })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// console.log(err)
|
|
||||||
throw 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(
|
@ManyToOne(
|
||||||
() => ProductVariant,
|
() => ProductVariant,
|
||||||
variant => variant.options
|
variant => variant.options,
|
||||||
|
{ onDelete: "cascade" }
|
||||||
)
|
)
|
||||||
@JoinColumn({ name: "variant_id" })
|
@JoinColumn({ name: "variant_id" })
|
||||||
variant: ProductVariant
|
variant: ProductVariant
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class ProductVariant {
|
|||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => MoneyAmount,
|
() => MoneyAmount,
|
||||||
ma => ma.variant,
|
ma => ma.variant,
|
||||||
{ cascade: true, onDelete: "CASCADE" }
|
{ cascade: ["remove"] }
|
||||||
)
|
)
|
||||||
prices: MoneyAmount[]
|
prices: MoneyAmount[]
|
||||||
|
|
||||||
|
|||||||
@@ -185,10 +185,11 @@ class ProductService extends BaseService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.variants)
|
if (product.variants) {
|
||||||
product.variants.sort(
|
product.variants.sort(
|
||||||
(variant1, variant2) => variant1.rank - variant2.rank
|
(variant1, variant2) => variant1.rank - variant2.rank
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return product
|
return product
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user