Skip to content

Commit 5919c31

Browse files
committed
fix unit tests
1 parent 9f7b83b commit 5919c31

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

spec/v2/providers/identity.spec.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,31 +207,30 @@ describe("identity", () => {
207207
},
208208
]);
209209
});
210-
});
211210

212-
it("should accept options and a handler", () => {
213-
const fn = identity.beforeEmailSent(opts, () => Promise.resolve());
214-
215-
expect(fn.__endpoint).to.deep.equal({
216-
...MINIMAL_V2_ENDPOINT,
217-
platform: "gcfv2",
218-
labels: {},
219-
minInstances: 1,
220-
region: [REGION],
221-
blockingTrigger: {
222-
...BEFORE_EMAIL_TRIGGER,
223-
options: {
224-
...BEFORE_EMAIL_TRIGGER.options,
225-
accessToken: true,
211+
it("should accept options and a handler", () => {
212+
const fn = identity.beforeEmailSent(
213+
{ region: opts.region, minInstances: opts.minInstances },
214+
() => Promise.resolve()
215+
);
216+
217+
expect(fn.__endpoint).to.deep.equal({
218+
...MINIMAL_V2_ENDPOINT,
219+
platform: "gcfv2",
220+
labels: {},
221+
minInstances: 1,
222+
region: [REGION],
223+
blockingTrigger: {
224+
...BEFORE_EMAIL_TRIGGER,
226225
},
227-
},
226+
});
227+
expect(fn.__requiredAPIs).to.deep.equal([
228+
{
229+
api: IDENTITY_TOOLKIT_API,
230+
reason: "Needed for auth blocking functions",
231+
},
232+
]);
228233
});
229-
expect(fn.__requiredAPIs).to.deep.equal([
230-
{
231-
api: IDENTITY_TOOLKIT_API,
232-
reason: "Needed for auth blocking functions",
233-
},
234-
]);
235234
});
236235

237236
describe("beforeOperation", () => {
@@ -347,10 +346,6 @@ describe("identity", () => {
347346
region: [REGION],
348347
blockingTrigger: {
349348
...BEFORE_EMAIL_TRIGGER,
350-
options: {
351-
...BEFORE_EMAIL_TRIGGER.options,
352-
accessToken: true,
353-
},
354349
},
355350
});
356351
expect(fn.__requiredAPIs).to.deep.equal([

src/v2/providers/identity.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ export function beforeOperation(
273273
if (!handler || typeof optsOrHandler === "function") {
274274
handler = optsOrHandler as (
275275
event: AuthBlockingEvent
276-
) => BeforeEmailResponse | void | Promise<BeforeEmailResponse> | Promise<void>;
276+
) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | void>;
277277
optsOrHandler = {};
278278
}
279279

280-
const { opts, accessToken, idToken, refreshToken } = getOpts(optsOrHandler);
280+
const { opts, ...blockingOptions } = getOpts(optsOrHandler);
281281

282282
// Create our own function that just calls the provided function so we know for sure that
283283
// handler takes one argument. This is something common/providers/identity depends on.
@@ -302,9 +302,7 @@ export function beforeOperation(
302302
blockingTrigger: {
303303
eventType: legacyEventType,
304304
options: {
305-
accessToken,
306-
idToken,
307-
refreshToken,
305+
...((eventType === "beforeCreate" || eventType === "beforeSignIn") && blockingOptions),
308306
},
309307
},
310308
};

0 commit comments

Comments
 (0)