-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types,clerk-js): Enhance Web3 wallet resource with relevant oper…
…ations Enhance Web3Wallet resource with new operations. Those are create() which creates a new web3 wallet prepareVerification() to prepare the relevant web3 wallet verification, attemptVerification() to verify the web3 wallet and finally destroy() to delete it.
- Loading branch information
1 parent
acd7160
commit a166716
Showing
8 changed files
with
233 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Web3WalletJSON } from '@clerk/types'; | ||
import { BaseResource, Web3Wallet } from 'core/resources/internal'; | ||
|
||
describe('Web3 wallet', () => { | ||
it('create', async () => { | ||
const web3WalletJSON = { | ||
object: 'web3_wallet', | ||
web3_wallet: '0x0000000000000000000000000000000000000000', | ||
} as Web3WalletJSON; | ||
|
||
// @ts-ignore | ||
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: web3WalletJSON })); | ||
|
||
const web3Wallet = new Web3Wallet(web3WalletJSON, '/me/web3_wallets'); | ||
await web3Wallet.create(); | ||
|
||
// @ts-ignore | ||
expect(BaseResource._fetch).toHaveBeenCalledWith({ | ||
method: 'POST', | ||
path: '/me/web3_wallets', | ||
body: { | ||
web3_wallet: web3WalletJSON.web3_wallet, | ||
}, | ||
}); | ||
}); | ||
|
||
it('prepareVerification', async () => { | ||
const web3WalletJSON = { | ||
id: 'test-id', | ||
object: 'web3_wallet', | ||
web3_wallet: '0x0000000000000000000000000000000000000000', | ||
} as Web3WalletJSON; | ||
|
||
// @ts-ignore | ||
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: web3WalletJSON })); | ||
|
||
const web3Wallet = new Web3Wallet(web3WalletJSON, '/me/web3_wallets'); | ||
await web3Wallet.prepareVerification({ strategy: 'web3_metamask_signature' }); | ||
|
||
// @ts-ignore | ||
expect(BaseResource._fetch).toHaveBeenCalledWith({ | ||
method: 'POST', | ||
path: `/me/web3_wallets/${web3WalletJSON.id}/prepare_verification`, | ||
body: { | ||
strategy: 'web3_metamask_signature', | ||
}, | ||
}); | ||
}); | ||
|
||
it('attemptVerification', async () => { | ||
const web3WalletJSON = { | ||
id: 'test-id', | ||
object: 'web3_wallet', | ||
web3_wallet: '0x0000000000000000000000000000000000000000', | ||
} as Web3WalletJSON; | ||
|
||
// @ts-ignore | ||
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: web3WalletJSON })); | ||
|
||
const web3Wallet = new Web3Wallet(web3WalletJSON, '/me/web3_wallets'); | ||
await web3Wallet.attemptVerification({ signature: 'mock-signature' }); | ||
|
||
// @ts-ignore | ||
expect(BaseResource._fetch).toHaveBeenCalledWith({ | ||
method: 'POST', | ||
path: `/me/web3_wallets/${web3WalletJSON.id}/attempt_verification`, | ||
body: { | ||
signature: 'mock-signature', | ||
}, | ||
}); | ||
}); | ||
|
||
it('destroy', async () => { | ||
const targetId = 'test_id'; | ||
|
||
const deletedObjectJSON = { | ||
object: 'web3_wallet', | ||
id: targetId, | ||
deleted: true, | ||
}; | ||
|
||
// @ts-ignore | ||
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: deletedObjectJSON })); | ||
|
||
const web3Wallet = new Web3Wallet({ id: targetId }, '/me/web3_wallets'); | ||
await web3Wallet.destroy(); | ||
|
||
// @ts-ignore | ||
expect(BaseResource._fetch).toHaveBeenCalledWith({ | ||
method: 'DELETE', | ||
path: `/me/web3_wallets/${targetId}`, | ||
}); | ||
}); | ||
}); |
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
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