Last active
June 30, 2020 06:12
-
-
Save ecklf/fb181b421b36ead778501fc4892c5b45 to your computer and use it in GitHub Desktop.
Mock OAuth2Client for testing (google-auth-library)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LoginTicket, OAuth2Client, TokenPayload } from "google-auth-library"; | |
const mockTokenPayload: TokenPayload = { | |
//... | |
} | |
const mockVerifyIdToken = ({ | |
idToken, | |
}: { | |
idToken: string; | |
}): Promise<LoginTicket> => { | |
return new Promise((resolve, reject) => { | |
if (idToken === "invalid") { | |
reject(new Error()); | |
} | |
resolve({ | |
getPayload: (): TokenPayload => mockTokenPayload, | |
} as LoginTicket); | |
}); | |
}; | |
OAuth2Client.prototype.verifyIdToken = mockVerifyIdToken; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment