From 8960f1948bcffe7617bfa5e66b7fa8f94a401e55 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 21:47:39 -0700 Subject: [PATCH 1/3] fix lint errors for auth, analytics, crashlytics, remoteconfig --- spec/providers/analytics.spec.ts | 26 +++++++++++++++----------- spec/providers/auth.spec.ts | 17 ++++++----------- spec/providers/crashlytics.spec.ts | 18 +++--------------- spec/providers/remoteConfig.spec.ts | 8 ++++---- 4 files changed, 28 insertions(+), 41 deletions(-) diff --git a/spec/providers/analytics.spec.ts b/spec/providers/analytics.spec.ts index cdb0ba02c..a81ffcec0 100644 --- a/spec/providers/analytics.spec.ts +++ b/spec/providers/analytics.spec.ts @@ -20,11 +20,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import * as analytics from '../../src/providers/analytics'; import { expect } from 'chai'; -import { EventContext, Event } from '../../src/cloud-functions'; -import * as analytics_spec_input from './analytics.spec.input'; + +import { Event, EventContext } from '../../src/cloud-functions'; import * as functions from '../../src/index'; +import * as analytics from '../../src/providers/analytics'; +import * as analytics_spec_input from './analytics.spec.input'; describe('Analytics Functions', () => { describe('EventBuilder', () => { @@ -37,7 +38,7 @@ describe('Analytics Functions', () => { }); it('should allow both region and runtime options to be set', () => { - let fn = functions + const fn = functions .region('us-east1') .runWith({ timeoutSeconds: 90, @@ -54,6 +55,7 @@ describe('Analytics Functions', () => { describe('#onLog', () => { it('should return a TriggerDefinition with appropriate values', () => { const cloudFunction = analytics.event('first_open').onLog(() => null); + expect(cloudFunction.__trigger).to.deep.equal({ eventTrigger: { eventType: @@ -75,7 +77,7 @@ describe('Analytics Functions', () => { // The event data delivered over the wire will be the JSON for an AnalyticsEvent: // https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data - let event: Event = { + const event: Event = { data: { userDim: { userId: 'hi!', @@ -114,7 +116,7 @@ describe('Analytics Functions', () => { // Incoming events will have four kinds of "xValue" fields: "intValue", // "stringValue", "doubleValue" and "floatValue". We expect those to get // flattened away, leaving just their values. - let event: Event = { + const event: Event = { data: { eventDim: [ { @@ -184,7 +186,7 @@ describe('Analytics Functions', () => { .event('first_open') .onLog((data: analytics.AnalyticsEvent) => data); - let event: Event = { + const event: Event = { data: { eventDim: [ { @@ -254,7 +256,7 @@ describe('Analytics Functions', () => { // // Separately, the input has a number of microsecond timestamps that we'd // like to rename and scale down to milliseconds. - let event: Event = { + const event: Event = { data: { eventDim: [ { @@ -289,10 +291,11 @@ describe('Analytics Functions', () => { it('should recognize all the fields the payload can contain', () => { const cloudFunction = analytics .event('first_open') - .onLog((data: analytics.AnalyticsEvent) => data); + .onLog((event: analytics.AnalyticsEvent) => event); // The payload in analytics_spec_input contains all possible fields at least once. const data = analytics_spec_input.fullPayload.data; const context = analytics_spec_input.fullPayload.context; + return expect(cloudFunction(data, context)).to.eventually.deep.equal( analytics_spec_input.data ); @@ -316,7 +319,7 @@ describe('Analytics Functions', () => { // The event data delivered over the wire will be the JSON for an AnalyticsEvent: // https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data - let event: Event = { + const event: Event = { data: { userDim: { userId: 'hi!', @@ -361,7 +364,8 @@ describe('Analytics Functions', () => { }); it('should not throw when #run is called', () => { - let cf = analytics.event('event').onLog(() => null); + const cf = analytics.event('event').onLog(() => null); + expect(cf.run).to.not.throw(Error); }); }); diff --git a/spec/providers/auth.spec.ts b/spec/providers/auth.spec.ts index c5300364d..f4337dd25 100644 --- a/spec/providers/auth.spec.ts +++ b/spec/providers/auth.spec.ts @@ -22,9 +22,10 @@ import { expect } from 'chai'; import * as firebase from 'firebase-admin'; -import * as auth from '../../src/providers/auth'; -import { CloudFunction, EventContext, Event } from '../../src/cloud-functions'; + +import { CloudFunction, Event, EventContext } from '../../src/cloud-functions'; import * as functions from '../../src/index'; +import * as auth from '../../src/providers/auth'; describe('Auth Functions', () => { const event: Event = { @@ -57,7 +58,7 @@ describe('Auth Functions', () => { }); it('should allow both region and runtime options to be set', () => { - let fn = functions + const fn = functions .region('us-east1') .runWith({ timeoutSeconds: 90, @@ -178,12 +179,6 @@ describe('Auth Functions', () => { describe('handler namespace', () => { describe('#onCreate', () => { - let cloudFunctionCreate: CloudFunction< - firebase.auth.UserRecord - > = functions.handler.auth.user.onCreate( - (data: firebase.auth.UserRecord) => data - ); - it('should return an empty trigger', () => { const cloudFunction = functions.handler.auth.user.onCreate(() => null); expect(cloudFunction.__trigger).to.deep.equal({}); @@ -191,7 +186,7 @@ describe('Auth Functions', () => { }); describe('#onDelete', () => { - let cloudFunctionDelete: CloudFunction< + const cloudFunctionDelete: CloudFunction< firebase.auth.UserRecord > = functions.handler.auth.user.onDelete( (data: firebase.auth.UserRecord) => data @@ -228,7 +223,7 @@ describe('Auth Functions', () => { }); it('should not throw when #run is called', () => { - let cf = auth.user().onCreate(() => null); + const cf = auth.user().onCreate(() => null); expect(cf.run).to.not.throw(Error); }); }); diff --git a/spec/providers/crashlytics.spec.ts b/spec/providers/crashlytics.spec.ts index 081fef807..7a724213b 100644 --- a/spec/providers/crashlytics.spec.ts +++ b/spec/providers/crashlytics.spec.ts @@ -22,9 +22,9 @@ import { expect } from 'chai'; -import * as crashlytics from '../../src/providers/crashlytics'; import { apps as appsNamespace } from '../../src/apps'; import * as functions from '../../src/index'; +import * as crashlytics from '../../src/providers/crashlytics'; describe('Crashlytics Functions', () => { describe('Issue Builder', () => { @@ -39,7 +39,7 @@ describe('Crashlytics Functions', () => { }); it('should allow both region and runtime options to be set', () => { - let fn = functions + const fn = functions .region('us-east1') .runWith({ timeoutSeconds: 90, @@ -95,18 +95,6 @@ describe('Crashlytics Functions', () => { }); describe('HandlerBuilder', () => { - const testIssue = { - issueId: '1234', - issueTitle: 'testIssue', - appInfo: { - appName: 'My Awesome Test App', - appPlatform: 'ios', - appId: '9876', - latestAppVersion: '1.2.3.4', - }, - createTime: '2018-12-18T23:05:55+00:00', - }; - describe('#onNew', () => { it('should return a CloudFunction with appropriate values', () => { const cloudFunction = functions.handler.crashlytics.issue.onNew( @@ -160,7 +148,7 @@ describe('Crashlytics Functions', () => { }); it('should not throw when #run is called', () => { - let cf = crashlytics.issue().onNew(() => null); + const cf = crashlytics.issue().onNew(() => null); expect(cf.run).to.not.throw(Error); }); }); diff --git a/spec/providers/remoteConfig.spec.ts b/spec/providers/remoteConfig.spec.ts index 97e74b593..d6e553cf4 100644 --- a/spec/providers/remoteConfig.spec.ts +++ b/spec/providers/remoteConfig.spec.ts @@ -25,8 +25,8 @@ import * as _ from 'lodash'; import { CloudFunction, Event, - TriggerAnnotated, EventContext, + TriggerAnnotated, } from '../../src/cloud-functions'; import * as functions from '../../src/index'; import * as remoteConfig from '../../src/providers/remoteConfig'; @@ -49,7 +49,7 @@ describe('RemoteConfig Functions', () => { function makeEvent(data: any, context: { [key: string]: any }): Event { context = context || {}; return { - data: data, + data, context: _.merge( { eventId: '123', @@ -158,11 +158,11 @@ describe('RemoteConfig Functions', () => { }); it('should correctly unwrap the event', () => { - let cloudFunctionUpdate = functions.handler.remoteConfig.onUpdate( + const cloudFunctionUpdate = functions.handler.remoteConfig.onUpdate( (version: remoteConfig.TemplateVersion, context: EventContext) => version ); - let event: Event = { + const event: Event = { data: constructVersion(), context: { eventId: '70172329041928', From 08eb739d27a628637d8da032e84fafaff8f961a2 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 23:13:36 -0700 Subject: [PATCH 2/3] fix handler function in auth test --- spec/providers/auth.spec.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/providers/auth.spec.ts b/spec/providers/auth.spec.ts index f4337dd25..676e973ce 100644 --- a/spec/providers/auth.spec.ts +++ b/spec/providers/auth.spec.ts @@ -26,6 +26,7 @@ import * as firebase from 'firebase-admin'; import { CloudFunction, Event, EventContext } from '../../src/cloud-functions'; import * as functions from '../../src/index'; import * as auth from '../../src/providers/auth'; +import { Resolver } from 'dns'; describe('Auth Functions', () => { const event: Event = { @@ -47,7 +48,9 @@ describe('Auth Functions', () => { }; describe('AuthBuilder', () => { - let handler: (user: firebase.auth.UserRecord) => PromiseLike | any; + const handler = (user: firebase.auth.UserRecord) => { + return Promise.resolve(); + }; before(() => { process.env.GCLOUD_PROJECT = 'project1'; @@ -193,7 +196,9 @@ describe('Auth Functions', () => { ); it('should return an empty trigger', () => { - let handler: (user: firebase.auth.UserRecord) => PromiseLike | any; + const handler = (user: firebase.auth.UserRecord) => { + return Promise.resolve(); + }; const cloudFunction = functions.handler.auth.user.onDelete(handler); expect(cloudFunction.__trigger).to.deep.equal({}); }); From 9530c70fab04b55a131ff750598a36cea809ef69 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Fri, 14 Jun 2019 01:03:06 -0700 Subject: [PATCH 3/3] renaming event back to data --- spec/providers/analytics.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/providers/analytics.spec.ts b/spec/providers/analytics.spec.ts index a81ffcec0..67e7a700b 100644 --- a/spec/providers/analytics.spec.ts +++ b/spec/providers/analytics.spec.ts @@ -291,14 +291,14 @@ describe('Analytics Functions', () => { it('should recognize all the fields the payload can contain', () => { const cloudFunction = analytics .event('first_open') - .onLog((event: analytics.AnalyticsEvent) => event); + .onLog((data: analytics.AnalyticsEvent) => data); // The payload in analytics_spec_input contains all possible fields at least once. - const data = analytics_spec_input.fullPayload.data; - const context = analytics_spec_input.fullPayload.context; + const payloadData = analytics_spec_input.fullPayload.data; + const payloadContext = analytics_spec_input.fullPayload.context; - return expect(cloudFunction(data, context)).to.eventually.deep.equal( - analytics_spec_input.data - ); + return expect( + cloudFunction(payloadData, payloadContext) + ).to.eventually.deep.equal(analytics_spec_input.data); }); }); });