Skip to content

Commit 8f92e1f

Browse files
committed
addressing comments
1 parent ec42a87 commit 8f92e1f

File tree

2 files changed

+19
-47
lines changed

2 files changed

+19
-47
lines changed

spec/v2/providers/alerts/alerts.spec.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { expect } from 'chai';
2-
import { CloudEvent, CloudFunction } from '../../../../src/v2/core';
32
import * as options from '../../../../src/v2/options';
43
import * as alerts from '../../../../src/v2/providers/alerts';
54
import { FULL_ENDPOINT, FULL_OPTIONS } from '../helpers';
65

76
const ALERT_TYPE = 'new-alert-type';
87
const APPID = '123456789';
98

10-
function getMockFunction(): CloudFunction<alerts.FirebaseAlertData<String>> {
11-
const func = (raw: CloudEvent<unknown>) => 42;
12-
func.run = (event: CloudEvent<alerts.FirebaseAlertData<String>>) => 42;
13-
func.__endpoint = {};
14-
return func;
15-
}
16-
179
describe('alerts', () => {
1810
describe('onAlertPublished', () => {
1911
it('should create the function without opts', () => {
@@ -75,11 +67,7 @@ describe('alerts', () => {
7567
});
7668

7769
it('should define the endpoint without appId and opts', () => {
78-
const func = getMockFunction();
79-
80-
func.__endpoint = alerts.getEndpointAnnotation({}, ALERT_TYPE);
81-
82-
expect(func.__endpoint).to.deep.equal({
70+
expect(alerts.getEndpointAnnotation({}, ALERT_TYPE)).to.deep.equal({
8371
platform: 'gcfv2',
8472
labels: {},
8573
eventTrigger: {
@@ -93,14 +81,9 @@ describe('alerts', () => {
9381
});
9482

9583
it('should define a complex endpoint without appId', () => {
96-
const func = getMockFunction();
97-
98-
func.__endpoint = alerts.getEndpointAnnotation(
99-
{ ...FULL_OPTIONS },
100-
ALERT_TYPE
101-
);
102-
103-
expect(func.__endpoint).to.deep.equal({
84+
expect(
85+
alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE)
86+
).to.deep.equal({
10487
...FULL_ENDPOINT,
10588
eventTrigger: {
10689
eventType: alerts.eventType,
@@ -113,15 +96,9 @@ describe('alerts', () => {
11396
});
11497

11598
it('should define a complex endpoint', () => {
116-
const func = getMockFunction();
117-
118-
func.__endpoint = alerts.getEndpointAnnotation(
119-
{ ...FULL_OPTIONS },
120-
ALERT_TYPE,
121-
APPID
122-
);
123-
124-
expect(func.__endpoint).to.deep.equal({
99+
expect(
100+
alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE, APPID)
101+
).to.deep.equal({
125102
...FULL_ENDPOINT,
126103
eventTrigger: {
127104
eventType: alerts.eventType,
@@ -144,15 +121,10 @@ describe('alerts', () => {
144121
region: 'us-west1',
145122
minInstances: 3,
146123
};
147-
const func = getMockFunction();
148-
149-
func.__endpoint = alerts.getEndpointAnnotation(
150-
specificOpts,
151-
ALERT_TYPE,
152-
APPID
153-
);
154124

155-
expect(func.__endpoint).to.deep.equal({
125+
expect(
126+
alerts.getEndpointAnnotation(specificOpts, ALERT_TYPE, APPID)
127+
).to.deep.equal({
156128
platform: 'gcfv2',
157129
labels: {},
158130
concurrency: 20,

src/v2/providers/alerts/alerts.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CloudEvent, CloudFunction } from '../../core';
33
import * as options from '../../options';
44

55
/**
6-
* The data object that is emitted from Firebase Alerts inside the CloudEvent
6+
* The CloudEvent data emitted by Firebase Alerts.
77
*/
88
export interface FirebaseAlertData<T = any> {
99
createTime: string;
@@ -16,7 +16,7 @@ interface WithAlertTypeAndApp {
1616
appId?: string;
1717
}
1818
/**
19-
* A custom CloudEvent for Firebase Alerts with custom extension attributes defined
19+
* A custom CloudEvent for Firebase Alerts (with custom extension attributes).
2020
*/
2121
export type AlertEvent<T> = CloudEvent<
2222
FirebaseAlertData<T>,
@@ -26,7 +26,7 @@ export type AlertEvent<T> = CloudEvent<
2626
/** @internal */
2727
export const eventType = 'firebase.firebasealerts.alerts.v1.published';
2828

29-
/** The underlying alert type of the Firebase Alerts provider */
29+
/** The underlying alert type of the Firebase Alerts provider. */
3030
export type AlertType =
3131
| 'crashlytics.newFatalIssue'
3232
| 'crashlytics.newNonfatalIssue'
@@ -40,17 +40,17 @@ export type AlertType =
4040
| string;
4141

4242
/**
43-
* Configuration for Firebase Alert functions
43+
* Configuration for Firebase Alert functions.
4444
*/
4545
export interface FirebaseAlertOptions extends options.EventHandlerOptions {
4646
alertType: AlertType;
4747
appId?: string;
4848
}
4949

5050
/**
51-
* Declares a function that can handle Firebase Alerts from CloudEvents
52-
* @param alertTypeOrOpts the alert type or Firebase Alert function configuration
53-
* @param handler a function that can handle the Firebase Alert inside a CloudEvent
51+
* Declares a function that can handle Firebase Alerts from CloudEvents.
52+
* @param alertTypeOrOpts the alert type or Firebase Alert function configuration.
53+
* @param handler a function that can handle the Firebase Alert inside a CloudEvent.
5454
*/
5555
export function onAlertPublished<T extends { ['@type']: string } = any>(
5656
alertTypeOrOpts: AlertType | FirebaseAlertOptions,
@@ -72,7 +72,7 @@ export function onAlertPublished<T extends { ['@type']: string } = any>(
7272

7373
/**
7474
* @internal
75-
* Helper function for getting the endpoint annotation used in alert handling functions
75+
* Helper function for getting the endpoint annotation used in alert handling functions.
7676
*/
7777
export function getEndpointAnnotation(
7878
opts: options.EventHandlerOptions,
@@ -105,7 +105,7 @@ export function getEndpointAnnotation(
105105

106106
/**
107107
* @internal
108-
* Helper function to parse the function opts, alert type, and appId
108+
* Helper function to parse the function opts, alert type, and appId.
109109
*/
110110
export function getOptsAndAlertTypeAndApp(
111111
alertTypeOrOpts: AlertType | FirebaseAlertOptions

0 commit comments

Comments
 (0)