Initial Commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import {
|
||||
ApnConfigSchema,
|
||||
NotificationsPluginOptionsSchema,
|
||||
} from "./options.js";
|
||||
|
||||
describe("NotificationsPluginOptionsSchema", () => {
|
||||
it("applies defaults on empty input", { timeout: 5000 }, () => {
|
||||
const v = NotificationsPluginOptionsSchema.parse({});
|
||||
expect(v.basePath).toBe("/notifications");
|
||||
expect(v.pushBasePath).toBe("/push");
|
||||
expect(v.enablePush).toBe(false);
|
||||
expect(v.autoCleanOldDays).toBe(30);
|
||||
expect(v.maxBulkRecipients).toBe(1000);
|
||||
expect(v.enableDispatcher).toBe(false);
|
||||
expect(v.defaultChannel).toBe("apn");
|
||||
expect(v.deliveryTenantId).toBe("default");
|
||||
});
|
||||
|
||||
it("accepts enableDispatcher + defaultChannel + tenantId", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const v = NotificationsPluginOptionsSchema.parse({
|
||||
enableDispatcher: true,
|
||||
defaultChannel: "email",
|
||||
deliveryTenantId: "tenant-a",
|
||||
});
|
||||
expect(v.enableDispatcher).toBe(true);
|
||||
expect(v.defaultChannel).toBe("email");
|
||||
expect(v.deliveryTenantId).toBe("tenant-a");
|
||||
});
|
||||
|
||||
it("rejects unknown defaultChannel literal", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
NotificationsPluginOptionsSchema.parse({
|
||||
defaultChannel: "carrier-pigeon",
|
||||
} as never)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects empty deliveryTenantId", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
NotificationsPluginOptionsSchema.parse({ deliveryTenantId: "" })
|
||||
).toThrow();
|
||||
});
|
||||
it("rejects empty basePath", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
NotificationsPluginOptionsSchema.parse({ basePath: "" })
|
||||
).toThrow();
|
||||
});
|
||||
it("rejects negative autoCleanOldDays", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
NotificationsPluginOptionsSchema.parse({ autoCleanOldDays: -1 })
|
||||
).toThrow();
|
||||
});
|
||||
it("rejects maxBulkRecipients > 10000", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
NotificationsPluginOptionsSchema.parse({
|
||||
maxBulkRecipients: 20000,
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
it("accepts a valid APN config", { timeout: 5000 }, () => {
|
||||
const v = NotificationsPluginOptionsSchema.parse({
|
||||
enablePush: true,
|
||||
apn: {
|
||||
token: { key: "k", keyId: "i", teamId: "t" },
|
||||
production: true,
|
||||
},
|
||||
});
|
||||
expect(v.apn?.production).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ApnConfigSchema", () => {
|
||||
it("defaults production to false", { timeout: 5000 }, () => {
|
||||
const v = ApnConfigSchema.parse({});
|
||||
expect(v.production).toBe(false);
|
||||
});
|
||||
it("rejects partial token (missing teamId)", { timeout: 5000 }, () => {
|
||||
expect(() =>
|
||||
ApnConfigSchema.parse({
|
||||
token: { key: "k", keyId: "i", teamId: "" },
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user