|
| 1 | +import { |
| 2 | + onAlertPublished, |
| 3 | + crashlytics, |
| 4 | + billing, |
| 5 | + appDistribution, |
| 6 | + performance, |
| 7 | +} from "firebase-functions/v2/alerts"; |
| 8 | +import { expectEq, TestSuite } from "../testing"; |
| 9 | + |
| 10 | +export const alertstestsCrashlytics = onAlertPublished( |
| 11 | + { alertType: "crashlytics.newFatalIssue" }, |
| 12 | + (event) => { |
| 13 | + const testId = event.appId || "unknown"; |
| 14 | + |
| 15 | + return new TestSuite("alerts crashlytics onAlertPublished") |
| 16 | + .it("should have alert type", () => { |
| 17 | + expectEq(event.alertType, "crashlytics.newFatalIssue"); |
| 18 | + }) |
| 19 | + .it("should have app id", () => { |
| 20 | + expectEq(typeof event.appId, "string"); |
| 21 | + }) |
| 22 | + .run(testId, event); |
| 23 | + } |
| 24 | +); |
| 25 | + |
| 26 | +export const alertstestsBilling = onAlertPublished({ alertType: "billing.planUpdate" }, (event) => { |
| 27 | + const testId = event.appId || "unknown"; |
| 28 | + |
| 29 | + return new TestSuite("alerts billing onAlertPublished") |
| 30 | + .it("should have alert type", () => { |
| 31 | + expectEq(event.alertType, "billing.planUpdate"); |
| 32 | + }) |
| 33 | + .run(testId, event); |
| 34 | +}); |
| 35 | + |
| 36 | +export const alertstestsAppDistribution = appDistribution.onNewTesterIosDevicePublished((event) => { |
| 37 | + const testId = event.appId || "unknown"; |
| 38 | + |
| 39 | + return new TestSuite("alerts appDistribution onNewTesterIosDevicePublished") |
| 40 | + .it("should have app id", () => { |
| 41 | + expectEq(typeof event.appId, "string"); |
| 42 | + }) |
| 43 | + .it("should have tester name", () => { |
| 44 | + expectEq(typeof event.data.testerName, "string"); |
| 45 | + }) |
| 46 | + .it("should have device model", () => { |
| 47 | + expectEq(typeof event.data.testerDeviceModelName, "string"); |
| 48 | + }) |
| 49 | + .it("should have device identifier", () => { |
| 50 | + expectEq(typeof event.data.testerDeviceIdentifier, "string"); |
| 51 | + }) |
| 52 | + .run(testId, event); |
| 53 | +}); |
| 54 | + |
| 55 | +export const alertstestsPerformance = performance.onThresholdAlertPublished((event) => { |
| 56 | + const testId = event.appId || "unknown"; |
| 57 | + |
| 58 | + return new TestSuite("alerts performance onThresholdAlertPublished") |
| 59 | + .it("should have app id", () => { |
| 60 | + expectEq(typeof event.appId, "string"); |
| 61 | + }) |
| 62 | + .it("should have metric type", () => { |
| 63 | + expectEq(typeof event.data.metricType, "string"); |
| 64 | + }) |
| 65 | + .it("should have event name", () => { |
| 66 | + expectEq(typeof event.data.eventName, "string"); |
| 67 | + }) |
| 68 | + .it("should have threshold value", () => { |
| 69 | + expectEq(typeof event.data.thresholdValue, "number"); |
| 70 | + }) |
| 71 | + .it("should have threshold unit", () => { |
| 72 | + expectEq(typeof event.data.thresholdUnit, "string"); |
| 73 | + }) |
| 74 | + .run(testId, event); |
| 75 | +}); |
| 76 | + |
| 77 | +export const alertstestsCrashlyticsRegression = crashlytics.onRegressionAlertPublished((event) => { |
| 78 | + const testId = event.appId || "unknown"; |
| 79 | + |
| 80 | + return new TestSuite("alerts crashlytics onRegressionAlertPublished") |
| 81 | + .it("should have app id", () => { |
| 82 | + expectEq(typeof event.appId, "string"); |
| 83 | + }) |
| 84 | + .it("should have issue data", () => { |
| 85 | + expectEq(typeof event.data.issue, "object"); |
| 86 | + }) |
| 87 | + .it("should have issue id", () => { |
| 88 | + expectEq(typeof event.data.issue.id, "string"); |
| 89 | + }) |
| 90 | + .it("should have issue title", () => { |
| 91 | + expectEq(typeof event.data.issue.title, "string"); |
| 92 | + }) |
| 93 | + .run(testId, event); |
| 94 | +}); |
| 95 | + |
| 96 | +export const alertstestsBillingAutomated = billing.onPlanAutomatedUpdatePublished((event) => { |
| 97 | + const testId = event.appId || "unknown"; |
| 98 | + |
| 99 | + return new TestSuite("alerts billing onPlanAutomatedUpdatePublished") |
| 100 | + .it("should have billing plan", () => { |
| 101 | + expectEq(typeof event.data.billingPlan, "string"); |
| 102 | + }) |
| 103 | + .it("should have notification type", () => { |
| 104 | + expectEq(typeof event.data.notificationType, "string"); |
| 105 | + }) |
| 106 | + .run(testId, event); |
| 107 | +}); |
0 commit comments