152 lines
4.7 KiB
TypeScript
152 lines
4.7 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import {
|
|
appBannerSchema,
|
|
appSplashScreenSchema,
|
|
exploreTabSchema,
|
|
h5LinkUpdateSchema,
|
|
} from "@/features/app-config/schema";
|
|
import { FormValidationError, parseForm } from "@/shared/forms/validation";
|
|
|
|
const validBannerForm = {
|
|
bannerType: "h5",
|
|
countryCode: "",
|
|
coverUrl: "https://media.haiyihy.com/banner/home.png",
|
|
description: "",
|
|
displayScope: "home",
|
|
displayScopes: ["home"],
|
|
endsAtMs: "1800000000000",
|
|
param: "https://h5.example.com/activity",
|
|
platform: "android",
|
|
regionId: "",
|
|
roomSmallImageUrl: "",
|
|
sortOrder: "0",
|
|
startsAtMs: "1700000000000",
|
|
status: "active",
|
|
};
|
|
|
|
const validSplashScreenForm = {
|
|
countryCode: "",
|
|
coverUrl: "https://media.haiyihy.com/splash/launch.png",
|
|
description: "",
|
|
endsAtMs: "1800000000000",
|
|
param: "https://h5.example.com/splash",
|
|
platform: "ios",
|
|
regionId: "",
|
|
sortOrder: "0",
|
|
splashType: "h5",
|
|
startsAtMs: "1700000000000",
|
|
status: "active",
|
|
};
|
|
|
|
describe("app config form schema", () => {
|
|
test("validates dynamic h5 config item", () => {
|
|
const payload = parseForm(h5LinkUpdateSchema, {
|
|
key: "host-center.v2",
|
|
label: "Host Center",
|
|
url: "https://h5.example.com/host",
|
|
});
|
|
|
|
expect(payload.key).toBe("host-center.v2");
|
|
expect(payload.label).toBe("Host Center");
|
|
});
|
|
|
|
test("rejects dynamic h5 config key with spaces", () => {
|
|
expect(() =>
|
|
parseForm(h5LinkUpdateSchema, {
|
|
key: "host center",
|
|
label: "Host Center",
|
|
url: "https://h5.example.com/host",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
|
|
test("keeps banner display scope and delivery time fields", () => {
|
|
const payload = parseForm(appBannerSchema, validBannerForm);
|
|
|
|
expect(payload.displayScopes).toEqual(["home"]);
|
|
expect(payload.startsAtMs).toBe(1700000000000);
|
|
expect(payload.endsAtMs).toBe(1800000000000);
|
|
});
|
|
|
|
test("accepts multiple banner display scopes", () => {
|
|
const payload = parseForm(appBannerSchema, {
|
|
...validBannerForm,
|
|
displayScopes: ["home", "room", "recharge"],
|
|
roomSmallImageUrl: "https://media.haiyihy.com/banner/room-small.png",
|
|
});
|
|
|
|
expect(payload.displayScopes).toEqual(["home", "room", "recharge"]);
|
|
});
|
|
|
|
test("requires room small image for room banner", () => {
|
|
expect(() =>
|
|
parseForm(appBannerSchema, {
|
|
...validBannerForm,
|
|
displayScopes: ["home", "room"],
|
|
roomSmallImageUrl: "",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
|
|
test("rejects inverted banner delivery time range", () => {
|
|
expect(() =>
|
|
parseForm(appBannerSchema, {
|
|
...validBannerForm,
|
|
endsAtMs: "1700000000000",
|
|
startsAtMs: "1800000000000",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
|
|
test("keeps splash screen delivery and placement fields without display scope", () => {
|
|
const payload = parseForm(appSplashScreenSchema, validSplashScreenForm);
|
|
|
|
expect(payload.splashType).toBe("h5");
|
|
expect(payload.startsAtMs).toBe(1700000000000);
|
|
expect(payload.endsAtMs).toBe(1800000000000);
|
|
expect("displayScopes" in payload).toBe(false);
|
|
});
|
|
|
|
test("requires h5 link for splash screen h5 type", () => {
|
|
expect(() =>
|
|
parseForm(appSplashScreenSchema, {
|
|
...validSplashScreenForm,
|
|
param: "",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
|
|
test("rejects inverted splash screen delivery time range", () => {
|
|
expect(() =>
|
|
parseForm(appSplashScreenSchema, {
|
|
...validSplashScreenForm,
|
|
endsAtMs: "1700000000000",
|
|
startsAtMs: "1800000000000",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
|
|
test("validates explore tab h5 url and sort order", () => {
|
|
const payload = parseForm(exploreTabSchema, {
|
|
enabled: true,
|
|
h5Url: "https://h5.example.com/explore/live",
|
|
sortOrder: "3",
|
|
tab: "Live",
|
|
});
|
|
|
|
expect(payload.sortOrder).toBe(3);
|
|
expect(payload.h5Url).toBe("https://h5.example.com/explore/live");
|
|
});
|
|
|
|
test("rejects explore tab url with whitespace", () => {
|
|
expect(() =>
|
|
parseForm(exploreTabSchema, {
|
|
enabled: true,
|
|
h5Url: "https://h5.example.com/explore live",
|
|
sortOrder: "0",
|
|
tab: "Live",
|
|
}),
|
|
).toThrow(FormValidationError);
|
|
});
|
|
});
|