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:
Philip Korsholm
2022-04-25 14:55:33 +02:00
committed by GitHub
parent 7a1e394b9d
commit f7386bf4b3
3 changed files with 52 additions and 6 deletions
@@ -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 () => {
const api = useApi()
@@ -1,4 +1,4 @@
import { Type } from "class-transformer"
import { Transform, Type } from "class-transformer"
import {
IsArray,
IsBoolean,
@@ -18,6 +18,7 @@ import {
} from "."
import listAndCount from "../../../../controllers/products/admin-list-products"
import { validator } from "../../../../utils/validator"
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
/**
* @oas [get] /products
@@ -162,8 +163,8 @@ export class AdminGetProductsParams extends AdminGetProductsPaginationParams {
@IsBoolean()
@IsOptional()
@Type(() => Boolean)
is_giftcard?: string
@Transform(({ value }) => optionalBooleanMapper.get(value.toLowerCase()))
is_giftcard?: boolean
@IsString()
@IsOptional()
+4 -3
View File
@@ -1,4 +1,4 @@
import { Type } from "class-transformer"
import { Transform, Type } from "class-transformer"
import {
IsArray,
IsBoolean,
@@ -7,6 +7,7 @@ import {
IsString,
ValidateNested,
} from "class-validator"
import { optionalBooleanMapper } from "../utils/validators/is-boolean"
import { IsType } from "../utils/validators/is-type"
import { DateComparisonOperator, StringComparisonOperator } from "./common"
@@ -56,8 +57,8 @@ export class FilterableProductProps {
@IsBoolean()
@IsOptional()
@Type(() => Boolean)
is_giftcard?: string
@Transform(({ value }) => optionalBooleanMapper.get(value.toLowerCase()))
is_giftcard?: boolean
@IsString()
@IsOptional()