-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platforms): alert users about missing CB attestation before oauth (
#2584) * feat(platforms): alert users about missing CB attestation before oauth * test(platforms): added test * changed error name for accuracy
- Loading branch information
1 parent
0e19d0f
commit 182018d
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
platforms/src/Coinbase/__tests__/coinbaseGetProviderInfo.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable */ | ||
// ---- Test subject | ||
import { verifyCoinbaseAttestation } from "../Providers/coinbase"; | ||
import { CoinbasePlatform } from "../App-Bindings"; | ||
import { PlatformPreCheckError } from "../../utils/platform"; | ||
|
||
jest.mock("../Providers/coinbase"); | ||
|
||
const mockedVerifyCoinbaseAttestation = jest.mocked(verifyCoinbaseAttestation); | ||
|
||
const mockResponse = { | ||
code: 123, | ||
sessionKey: "sessionKey", | ||
signature: "signature", | ||
}; | ||
|
||
const appContext = { | ||
waitForRedirect: () => Promise.resolve(mockResponse), | ||
window: { | ||
open: jest.fn(), | ||
}, | ||
screen: { | ||
width: 800, | ||
height: 600, | ||
}, | ||
state: "state", | ||
userDid: "did:pk:ethr:1:0x12345", | ||
selectedProviders: [] as any[], | ||
}; | ||
|
||
describe("getProviderInfo", () => { | ||
it("should return oauth info for a valid attestation", async () => { | ||
mockedVerifyCoinbaseAttestation.mockResolvedValueOnce(true); | ||
const providerInfo = await new CoinbasePlatform({ | ||
clientId: "clientId", | ||
redirectUri: "redirectUri", | ||
}).getProviderPayload(appContext); | ||
expect(providerInfo.code).toBe(mockResponse.code); | ||
expect(mockedVerifyCoinbaseAttestation).toHaveBeenCalledWith("0x12345"); | ||
}); | ||
|
||
it("should return PlatformPreCheckError for an invalid attestation", async () => { | ||
mockedVerifyCoinbaseAttestation.mockResolvedValueOnce(false); | ||
await expect( | ||
new CoinbasePlatform({ | ||
clientId: "clientId", | ||
redirectUri: "redirectUri", | ||
}).getProviderPayload(appContext) | ||
).rejects.toThrowError( | ||
new PlatformPreCheckError( | ||
"You need to verify your Coinbase ID onchain before you can verify your Coinbase account." | ||
) | ||
); | ||
expect(mockedVerifyCoinbaseAttestation).toHaveBeenCalledWith("0x12345"); | ||
}); | ||
}); |
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
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