From 90a70fb77e5496acf8bc7254c2aa4219a5d9f88d Mon Sep 17 00:00:00 2001 From: Ian Krieger Date: Wed, 27 Sep 2023 15:59:25 -0400 Subject: [PATCH] test: validate price schema pt 2 --- src/validation/CampaignSchema.test.ts | 42 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/validation/CampaignSchema.test.ts b/src/validation/CampaignSchema.test.ts index e2eb08ba7..cdd61ebf6 100644 --- a/src/validation/CampaignSchema.test.ts +++ b/src/validation/CampaignSchema.test.ts @@ -7,6 +7,7 @@ import { } from "graphql/types"; import { CampaignSchema } from "./CampaignSchema"; import { AdvertiserPriceFragment } from "graphql/advertiser.generated"; +import { describe } from "vitest"; const prices: Omit[] = [ { @@ -14,6 +15,11 @@ const prices: Omit[] = [ price: "6", billingType: BillingType.Cpm, }, + { + format: CampaignFormat.PushNotification, + price: ".15", + billingType: BillingType.Cpc, + }, ]; const validCampaign = { @@ -50,12 +56,36 @@ it("should fail if the campaign start date is in past", () => { ); }); -it("should fail if the campaign price is less than allowed price", () => { - const c = produce(validCampaign, (draft) => { - draft.price = "5"; +describe("pricing tests", () => { + it("should fail if the campaign price is less than allowed price", () => { + const c = produce(validCampaign, (draft) => { + draft.price = "5"; + }); + + expect(() => + CampaignSchema(prices).validateSync(c), + ).toThrowErrorMatchingInlineSnapshot('"CPM price must be 6 or higher"'); }); - expect(() => - CampaignSchema(prices).validateSync(c), - ).toThrowErrorMatchingInlineSnapshot('"CPM price must be 6 or higher"'); + it("should validate against default if none found", () => { + const c = produce(validCampaign, (draft) => { + (draft.format = CampaignFormat.NewsDisplayAd), (draft.price = "9"); + }); + + expect(() => + CampaignSchema(prices).validateSync(c), + ).toThrowErrorMatchingInlineSnapshot('"CPM price must be 10 or higher"'); + }); + + it("should validate against default if none found", () => { + const c = produce(validCampaign, (draft) => { + (draft.format = CampaignFormat.NewsDisplayAd), + (draft.billingType = "cpc"); + draft.price = ".1"; + }); + + expect(() => + CampaignSchema(prices).validateSync(c), + ).toThrowErrorMatchingInlineSnapshot('"CPC price must be 0.15 or higher"'); + }); });