Skip to content

Commit

Permalink
refactor: added addContactInfo to AuthorizedUserTestContext template
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed Sep 19, 2022
1 parent 5778d95 commit 03d06ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface AuthorizedUserTestContext {
readonly uid: FirebaseAuthUserId;
loadUserRecord(): Promise<UserRecord>;
loadIdToken(): Promise<string>;
loadUserEmailAndPhone(): Promise<{ email: EmailAddress; phone?: E164PhoneNumber }>;
loadDecodedIdToken(): Promise<DecodedIdToken>;
makeContextOptions(): Promise<ContextOptions>;
callCloudFunction<F extends CallCloudFunction, O = unknown>(fn: F, params: CallCloudFunctionParams<F>): Promise<O>;
Expand All @@ -36,6 +37,10 @@ export class AuthorizedUserTestContextFixture<PI extends FirebaseAdminTestContex
return this.instance.loadUserRecord();
}

loadUserEmailAndPhone() {
return this.instance.loadUserEmailAndPhone();
}

loadIdToken(): Promise<string> {
return this.instance.loadIdToken();
}
Expand Down Expand Up @@ -103,6 +108,12 @@ export interface AuthorizedUserTestContextDetailsTemplate {
* Custom claims object to add to a user's tokens.
*/
claims?: object;
/**
* Whether or not to add contact info. Is false by default.
*
* Any generated contact info will be overwritten by the input template.
*/
addContactInfo?: boolean;
}

/**
Expand Down Expand Up @@ -174,14 +185,15 @@ export function authorizedUserContextFactory<PI extends FirebaseAdminTestContext
const makeUid = uidGetter ? asGetter(uidGetter) : testUidFactory;

return (params: C, buildTests: (u: F) => void) => {
const { f, user: inputUser, addContactInfo } = params;
const { f, user: inputUser, addContactInfo: inputAddContactInfo } = params;

return useJestContextFixture<F, I>({
fixture: makeFixture(f) as F,
buildTests,
initInstance: async () => {
const uid = inputUser?.uid || makeUid();
const { details, claims } = { ...makeUserDetails(uid, params), ...params.template };
const { details, claims, addContactInfo: userDetailsAddContactInfo } = { ...makeUserDetails(uid, params), ...params.template };
const addContactInfo = inputAddContactInfo || userDetailsAddContactInfo;
const auth = f.instance.auth;

let email: EmailAddress | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/nestjs/mailgun/src/lib/mailgun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface MailgunTemplateEmailParameters {
/**
* Overrides the global configuration for sending test emails to force sending. Useful when debugging specific tests.
*/
sendTestEmails?: true;
sendTestEmails?: true | undefined;
}

export interface MailgunTemplateEmailRequest extends MailgunEmailRequest, MailgunTemplateEmailParameters {
Expand Down

0 comments on commit 03d06ed

Please sign in to comment.