Files
aniplay-api/src/libs/fcm/verifyFcm.spec.ts

52 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { server } from "~/mocks";
import "~/mocks/gToken";
import { verifyFcmToken } from "./verifyFcmToken";
server.listen();
const FAKE_ADMIN_SDK_JSON = {
type: "service_account",
projectID: "test-26g38",
privateKeyID: "privateKeyId",
privateKey: "privateKey",
clientEmail: "test@test.com",
clientID: "clientId",
authURI: "https://accounts.google.com/o/oauth2/auth",
tokenURI: "https://oauth2.googleapis.com/token",
authProviderX509CERTURL: "https://www.googleapis.com/oauth2/v1/certs",
clientX509CERTURL:
"https://www.googleapis.com/robot/v1/metadata/x509/test%40test.com",
universeDomain: "aniplay.com",
};
describe("verifyFcmToken", () => {
it("valid token, returns true", async () => {
const token =
"7v8sy43aq0re4r8xe7rmr0cn1fsmh6phehnfla2pa73z899zmhyarivmkt4sj6pyv0py43u6p2sim6wz2vg9ypjp9rug1keoth7f6ll3gdvas4q020u3ah51r6bjgn51j6bd92ztmtof3ljpcm8q31njvndy65enm68";
const res = await verifyFcmToken(token, FAKE_ADMIN_SDK_JSON);
expect(res).toBeTrue();
});
it("invalid token, returns false", async () => {
const token = "abc123";
const res = await verifyFcmToken(token, FAKE_ADMIN_SDK_JSON);
expect(res).toBeFalse();
});
it("invalid ADMIN_SDK_JSON, returns false", async () => {
const token =
"7v8sy43aq0re4r8xe7rmr0cn1fsmh6phehnfla2pa73z899zmhyarivmkt4sj6pyv0py43u6p2sim6wz2vg9ypjp9rug1keoth7f6ll3gdvas4q020u3ah51r6bjgn51j6bd92ztmtof3ljpcm8q31njvndy65enm68";
const res = await verifyFcmToken(token, {
...FAKE_ADMIN_SDK_JSON,
clientEmail: "",
});
expect(res).toBeFalse();
});
});