-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* breaking out general interface * cleaning up exports * removing comments & references to specific interfaces * format * jsdoc comments * address pr comments * added param comment * addressing comments * Specific interface for provider enhancement (1/3) (#1021) * adding in app distro changes * removing comments & addings package refs * jsdoc comments * fix comments * adding periods to doc strings * fix wording * adding import/export statement * Specific interface for provider enhancement (2/3) (#1022) * adding in billing changes * removing comments & adding package refs * jsdoc comments * addressing pr comments * change handler doc string * changing to BillingEventHandler type * remove BillingEventHandler type * Specific interface for provider enhancement (3/3) (#1023) * adding in crashlytics changes * comments & adding package refs * address comments and make doc strings better * add opts.retry to event trigger
- Loading branch information
1 parent
7645a69
commit 8e21f77
Showing
18 changed files
with
1,839 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- Parallelizes network calls that occur when validating authorization for onCall handlers. | ||
- Adds new regions to V2 API | ||
- Fixes bug where the emulator crashed when given app without an `options` property. | ||
- Adds new alerting providers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { expect } from 'chai'; | ||
import * as options from '../../../../src/v2/options'; | ||
import * as alerts from '../../../../src/v2/providers/alerts'; | ||
import { FULL_ENDPOINT, FULL_OPTIONS } from '../helpers'; | ||
|
||
const ALERT_TYPE = 'new-alert-type'; | ||
const APPID = '123456789'; | ||
|
||
describe('alerts', () => { | ||
describe('onAlertPublished', () => { | ||
it('should create the function without opts', () => { | ||
const result = alerts.onAlertPublished(ALERT_TYPE, () => 42); | ||
|
||
expect(result.__endpoint).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create the function with opts', () => { | ||
const result = alerts.onAlertPublished( | ||
{ | ||
...FULL_OPTIONS, | ||
alertType: ALERT_TYPE, | ||
appId: APPID, | ||
}, | ||
() => 42 | ||
); | ||
|
||
expect(result.__endpoint).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
appId: APPID, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should have a .run method', () => { | ||
const func = alerts.onAlertPublished(ALERT_TYPE, (event) => event); | ||
|
||
const res = func.run('input' as any); | ||
|
||
expect(res).to.equal('input'); | ||
}); | ||
}); | ||
|
||
describe('getEndpointAnnotation', () => { | ||
beforeEach(() => { | ||
process.env.GCLOUD_PROJECT = 'aProject'; | ||
}); | ||
|
||
afterEach(() => { | ||
options.setGlobalOptions({}); | ||
delete process.env.GCLOUD_PROJECT; | ||
}); | ||
|
||
it('should define the endpoint without appId and opts', () => { | ||
expect(alerts.getEndpointAnnotation({}, ALERT_TYPE)).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should define a complex endpoint without appId', () => { | ||
expect( | ||
alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE) | ||
).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should define a complex endpoint', () => { | ||
expect( | ||
alerts.getEndpointAnnotation({ ...FULL_OPTIONS }, ALERT_TYPE, APPID) | ||
).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
appId: APPID, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should merge global & specific opts', () => { | ||
options.setGlobalOptions({ | ||
concurrency: 20, | ||
region: 'europe-west1', | ||
minInstances: 1, | ||
}); | ||
const specificOpts = { | ||
region: 'us-west1', | ||
minInstances: 3, | ||
}; | ||
|
||
expect( | ||
alerts.getEndpointAnnotation(specificOpts, ALERT_TYPE, APPID) | ||
).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
concurrency: 20, | ||
region: ['us-west1'], | ||
minInstances: 3, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: ALERT_TYPE, | ||
appId: APPID, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getOptsAndAlertTypeAndApp', () => { | ||
it('should parse a string', () => { | ||
const [opts, alertType, appId] = alerts.getOptsAndAlertTypeAndApp( | ||
ALERT_TYPE | ||
); | ||
|
||
expect(opts).to.deep.equal({}); | ||
expect(alertType).to.equal(ALERT_TYPE); | ||
expect(appId).to.be.undefined; | ||
}); | ||
|
||
it('should parse an options object without appId', () => { | ||
const myOpts: alerts.FirebaseAlertOptions = { | ||
alertType: ALERT_TYPE, | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, alertType, appId] = alerts.getOptsAndAlertTypeAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(alertType).to.equal(myOpts.alertType); | ||
expect(appId).to.be.undefined; | ||
}); | ||
|
||
it('should parse an options object with appId', () => { | ||
const myOpts: alerts.FirebaseAlertOptions = { | ||
alertType: ALERT_TYPE, | ||
appId: APPID, | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, alertType, appId] = alerts.getOptsAndAlertTypeAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(alertType).to.equal(myOpts.alertType); | ||
expect(appId).to.be.equal(myOpts.appId); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { expect } from 'chai'; | ||
import * as alerts from '../../../../src/v2/providers/alerts'; | ||
import * as appDistribution from '../../../../src/v2/providers/alerts/appDistribution'; | ||
import { FULL_ENDPOINT, FULL_OPTIONS } from '../helpers'; | ||
|
||
const APPID = '123456789'; | ||
const myHandler = () => 42; | ||
|
||
describe('appDistribution', () => { | ||
describe('onNewTesterIosDevicePublished', () => { | ||
it('should create a function with alertType & appId', () => { | ||
const func = appDistribution.onNewTesterIosDevicePublished( | ||
APPID, | ||
myHandler | ||
); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: appDistribution.newTesterIosDeviceAlert, | ||
appId: APPID, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with opts', () => { | ||
const func = appDistribution.onNewTesterIosDevicePublished( | ||
{ ...FULL_OPTIONS }, | ||
myHandler | ||
); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: appDistribution.newTesterIosDeviceAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with appid in opts', () => { | ||
const func = appDistribution.onNewTesterIosDevicePublished( | ||
{ ...FULL_OPTIONS, appId: APPID }, | ||
myHandler | ||
); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
...FULL_ENDPOINT, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: appDistribution.newTesterIosDeviceAlert, | ||
appId: APPID, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function without opts or appId', () => { | ||
const func = appDistribution.onNewTesterIosDevicePublished(myHandler); | ||
|
||
expect(func.__endpoint).to.deep.equal({ | ||
platform: 'gcfv2', | ||
labels: {}, | ||
eventTrigger: { | ||
eventType: alerts.eventType, | ||
eventFilters: { | ||
alertType: appDistribution.newTesterIosDeviceAlert, | ||
}, | ||
retry: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create a function with a run method', () => { | ||
const func = appDistribution.onNewTesterIosDevicePublished( | ||
APPID, | ||
(event) => event | ||
); | ||
|
||
const res = func.run('input' as any); | ||
|
||
expect(res).to.equal('input'); | ||
}); | ||
}); | ||
|
||
describe('getOptsAndApp', () => { | ||
it('should parse a string', () => { | ||
const [opts, appId] = appDistribution.getOptsAndApp(APPID); | ||
|
||
expect(opts).to.deep.equal({}); | ||
expect(appId).to.equal(APPID); | ||
}); | ||
|
||
it('should parse an options object without appId', () => { | ||
const myOpts: appDistribution.AppDistributionOptions = { | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, appId] = appDistribution.getOptsAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(appId).to.be.undefined; | ||
}); | ||
|
||
it('should parse an options object with appId', () => { | ||
const myOpts: appDistribution.AppDistributionOptions = { | ||
appId: APPID, | ||
region: 'us-west1', | ||
}; | ||
|
||
const [opts, appId] = appDistribution.getOptsAndApp(myOpts); | ||
|
||
expect(opts).to.deep.equal({ region: 'us-west1' }); | ||
expect(appId).to.equal(APPID); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.