Skip to content

Commit

Permalink
test: validate price schema pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
IanKrieger committed Sep 27, 2023
1 parent 85313ca commit 90a70fb
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/validation/CampaignSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {
} from "graphql/types";
import { CampaignSchema } from "./CampaignSchema";
import { AdvertiserPriceFragment } from "graphql/advertiser.generated";
import { describe } from "vitest";

const prices: Omit<AdvertiserPriceFragment, "isDefault">[] = [
{
format: CampaignFormat.PushNotification,
price: "6",
billingType: BillingType.Cpm,
},
{
format: CampaignFormat.PushNotification,
price: ".15",
billingType: BillingType.Cpc,
},
];

const validCampaign = {
Expand Down Expand Up @@ -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"');
});
});

0 comments on commit 90a70fb

Please sign in to comment.