Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions spec/providers/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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!',
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -184,7 +186,7 @@ describe('Analytics Functions', () => {
.event('first_open')
.onLog((data: analytics.AnalyticsEvent) => data);

let event: Event = {
const event: Event = {
data: {
eventDim: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -291,11 +293,12 @@ describe('Analytics Functions', () => {
.event('first_open')
.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;
return expect(cloudFunction(data, context)).to.eventually.deep.equal(
analytics_spec_input.data
);
const payloadData = analytics_spec_input.fullPayload.data;
const payloadContext = analytics_spec_input.fullPayload.context;

return expect(
cloudFunction(payloadData, payloadContext)
).to.eventually.deep.equal(analytics_spec_input.data);
});
});
});
Expand All @@ -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!',
Expand Down Expand Up @@ -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);
});
});
Expand Down
26 changes: 13 additions & 13 deletions spec/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

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';
import { Resolver } from 'dns';

describe('Auth Functions', () => {
const event: Event = {
Expand All @@ -46,7 +48,9 @@ describe('Auth Functions', () => {
};

describe('AuthBuilder', () => {
let handler: (user: firebase.auth.UserRecord) => PromiseLike<any> | any;
const handler = (user: firebase.auth.UserRecord) => {
return Promise.resolve();
};

before(() => {
process.env.GCLOUD_PROJECT = 'project1';
Expand All @@ -57,7 +61,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,
Expand Down Expand Up @@ -178,27 +182,23 @@ 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({});
});
});

describe('#onDelete', () => {
let cloudFunctionDelete: CloudFunction<
const cloudFunctionDelete: CloudFunction<
firebase.auth.UserRecord
> = functions.handler.auth.user.onDelete(
(data: firebase.auth.UserRecord) => data
);

it('should return an empty trigger', () => {
let handler: (user: firebase.auth.UserRecord) => PromiseLike<any> | any;
const handler = (user: firebase.auth.UserRecord) => {
return Promise.resolve();
};
const cloudFunction = functions.handler.auth.user.onDelete(handler);
expect(cloudFunction.__trigger).to.deep.equal({});
});
Expand Down Expand Up @@ -228,7 +228,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);
});
});
Expand Down
18 changes: 3 additions & 15 deletions spec/providers/crashlytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
});
Expand Down
8 changes: 4 additions & 4 deletions spec/providers/remoteConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down