|
@@ -1,13 +1,34 @@
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * The demo instance seeds customer-looking contact details and a queue of
|
|
|
|
|
+ * scheduled messages, and its crons run every minute. These cover the guards
|
|
|
|
|
+ * that keep any of that from reaching a real inbox or handset.
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+vi.mock("@/lib/db", () => ({
|
|
|
|
|
+ db: {
|
|
|
|
|
+ scheduledMessage: {
|
|
|
|
|
+ findMany: vi.fn(() => {
|
|
|
|
|
+ throw new Error("the demo must not read the send queue at all");
|
|
|
|
|
+ }),
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
describe("demo mode blocks every outbound transport", () => {
|
|
describe("demo mode blocks every outbound transport", () => {
|
|
|
- beforeEach(() => { vi.resetModules(); process.env.DEMO_MODE = "true"; });
|
|
|
|
|
- afterEach(() => { delete process.env.DEMO_MODE; });
|
|
|
|
|
|
|
+ beforeEach(() => {
|
|
|
|
|
+ vi.resetModules();
|
|
|
|
|
+ process.env.DEMO_MODE = "true";
|
|
|
|
|
+ });
|
|
|
|
|
+ afterEach(() => {
|
|
|
|
|
+ delete process.env.DEMO_MODE;
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- it("refuses email, sms and telegram", async () => {
|
|
|
|
|
|
|
+ it("refuses email, SMS and Telegram", async () => {
|
|
|
const { assertOutboundAllowed } = await import("@/lib/demo");
|
|
const { assertOutboundAllowed } = await import("@/lib/demo");
|
|
|
- for (const ch of ["email", "sms", "telegram"] as const) {
|
|
|
|
|
- expect(() => assertOutboundAllowed(ch)).toThrow(/disabled on the demo/);
|
|
|
|
|
|
|
+ for (const channel of ["email", "sms", "telegram"] as const) {
|
|
|
|
|
+ expect(() => assertOutboundAllowed(channel)).toThrow(/disabled on the demo/);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -18,16 +39,17 @@ describe("demo mode blocks every outbound transport", () => {
|
|
|
expect(() => assertOutboundAllowed("email")).not.toThrow();
|
|
expect(() => assertOutboundAllowed("email")).not.toThrow();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it("unlocks the feature set for the demo org", async () => {
|
|
|
|
|
|
|
+ it("unlocks the plan features so the messaging pages render", async () => {
|
|
|
const { getFeatures } = await import("@/lib/features");
|
|
const { getFeatures } = await import("@/lib/features");
|
|
|
const features = await getFeatures("any-org");
|
|
const features = await getFeatures("any-org");
|
|
|
expect(features.sms).toBe(true);
|
|
expect(features.sms).toBe(true);
|
|
|
expect(features.telegram).toBe(true);
|
|
expect(features.telegram).toBe(true);
|
|
|
|
|
+ // Branding stays on: the demo is still advertising the product.
|
|
|
expect(features.brandingRemoved).toBe(false);
|
|
expect(features.brandingRemoved).toBe(false);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it("stops the scheduled-message cron before it reads the queue", async () => {
|
|
it("stops the scheduled-message cron before it reads the queue", async () => {
|
|
|
const { processDueMessages } = await import("@/lib/cron/scheduled-messages");
|
|
const { processDueMessages } = await import("@/lib/cron/scheduled-messages");
|
|
|
- expect(await processDueMessages()).toBe(0);
|
|
|
|
|
|
|
+ await expect(processDueMessages()).resolves.toBe(0);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|