Skip to content

Commit 5616b1b

Browse files
authored
test(e2e): update expected payment flow for multiple links (#1130)
1 parent 862c785 commit 5616b1b

3 files changed

Lines changed: 92 additions & 6 deletions

File tree

tests/e2e/fixtures/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const test = base.extend<Fixtures>({
2929
context: [
3030
async ({ browserName, channel }, use, testInfo) => {
3131
const context = await loadContext({ browserName, channel }, testInfo);
32+
await context.clock.install();
3233
await use(context);
3334
await context.close();
3435
},

tests/e2e/multiple.spec.ts

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MIN_PAYMENT_WAIT } from '@/background/config';
12
import { test, expect, DEFAULT_BUDGET } from './fixtures/connected';
23
import {
34
getWalletInfoCached,
@@ -53,7 +54,15 @@ const orderById = <T extends { id: string }>(a: T, b: T) =>
5354
a.id.localeCompare(b.id);
5455

5556
test.describe('should monetized site with multiple wallet address', () => {
56-
test('same currency', async ({ page, popup }) => {
57+
test('same currency', async ({ page, popup, background, context }) => {
58+
// At rateOfPay=3600, we pay $0.01 every second. But given minimum interval
59+
// is 2s, we'll need to wait for 2s.
60+
const rateOfPay = '3600';
61+
const interval = MIN_PAYMENT_WAIT;
62+
await background.evaluate((rateOfPay) => {
63+
return chrome.storage.local.set({ rateOfPay });
64+
}, rateOfPay);
65+
5766
const walletAddresses = [
5867
walletAddressUrl,
5968
walletAddressUrlSameCurrency,
@@ -65,11 +74,38 @@ test.describe('should monetized site with multiple wallet address', () => {
6574
);
6675

6776
await test.step('continuous payments', async () => {
68-
await expect(monetizationCallback).toHaveBeenCalledTimes(count);
77+
await expect(monetizationCallback).toHaveBeenCalledTimes(1);
78+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
79+
paymentPointer: walletAddresses[0],
80+
});
81+
82+
await context.clock.runFor(interval);
83+
await expect(monetizationCallback).toHaveBeenCalledTimes(2);
84+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
85+
paymentPointer: walletAddresses[1],
86+
});
87+
6988
expect(
7089
monetizationCallback.calls.map(([ev]) => ev.paymentPointer).sort(),
7190
'monetization callback is called once for each wallet address',
72-
).toEqual(walletAddresses);
91+
).toEqual([...walletAddresses].sort());
92+
93+
await context.clock.runFor(interval);
94+
await expect(monetizationCallback).toHaveBeenCalledTimes(3);
95+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
96+
paymentPointer: walletAddresses[0],
97+
});
98+
99+
await context.clock.runFor(interval);
100+
await expect(monetizationCallback).toHaveBeenCalledTimes(4);
101+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
102+
paymentPointer: walletAddresses[1],
103+
});
104+
105+
expect(
106+
monetizationCallback.calls.map(([ev]) => ev.paymentPointer).sort(),
107+
'monetization callback is called twice for each wallet address',
108+
).toEqual([...walletAddresses, ...walletAddresses].sort());
73109
});
74110

75111
await setContinuousPayments(popup, false);
@@ -101,7 +137,15 @@ test.describe('should monetized site with multiple wallet address', () => {
101137
});
102138
});
103139

104-
test('different currencies', async ({ page, popup, context }) => {
140+
test('different currencies', async ({ page, popup, background, context }) => {
141+
// At rateOfPay=3600, we pay $0.01 every second. But given minimum interval
142+
// is 2s, we'll need to wait for 2s.
143+
const rateOfPay = '3600';
144+
const interval = MIN_PAYMENT_WAIT;
145+
await background.evaluate((rateOfPay) => {
146+
return chrome.storage.local.set({ rateOfPay });
147+
}, rateOfPay);
148+
105149
const walletAddressesInfo = [
106150
walletInfoSameCurrency,
107151
walletInfoWeakerCurrency,
@@ -116,11 +160,50 @@ test.describe('should monetized site with multiple wallet address', () => {
116160
);
117161

118162
await test.step('continuous payments', async () => {
119-
await expect(monetizationCallback).toHaveBeenCalledTimes(count);
163+
await expect(monetizationCallback).toHaveBeenCalledTimes(1);
164+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
165+
paymentPointer: walletAddresses[0],
166+
});
167+
168+
await context.clock.runFor(interval);
169+
await expect(monetizationCallback).toHaveBeenCalledTimes(2);
170+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
171+
paymentPointer: walletAddresses[1],
172+
});
173+
174+
await context.clock.runFor(interval);
175+
await expect(monetizationCallback).toHaveBeenCalledTimes(3);
176+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
177+
paymentPointer: walletAddresses[2],
178+
});
179+
120180
expect(
121181
monetizationCallback.calls.map(([ev]) => ev.paymentPointer).sort(),
122182
'monetization callback is called once for each wallet address',
123-
).toEqual(walletAddresses);
183+
).toEqual([...walletAddresses].sort());
184+
185+
await context.clock.runFor(interval);
186+
await expect(monetizationCallback).toHaveBeenCalledTimes(4);
187+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
188+
paymentPointer: walletAddresses[0],
189+
});
190+
191+
await context.clock.runFor(interval);
192+
await expect(monetizationCallback).toHaveBeenCalledTimes(5);
193+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
194+
paymentPointer: walletAddresses[1],
195+
});
196+
197+
await context.clock.runFor(interval);
198+
await expect(monetizationCallback).toHaveBeenCalledTimes(6);
199+
await expect(monetizationCallback).toHaveBeenLastCalledWithMatching({
200+
paymentPointer: walletAddresses[2],
201+
});
202+
203+
expect(
204+
monetizationCallback.calls.map(([ev]) => ev.paymentPointer).sort(),
205+
'monetization callback is called twice for each wallet address',
206+
).toEqual([...walletAddresses, ...walletAddresses].sort());
124207
});
125208

126209
await setContinuousPayments(popup, false);

tests/e2e/reconnectAutoKeyTestWallet.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ test('Reconnect to test wallet with automatic key addition', async ({
2424
background,
2525
i18n,
2626
}) => {
27+
test.slow();
28+
2729
const walletAddressUrl = process.env.TEST_WALLET_ADDRESS_URL;
2830
const revokeInfo = await test.step('connect wallet', async () => {
2931
const connectButton = await test.step('fill popup', async () => {

0 commit comments

Comments
 (0)