fix: Update is_giftcard type when filtering products (#1427)
* transform is_giftcard parameter and default to false * add test for non gift_cards * make default optional
This commit is contained in:
1 parent
7a1e394b9d
commit
f7386bf4b3
3 files changed
+52
-6
No files matched your search
@@ -509,6 +509,50 @@ describe("/admin/products", () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns a list of products not containing a giftcard in list", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: "Test Giftcard",
|
||||||
|
is_giftcard: true,
|
||||||
|
description: "test-giftcard-description",
|
||||||
|
options: [{ title: "Denominations" }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "Test variant",
|
||||||
|
prices: [{ currency_code: "usd", amount: 100 }],
|
||||||
|
options: [{ value: "100" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
await api
|
||||||
|
.post("/admin/products", payload, {
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.get("/admin/products?is_giftcard=false", {
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.data.products).toEqual(
|
||||||
|
expect.not.arrayContaining([
|
||||||
|
expect.objectContaining({ is_giftcard: true }),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("returns a list of products with child entities", async () => {
|
it("returns a list of products with child entities", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Type } from "class-transformer"
|
import { Transform, Type } from "class-transformer"
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from "."
|
} from "."
|
||||||
import listAndCount from "../../../../controllers/products/admin-list-products"
|
import listAndCount from "../../../../controllers/products/admin-list-products"
|
||||||
import { validator } from "../../../../utils/validator"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /products
|
* @oas [get] /products
|
||||||
@@ -162,8 +163,8 @@ export class AdminGetProductsParams extends AdminGetProductsPaginationParams {
|
|||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Type(() => Boolean)
|
@Transform(({ value }) => optionalBooleanMapper.get(value.toLowerCase()))
|
||||||
is_giftcard?: string
|
is_giftcard?: boolean
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Type } from "class-transformer"
|
import { Transform, Type } from "class-transformer"
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
IsString,
|
IsString,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from "class-validator"
|
} from "class-validator"
|
||||||
|
import { optionalBooleanMapper } from "../utils/validators/is-boolean"
|
||||||
import { IsType } from "../utils/validators/is-type"
|
import { IsType } from "../utils/validators/is-type"
|
||||||
import { DateComparisonOperator, StringComparisonOperator } from "./common"
|
import { DateComparisonOperator, StringComparisonOperator } from "./common"
|
||||||
|
|
||||||
@@ -56,8 +57,8 @@ export class FilterableProductProps {
|
|||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Type(() => Boolean)
|
@Transform(({ value }) => optionalBooleanMapper.get(value.toLowerCase()))
|
||||||
is_giftcard?: string
|
is_giftcard?: boolean
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
Reference in new issue
Block a user