Skip to content

Commit 1ccd569

Browse files
authored
Fix lint errors for auth, analytics, crashlytics, remoteconfig tests (#469)
* fix lint errors for auth, analytics, crashlytics, remoteconfig * fix handler function in auth test * renaming event back to data
1 parent f989e8c commit 1ccd569

File tree

4 files changed

+39
-47
lines changed

4 files changed

+39
-47
lines changed

spec/providers/analytics.spec.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import * as analytics from '../../src/providers/analytics';
2423
import { expect } from 'chai';
25-
import { EventContext, Event } from '../../src/cloud-functions';
26-
import * as analytics_spec_input from './analytics.spec.input';
24+
25+
import { Event, EventContext } from '../../src/cloud-functions';
2726
import * as functions from '../../src/index';
27+
import * as analytics from '../../src/providers/analytics';
28+
import * as analytics_spec_input from './analytics.spec.input';
2829

2930
describe('Analytics Functions', () => {
3031
describe('EventBuilder', () => {
@@ -37,7 +38,7 @@ describe('Analytics Functions', () => {
3738
});
3839

3940
it('should allow both region and runtime options to be set', () => {
40-
let fn = functions
41+
const fn = functions
4142
.region('us-east1')
4243
.runWith({
4344
timeoutSeconds: 90,
@@ -54,6 +55,7 @@ describe('Analytics Functions', () => {
5455
describe('#onLog', () => {
5556
it('should return a TriggerDefinition with appropriate values', () => {
5657
const cloudFunction = analytics.event('first_open').onLog(() => null);
58+
5759
expect(cloudFunction.__trigger).to.deep.equal({
5860
eventTrigger: {
5961
eventType:
@@ -75,7 +77,7 @@ describe('Analytics Functions', () => {
7577

7678
// The event data delivered over the wire will be the JSON for an AnalyticsEvent:
7779
// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
78-
let event: Event = {
80+
const event: Event = {
7981
data: {
8082
userDim: {
8183
userId: 'hi!',
@@ -114,7 +116,7 @@ describe('Analytics Functions', () => {
114116
// Incoming events will have four kinds of "xValue" fields: "intValue",
115117
// "stringValue", "doubleValue" and "floatValue". We expect those to get
116118
// flattened away, leaving just their values.
117-
let event: Event = {
119+
const event: Event = {
118120
data: {
119121
eventDim: [
120122
{
@@ -184,7 +186,7 @@ describe('Analytics Functions', () => {
184186
.event('first_open')
185187
.onLog((data: analytics.AnalyticsEvent) => data);
186188

187-
let event: Event = {
189+
const event: Event = {
188190
data: {
189191
eventDim: [
190192
{
@@ -254,7 +256,7 @@ describe('Analytics Functions', () => {
254256
//
255257
// Separately, the input has a number of microsecond timestamps that we'd
256258
// like to rename and scale down to milliseconds.
257-
let event: Event = {
259+
const event: Event = {
258260
data: {
259261
eventDim: [
260262
{
@@ -291,11 +293,12 @@ describe('Analytics Functions', () => {
291293
.event('first_open')
292294
.onLog((data: analytics.AnalyticsEvent) => data);
293295
// The payload in analytics_spec_input contains all possible fields at least once.
294-
const data = analytics_spec_input.fullPayload.data;
295-
const context = analytics_spec_input.fullPayload.context;
296-
return expect(cloudFunction(data, context)).to.eventually.deep.equal(
297-
analytics_spec_input.data
298-
);
296+
const payloadData = analytics_spec_input.fullPayload.data;
297+
const payloadContext = analytics_spec_input.fullPayload.context;
298+
299+
return expect(
300+
cloudFunction(payloadData, payloadContext)
301+
).to.eventually.deep.equal(analytics_spec_input.data);
299302
});
300303
});
301304
});
@@ -316,7 +319,7 @@ describe('Analytics Functions', () => {
316319

317320
// The event data delivered over the wire will be the JSON for an AnalyticsEvent:
318321
// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
319-
let event: Event = {
322+
const event: Event = {
320323
data: {
321324
userDim: {
322325
userId: 'hi!',
@@ -361,7 +364,8 @@ describe('Analytics Functions', () => {
361364
});
362365

363366
it('should not throw when #run is called', () => {
364-
let cf = analytics.event('event').onLog(() => null);
367+
const cf = analytics.event('event').onLog(() => null);
368+
365369
expect(cf.run).to.not.throw(Error);
366370
});
367371
});

spec/providers/auth.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
import { expect } from 'chai';
2424
import * as firebase from 'firebase-admin';
25-
import * as auth from '../../src/providers/auth';
26-
import { CloudFunction, EventContext, Event } from '../../src/cloud-functions';
25+
26+
import { CloudFunction, Event, EventContext } from '../../src/cloud-functions';
2727
import * as functions from '../../src/index';
28+
import * as auth from '../../src/providers/auth';
29+
import { Resolver } from 'dns';
2830

2931
describe('Auth Functions', () => {
3032
const event: Event = {
@@ -46,7 +48,9 @@ describe('Auth Functions', () => {
4648
};
4749

4850
describe('AuthBuilder', () => {
49-
let handler: (user: firebase.auth.UserRecord) => PromiseLike<any> | any;
51+
const handler = (user: firebase.auth.UserRecord) => {
52+
return Promise.resolve();
53+
};
5054

5155
before(() => {
5256
process.env.GCLOUD_PROJECT = 'project1';
@@ -57,7 +61,7 @@ describe('Auth Functions', () => {
5761
});
5862

5963
it('should allow both region and runtime options to be set', () => {
60-
let fn = functions
64+
const fn = functions
6165
.region('us-east1')
6266
.runWith({
6367
timeoutSeconds: 90,
@@ -178,27 +182,23 @@ describe('Auth Functions', () => {
178182

179183
describe('handler namespace', () => {
180184
describe('#onCreate', () => {
181-
let cloudFunctionCreate: CloudFunction<
182-
firebase.auth.UserRecord
183-
> = functions.handler.auth.user.onCreate(
184-
(data: firebase.auth.UserRecord) => data
185-
);
186-
187185
it('should return an empty trigger', () => {
188186
const cloudFunction = functions.handler.auth.user.onCreate(() => null);
189187
expect(cloudFunction.__trigger).to.deep.equal({});
190188
});
191189
});
192190

193191
describe('#onDelete', () => {
194-
let cloudFunctionDelete: CloudFunction<
192+
const cloudFunctionDelete: CloudFunction<
195193
firebase.auth.UserRecord
196194
> = functions.handler.auth.user.onDelete(
197195
(data: firebase.auth.UserRecord) => data
198196
);
199197

200198
it('should return an empty trigger', () => {
201-
let handler: (user: firebase.auth.UserRecord) => PromiseLike<any> | any;
199+
const handler = (user: firebase.auth.UserRecord) => {
200+
return Promise.resolve();
201+
};
202202
const cloudFunction = functions.handler.auth.user.onDelete(handler);
203203
expect(cloudFunction.__trigger).to.deep.equal({});
204204
});
@@ -228,7 +228,7 @@ describe('Auth Functions', () => {
228228
});
229229

230230
it('should not throw when #run is called', () => {
231-
let cf = auth.user().onCreate(() => null);
231+
const cf = auth.user().onCreate(() => null);
232232
expect(cf.run).to.not.throw(Error);
233233
});
234234
});

spec/providers/crashlytics.spec.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
import { expect } from 'chai';
2424

25-
import * as crashlytics from '../../src/providers/crashlytics';
2625
import { apps as appsNamespace } from '../../src/apps';
2726
import * as functions from '../../src/index';
27+
import * as crashlytics from '../../src/providers/crashlytics';
2828

2929
describe('Crashlytics Functions', () => {
3030
describe('Issue Builder', () => {
@@ -39,7 +39,7 @@ describe('Crashlytics Functions', () => {
3939
});
4040

4141
it('should allow both region and runtime options to be set', () => {
42-
let fn = functions
42+
const fn = functions
4343
.region('us-east1')
4444
.runWith({
4545
timeoutSeconds: 90,
@@ -95,18 +95,6 @@ describe('Crashlytics Functions', () => {
9595
});
9696

9797
describe('HandlerBuilder', () => {
98-
const testIssue = {
99-
issueId: '1234',
100-
issueTitle: 'testIssue',
101-
appInfo: {
102-
appName: 'My Awesome Test App',
103-
appPlatform: 'ios',
104-
appId: '9876',
105-
latestAppVersion: '1.2.3.4',
106-
},
107-
createTime: '2018-12-18T23:05:55+00:00',
108-
};
109-
11098
describe('#onNew', () => {
11199
it('should return a CloudFunction with appropriate values', () => {
112100
const cloudFunction = functions.handler.crashlytics.issue.onNew(
@@ -160,7 +148,7 @@ describe('Crashlytics Functions', () => {
160148
});
161149

162150
it('should not throw when #run is called', () => {
163-
let cf = crashlytics.issue().onNew(() => null);
151+
const cf = crashlytics.issue().onNew(() => null);
164152
expect(cf.run).to.not.throw(Error);
165153
});
166154
});

spec/providers/remoteConfig.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import * as _ from 'lodash';
2525
import {
2626
CloudFunction,
2727
Event,
28-
TriggerAnnotated,
2928
EventContext,
29+
TriggerAnnotated,
3030
} from '../../src/cloud-functions';
3131
import * as functions from '../../src/index';
3232
import * as remoteConfig from '../../src/providers/remoteConfig';
@@ -49,7 +49,7 @@ describe('RemoteConfig Functions', () => {
4949
function makeEvent(data: any, context: { [key: string]: any }): Event {
5050
context = context || {};
5151
return {
52-
data: data,
52+
data,
5353
context: _.merge(
5454
{
5555
eventId: '123',
@@ -158,11 +158,11 @@ describe('RemoteConfig Functions', () => {
158158
});
159159

160160
it('should correctly unwrap the event', () => {
161-
let cloudFunctionUpdate = functions.handler.remoteConfig.onUpdate(
161+
const cloudFunctionUpdate = functions.handler.remoteConfig.onUpdate(
162162
(version: remoteConfig.TemplateVersion, context: EventContext) =>
163163
version
164164
);
165-
let event: Event = {
165+
const event: Event = {
166166
data: constructVersion(),
167167
context: {
168168
eventId: '70172329041928',

0 commit comments

Comments
 (0)