126 lines
3.4 KiB
TypeScript
126 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { ROUTES } from "@/router/routes";
|
|
|
|
import {
|
|
resolveExternalEntryPromotionType,
|
|
resolveExternalEntryTarget,
|
|
shouldBindExternalFacebookIdentity,
|
|
} from "../external_entry";
|
|
|
|
describe("external entry navigation", () => {
|
|
it("defaults to chat", () => {
|
|
expect(resolveExternalEntryTarget({})).toBe(ROUTES.chat);
|
|
});
|
|
|
|
it("resolves only canonical targets", () => {
|
|
expect(resolveExternalEntryTarget({ target: "chat" })).toBe(ROUTES.chat);
|
|
expect(resolveExternalEntryTarget({ target: "tip" })).toBe(ROUTES.tip);
|
|
expect(resolveExternalEntryTarget({ target: "private-room" })).toBe(
|
|
ROUTES.privateRoom,
|
|
);
|
|
});
|
|
|
|
it("rejects removed aliases and unsupported targets", () => {
|
|
expect(resolveExternalEntryTarget({ target: "tips" })).toBe(ROUTES.chat);
|
|
expect(resolveExternalEntryTarget({ target: "coffee" })).toBe(ROUTES.chat);
|
|
expect(resolveExternalEntryTarget({ target: "private_room" })).toBe(
|
|
ROUTES.chat,
|
|
);
|
|
expect(resolveExternalEntryTarget({ target: "/tip" })).toBe(ROUTES.chat);
|
|
expect(resolveExternalEntryTarget({ target: "sidebar" })).toBe(ROUTES.chat);
|
|
});
|
|
});
|
|
|
|
describe("external entry facebook identity binding", () => {
|
|
it("binds only a ready real-user session with an external id", () => {
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "email",
|
|
asid: "asid-1",
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "google",
|
|
asid: "asid-1",
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "facebook",
|
|
psid: "psid-1",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("skips guest, notLoggedIn, loading, and empty identity inputs", () => {
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "guest",
|
|
asid: "asid-1",
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "notLoggedIn",
|
|
psid: "psid-1",
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: true,
|
|
loginStatus: "google",
|
|
asid: "asid-1",
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldBindExternalFacebookIdentity({
|
|
hasInitialized: true,
|
|
isLoading: false,
|
|
loginStatus: "google",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("external entry promotion", () => {
|
|
it("accepts only explicit promotion mode and supported message types", () => {
|
|
expect(
|
|
resolveExternalEntryPromotionType({
|
|
mode: "promotion",
|
|
promotionType: "voice",
|
|
}),
|
|
).toBe("voice");
|
|
expect(
|
|
resolveExternalEntryPromotionType({
|
|
mode: "promotion",
|
|
promotionType: "image",
|
|
}),
|
|
).toBe("image");
|
|
expect(
|
|
resolveExternalEntryPromotionType({
|
|
mode: "normal",
|
|
promotionType: "private",
|
|
}),
|
|
).toBeNull();
|
|
expect(
|
|
resolveExternalEntryPromotionType({
|
|
mode: "promotion",
|
|
promotionType: "video",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|