Skip to content

Commit

Permalink
[EXC-18] passport doc snippet (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-yangy authored Jul 17, 2024
1 parent 6c54396 commit 67b3ab7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/passport/sdk/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config: Config = {
moduleDirectories: ['node_modules', 'src'],
moduleNameMapper: {
'@imtbl/config': '<rootDir>../../config/src',
'@imtbl/metrics': '<rootDir>../../internal/metrics/src',
'@imtbl/generated-clients': '<rootDir>../../internal/generated-clients/src',
'@imtbl/guardian': '<rootDir>../../internal/guardian/src',
'@imtbl/x-client': '<rootDir>../../x-client/src',
Expand Down
12 changes: 7 additions & 5 deletions packages/passport/sdk/src/Passport.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,17 @@ describe('Passport', () => {
});

// user isn't logged in, so wont set signer when provider is instantiated
const zkEvmProvider = passport.connectEvm();
// #doc request-accounts
const provider = passport.connectEvm();
const accounts = await provider.request({
method: 'eth_requestAccounts',
});
// #enddoc request-accounts

// user logs in, ethSigner is initialised
await passport.login();

mockGetUser.mockResolvedValue(Promise.resolve(mockOidcUserZkevm));
const accounts = await zkEvmProvider.request({
method: 'eth_requestAccounts',
});

expect(accounts).toEqual([mockUserZkEvm.zkEvm.ethAddress]);

Expand All @@ -344,7 +346,7 @@ describe('Passport', () => {
value: '5000000000000000',
data: '0x00',
};
const result = await zkEvmProvider.request({
const result = await provider.request({
method: 'eth_sendTransaction',
params: [transaction],
});
Expand Down
12 changes: 8 additions & 4 deletions packages/passport/sdk/src/Passport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AuthManager from './authManager';
import MagicAdapter from './magicAdapter';
import { Passport } from './Passport';
import { PassportImxProvider, PassportImxProviderFactory } from './starkEx';
import { OidcConfiguration } from './types';
import { OidcConfiguration, UserProfile } from './types';
import { mockUser, mockLinkedAddresses, mockUserImx } from './test/mocks';
import { announceProvider, passportProviderInfo } from './zkEvm/provider/eip6963';
import { ZkEvmProvider } from './zkEvm';
Expand Down Expand Up @@ -156,9 +156,11 @@ describe('Passport', () => {

describe('connectEvm', () => {
it('should execute connectEvm without error and return the provider', async () => {
const provider = await passport.connectEvm();
// #doc connect-evm
const passportProvider = await passport.connectEvm();
// #enddoc connect-evm

expect(provider).toBeInstanceOf(ZkEvmProvider);
expect(passportProvider).toBeInstanceOf(ZkEvmProvider);
expect(ZkEvmProvider).toHaveBeenCalled();
});

Expand Down Expand Up @@ -314,7 +316,9 @@ describe('Passport', () => {
describe('login', () => {
it('should login silently if there is a user', async () => {
getUserMock.mockReturnValue(mockUserImx);
const user = await passport.login();
// #doc auth-users-without-wallet
const user: UserProfile | null = await passport.login();
// #enddoc auth-users-without-wallet

expect(getUserMock).toBeCalledTimes(1);
expect(authLoginMock).toBeCalledTimes(0);
Expand Down
6 changes: 4 additions & 2 deletions packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ describe('ZkEvmProvider', () => {

provider.on('accountsChanged', onAccountsChanged);

const result = await provider.request({ method: 'eth_requestAccounts' });
// #doc eth_request-accounts
const accounts = await provider.request({ method: 'eth_requestAccounts' });
// #enddoc eth_request-accounts

expect(result).toEqual([mockUserZkEvm.zkEvm.ethAddress]);
expect(accounts).toEqual([mockUserZkEvm.zkEvm.ethAddress]);
expect(onAccountsChanged).toHaveBeenCalledWith([mockUserZkEvm.zkEvm.ethAddress]);
expect(identify).toHaveBeenCalledWith({
passportId: mockUserZkEvm.profile.sub,
Expand Down

0 comments on commit 67b3ab7

Please sign in to comment.