Skip to content

Commit 3241eaf

Browse files
committed
Rip out handler namespace.
1 parent 87ca228 commit 3241eaf

File tree

11 files changed

+913
-2088
lines changed

11 files changed

+913
-2088
lines changed

spec/v1/providers/analytics.spec.ts

Lines changed: 92 additions & 160 deletions
Large diffs are not rendered by default.

spec/v1/providers/auth.spec.ts

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

23-
import { expect } from 'chai';
24-
import { UserRecord } from '../../../src/common/providers/identity';
25-
import * as functions from '../../../src/v1';
26-
import {
27-
CloudFunction,
28-
Event,
29-
EventContext,
30-
} from '../../../src/v1/cloud-functions';
31-
import * as auth from '../../../src/v1/providers/auth';
23+
import { expect } from "chai";
24+
import { UserRecord } from "../../../src/common/providers/identity";
25+
import * as functions from "../../../src/v1";
26+
import { CloudFunction, Event, EventContext } from "../../../src/v1/cloud-functions";
27+
import * as auth from "../../../src/v1/providers/auth";
3228

33-
describe('Auth Functions', () => {
29+
describe("Auth Functions", () => {
3430
const event: Event = {
3531
data: {
3632
metadata: {
37-
creationTime: '2016-12-15T19:37:37.059Z',
38-
lastSignInTime: '2017-01-01T00:00:00.000Z',
33+
creationTime: "2016-12-15T19:37:37.059Z",
34+
lastSignInTime: "2017-01-01T00:00:00.000Z",
3935
},
4036
},
4137
context: {
42-
eventId: '70172329041928',
43-
timestamp: '2018-04-09T07:56:12.975Z',
44-
eventType: 'providers/firebase.auth/eventTypes/user.delete',
38+
eventId: "70172329041928",
39+
timestamp: "2018-04-09T07:56:12.975Z",
40+
eventType: "providers/firebase.auth/eventTypes/user.delete",
4541
resource: {
46-
service: 'firebaseauth.googleapis.com',
47-
name: 'projects/project1',
42+
service: "firebaseauth.googleapis.com",
43+
name: "projects/project1",
4844
},
4945
},
5046
};
5147

52-
describe('AuthBuilder', () => {
48+
describe("AuthBuilder", () => {
5349
function expectedEndpoint(project: string, eventType: string) {
5450
return {
55-
platform: 'gcfv1',
51+
platform: "gcfv1",
5652
eventTrigger: {
5753
eventFilters: {
5854
resource: `projects/${project}`,
@@ -68,7 +64,7 @@ describe('Auth Functions', () => {
6864
return Promise.resolve();
6965
};
7066

71-
const project = 'project1';
67+
const project = "project1";
7268

7369
before(() => {
7470
process.env.GCLOUD_PROJECT = project;
@@ -78,54 +74,50 @@ describe('Auth Functions', () => {
7874
delete process.env.GCLOUD_PROJECT;
7975
});
8076

81-
it('should allow both region and runtime options to be set', () => {
77+
it("should allow both region and runtime options to be set", () => {
8278
const fn = functions
83-
.region('us-east1')
79+
.region("us-east1")
8480
.runWith({
8581
timeoutSeconds: 90,
86-
memory: '256MB',
82+
memory: "256MB",
8783
})
8884
.auth.user()
8985
.onCreate(() => null);
9086

91-
expect(fn.__endpoint.region).to.deep.equal(['us-east1']);
87+
expect(fn.__endpoint.region).to.deep.equal(["us-east1"]);
9288
expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256);
9389
expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90);
9490

95-
expect(fn.__endpoint.region).to.deep.equal(['us-east1']);
91+
expect(fn.__endpoint.region).to.deep.equal(["us-east1"]);
9692
expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256);
9793
expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90);
9894
});
9995

100-
describe('#onCreate', () => {
101-
it('should return a trigger/endpoint with appropriate values', () => {
96+
describe("#onCreate", () => {
97+
it("should return a trigger/endpoint with appropriate values", () => {
10298
const cloudFunction = auth.user().onCreate(() => null);
10399

104-
expect(cloudFunction.__endpoint).to.deep.equal(
105-
expectedEndpoint(project, 'user.create')
106-
);
100+
expect(cloudFunction.__endpoint).to.deep.equal(expectedEndpoint(project, "user.create"));
107101
});
108102
});
109103

110-
describe('#onDelete', () => {
111-
it('should return a trigger/endpoint with appropriate values', () => {
104+
describe("#onDelete", () => {
105+
it("should return a trigger/endpoint with appropriate values", () => {
112106
const cloudFunction = auth.user().onDelete(handler);
113107

114-
expect(cloudFunction.__endpoint).to.deep.equal(
115-
expectedEndpoint(project, 'user.delete')
116-
);
108+
expect(cloudFunction.__endpoint).to.deep.equal(expectedEndpoint(project, "user.delete"));
117109
});
118110
});
119111

120-
describe('beforeCreate', () => {
121-
it('should create the function without options', () => {
112+
describe("beforeCreate", () => {
113+
it("should create the function without options", () => {
122114
const fn = auth.user().beforeCreate((u, c) => Promise.resolve());
123115

124116
expect(fn.__endpoint).to.deep.equal({
125-
platform: 'gcfv1',
117+
platform: "gcfv1",
126118
labels: {},
127119
blockingTrigger: {
128-
eventType: 'providers/cloud.auth/eventTypes/user.beforeCreate',
120+
eventType: "providers/cloud.auth/eventTypes/user.beforeCreate",
129121
options: {
130122
accessToken: false,
131123
idToken: false,
@@ -135,18 +127,18 @@ describe('Auth Functions', () => {
135127
});
136128
expect(fn.__requiredAPIs).to.deep.equal([
137129
{
138-
api: 'identitytoolkit.googleapis.com',
139-
reason: 'Needed for auth blocking functions',
130+
api: "identitytoolkit.googleapis.com",
131+
reason: "Needed for auth blocking functions",
140132
},
141133
]);
142134
});
143135

144-
it('should create the function with options', () => {
136+
it("should create the function with options", () => {
145137
const fn = functions
146-
.region('us-east1')
138+
.region("us-east1")
147139
.runWith({
148140
timeoutSeconds: 90,
149-
memory: '256MB',
141+
memory: "256MB",
150142
})
151143
.auth.user({
152144
blockingOptions: {
@@ -157,13 +149,13 @@ describe('Auth Functions', () => {
157149
.beforeCreate((u, c) => Promise.resolve());
158150

159151
expect(fn.__endpoint).to.deep.equal({
160-
platform: 'gcfv1',
152+
platform: "gcfv1",
161153
labels: {},
162-
region: ['us-east1'],
154+
region: ["us-east1"],
163155
availableMemoryMb: 256,
164156
timeoutSeconds: 90,
165157
blockingTrigger: {
166-
eventType: 'providers/cloud.auth/eventTypes/user.beforeCreate',
158+
eventType: "providers/cloud.auth/eventTypes/user.beforeCreate",
167159
options: {
168160
accessToken: true,
169161
idToken: false,
@@ -173,22 +165,22 @@ describe('Auth Functions', () => {
173165
});
174166
expect(fn.__requiredAPIs).to.deep.equal([
175167
{
176-
api: 'identitytoolkit.googleapis.com',
177-
reason: 'Needed for auth blocking functions',
168+
api: "identitytoolkit.googleapis.com",
169+
reason: "Needed for auth blocking functions",
178170
},
179171
]);
180172
});
181173
});
182174

183-
describe('beforeSignIn', () => {
184-
it('should create the function without options', () => {
175+
describe("beforeSignIn", () => {
176+
it("should create the function without options", () => {
185177
const fn = auth.user().beforeSignIn((u, c) => Promise.resolve());
186178

187179
expect(fn.__endpoint).to.deep.equal({
188-
platform: 'gcfv1',
180+
platform: "gcfv1",
189181
labels: {},
190182
blockingTrigger: {
191-
eventType: 'providers/cloud.auth/eventTypes/user.beforeSignIn',
183+
eventType: "providers/cloud.auth/eventTypes/user.beforeSignIn",
192184
options: {
193185
accessToken: false,
194186
idToken: false,
@@ -198,18 +190,18 @@ describe('Auth Functions', () => {
198190
});
199191
expect(fn.__requiredAPIs).to.deep.equal([
200192
{
201-
api: 'identitytoolkit.googleapis.com',
202-
reason: 'Needed for auth blocking functions',
193+
api: "identitytoolkit.googleapis.com",
194+
reason: "Needed for auth blocking functions",
203195
},
204196
]);
205197
});
206198

207-
it('should create the function with options', () => {
199+
it("should create the function with options", () => {
208200
const fn = functions
209-
.region('us-east1')
201+
.region("us-east1")
210202
.runWith({
211203
timeoutSeconds: 90,
212-
memory: '256MB',
204+
memory: "256MB",
213205
})
214206
.auth.user({
215207
blockingOptions: {
@@ -220,13 +212,13 @@ describe('Auth Functions', () => {
220212
.beforeSignIn((u, c) => Promise.resolve());
221213

222214
expect(fn.__endpoint).to.deep.equal({
223-
platform: 'gcfv1',
215+
platform: "gcfv1",
224216
labels: {},
225-
region: ['us-east1'],
217+
region: ["us-east1"],
226218
availableMemoryMb: 256,
227219
timeoutSeconds: 90,
228220
blockingTrigger: {
229-
eventType: 'providers/cloud.auth/eventTypes/user.beforeSignIn',
221+
eventType: "providers/cloud.auth/eventTypes/user.beforeSignIn",
230222
options: {
231223
accessToken: true,
232224
idToken: false,
@@ -236,14 +228,14 @@ describe('Auth Functions', () => {
236228
});
237229
expect(fn.__requiredAPIs).to.deep.equal([
238230
{
239-
api: 'identitytoolkit.googleapis.com',
240-
reason: 'Needed for auth blocking functions',
231+
api: "identitytoolkit.googleapis.com",
232+
reason: "Needed for auth blocking functions",
241233
},
242234
]);
243235
});
244236
});
245237

246-
describe('#_dataConstructor', () => {
238+
describe("#_dataConstructor", () => {
247239
let cloudFunctionDelete: CloudFunction<UserRecord>;
248240

249241
before(() => {
@@ -252,63 +244,25 @@ describe('Auth Functions', () => {
252244
.onDelete((data: UserRecord, context: EventContext) => data);
253245
});
254246

255-
it('should handle wire format as of v5.0.0 of firebase-admin', () => {
256-
return cloudFunctionDelete(event.data, event.context).then(
257-
(data: any) => {
258-
expect(data.metadata.creationTime).to.equal(
259-
'2016-12-15T19:37:37.059Z'
260-
);
261-
expect(data.metadata.lastSignInTime).to.equal(
262-
'2017-01-01T00:00:00.000Z'
263-
);
264-
}
265-
);
266-
});
267-
});
268-
});
269-
270-
describe('handler namespace', () => {
271-
describe('#onCreate', () => {
272-
it('should return an empty endpoint', () => {
273-
const cloudFunction = functions.handler.auth.user.onCreate(() => null);
274-
expect(cloudFunction.__endpoint).to.be.undefined;
275-
});
276-
});
277-
278-
describe('#onDelete', () => {
279-
const cloudFunctionDelete: CloudFunction<UserRecord> =
280-
functions.handler.auth.user.onDelete((data: UserRecord) => data);
281-
282-
it('should return an empty endpoint', () => {
283-
const cloudFunction = functions.handler.auth.user.onDelete(() => null);
284-
expect(cloudFunction.__endpoint).to.be.undefined;
285-
});
286-
287-
it('should handle wire format as of v5.0.0 of firebase-admin', () => {
288-
return cloudFunctionDelete(event.data, event.context).then(
289-
(data: any) => {
290-
expect(data.metadata.creationTime).to.equal(
291-
'2016-12-15T19:37:37.059Z'
292-
);
293-
expect(data.metadata.lastSignInTime).to.equal(
294-
'2017-01-01T00:00:00.000Z'
295-
);
296-
}
297-
);
247+
it("should handle wire format as of v5.0.0 of firebase-admin", () => {
248+
return cloudFunctionDelete(event.data, event.context).then((data: any) => {
249+
expect(data.metadata.creationTime).to.equal("2016-12-15T19:37:37.059Z");
250+
expect(data.metadata.lastSignInTime).to.equal("2017-01-01T00:00:00.000Z");
251+
});
298252
});
299253
});
300254
});
301255

302-
describe('process.env.GCLOUD_PROJECT not set', () => {
303-
it('should not throw if __endpoint is not accessed', () => {
256+
describe("process.env.GCLOUD_PROJECT not set", () => {
257+
it("should not throw if __endpoint is not accessed", () => {
304258
expect(() => auth.user().onCreate(() => null)).to.not.throw(Error);
305259
});
306260

307-
it('should throw when endpoint is accessed', () => {
261+
it("should throw when endpoint is accessed", () => {
308262
expect(() => auth.user().onCreate(() => null).__endpoint).to.throw(Error);
309263
});
310264

311-
it('should not throw when #run is called', () => {
265+
it("should not throw when #run is called", () => {
312266
const cf = auth.user().onCreate(() => null);
313267
expect(cf.run).to.not.throw(Error);
314268
});

0 commit comments

Comments
 (0)