|
| 1 | +import type * as AlertsGate from "~/v3/canUseAlertsList.server"; |
1 | 2 | import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 |
|
3 | 4 | vi.setConfig({ testTimeout: 30_000 }); |
@@ -35,8 +36,11 @@ vi.mock("~/services/routeBuilders/dashboardBuilder", () => { |
35 | 36 | vi.mock("~/services/session.server", () => ({ requireUserId: async () => "user_1" })); |
36 | 37 |
|
37 | 38 | vi.mock("~/db.server", () => ({ |
38 | | - prisma: { organizationIntegration: { findFirst: async () => ({ id: "int_1" }) } }, |
39 | | - $replica: {}, |
| 39 | + prisma: { |
| 40 | + organizationIntegration: { findFirst: async () => ({ id: "int_1" }) }, |
| 41 | + user: { findFirst: async () => ({ admin: true }) }, |
| 42 | + }, |
| 43 | + $replica: { organization: { findFirst: async () => ({ featureFlags: {} }) } }, |
40 | 44 | })); |
41 | 45 |
|
42 | 46 | vi.mock("~/models/project.server", async (importOriginal) => ({ |
@@ -132,6 +136,11 @@ vi.mock("~/v3/canUseAlertsList.server", async () => { |
132 | 136 | }; |
133 | 137 | }); |
134 | 138 |
|
| 139 | +vi.mock("~/v3/featureFlags.server", async (importOriginal) => ({ |
| 140 | + ...(await importOriginal<object>()), |
| 141 | + makeFlag: () => async (opts: { defaultValue: unknown }) => opts.defaultValue, |
| 142 | +})); |
| 143 | + |
135 | 144 | const P = "_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam"; |
136 | 145 | const params = { organizationSlug: "o", projectParam: "p", envParam: "dev", channelId: "c" }; |
137 | 146 | const request = (method = "GET") => new Request("http://localhost/x", { method }); |
@@ -189,6 +198,15 @@ describe("new alerts surfaces when alertsEnabled is off", () => { |
189 | 198 | }); |
190 | 199 | }); |
191 | 200 |
|
| 201 | +describe("admin preview when ALERTS_ENABLED is unset", () => { |
| 202 | + it("the real gate redirects an admin to the old alerts page", async () => { |
| 203 | + const real = await vi.importActual<typeof AlertsGate>("~/v3/canUseAlertsList.server"); |
| 204 | + const res = await thrown(() => real.requireAlertsEnabledOrRedirect("user_1", params)); |
| 205 | + expect(res?.status).toBe(302); |
| 206 | + expect(await real.canUseAlertsList({ orgFeatureFlags: {}, user: { admin: true } })).toBe(false); |
| 207 | + }); |
| 208 | +}); |
| 209 | + |
192 | 210 | describe("preview-series authorization", () => { |
193 | 211 | it("responds 403 to a member denied read:alerts", async () => { |
194 | 212 | STATE.enabled = true; |
|
0 commit comments