-
Notifications
You must be signed in to change notification settings - Fork 85
/
checkout.spec.ts
120 lines (98 loc) · 3.79 KB
/
checkout.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import browserEnv from '@ikscodes/browser-env';
import { createMagicSDK } from '../../../factories';
import { createPromiEvent } from '../../../../src/util';
import { NftCheckoutIntermediaryEvents, NftCheckoutEventHandler } from '../../../../../types/src/modules/nft-types';
beforeEach(() => {
browserEnv.restore();
});
test('checkout method should return a PromiEvent', async () => {
const magic = createMagicSDK();
magic.nft.request = jest.fn().mockReturnValue({
status: 'processed',
});
const response = await magic.nft.checkout({
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
});
expect(response.status).toBe('processed');
const requestPayload = magic.nft.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_nft_checkout');
expect(requestPayload.params).toMatchObject([
{
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
},
]);
});
test('checkout method can add isCryptoCheckoutEnabled to request payload', async () => {
const magic = createMagicSDK();
magic.nft.request = jest.fn().mockReturnValue({
status: 'processed',
});
const response = await magic.nft.checkout({
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
});
expect(response.status).toBe('processed');
const requestPayload = magic.nft.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_nft_checkout');
expect(requestPayload.params).toMatchObject([
{
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
},
]);
});
test('Third party wallet is connected', async () => {
const magic = createMagicSDK();
magic.thirdPartyWallets.isConnected = true;
magic.nft.request = jest.fn().mockReturnValue({
on: jest.fn(),
status: 'processed',
});
const mockPromiEvent = createPromiEvent<string, NftCheckoutEventHandler>((resolve) => {
resolve('0xasdfsadf');
});
const response = await magic.nft.checkout({
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
});
mockPromiEvent.emit(NftCheckoutIntermediaryEvents.Initiated, '0x1234');
expect(response.status).toBe('processed');
const requestPayload = magic.nft.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_nft_checkout');
expect(requestPayload.params).toMatchObject([
{
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
},
]);
});