Skip to content

Commit 79879ec

Browse files
author
root
committed
test: add playwright lifecycle flow
1 parent 0ca9ad1 commit 79879ec

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

tests/e2e/fairshare.spec.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,84 @@ test('view activity after expense and settlement', async ({ request, baseURL })
114114
expect(activityPayload.some((item) => item.type === 'expense_created')).toBeTruthy();
115115
expect(activityPayload.some((item) => item.type === 'settlement_created')).toBeTruthy();
116116
});
117+
118+
test('end-to-end lifecycle flow', async ({ request, baseURL }) => {
119+
test.skip(process.env.RUN_E2E !== 'true', 'Set RUN_E2E=true to run backend e2e flow');
120+
test.skip(!baseURL, 'Base URL is required');
121+
122+
const emailPayer = randomEmail();
123+
const emailParticipant = randomEmail();
124+
const password = 'Password123';
125+
let participantId = '';
126+
127+
await test.step('register two users', async () => {
128+
const registerPayer = await request.post('/auth/register', {
129+
data: { name: 'Payer', email: emailPayer, password },
130+
});
131+
expect(registerPayer.ok()).toBeTruthy();
132+
133+
const registerParticipant = await request.post('/auth/register', {
134+
data: { name: 'Participant', email: emailParticipant, password },
135+
});
136+
expect(registerParticipant.ok()).toBeTruthy();
137+
const participantPayload = await registerParticipant.json();
138+
participantId = participantPayload.user.id as string;
139+
});
140+
141+
const login = await request.post('/auth/login', {
142+
data: { email: emailPayer, password },
143+
});
144+
expect(login.ok()).toBeTruthy();
145+
const loginPayload = await login.json();
146+
const token = loginPayload.accessToken as string;
147+
const authHeaders = { Authorization: `Bearer ${token}` };
148+
const payerId = loginPayload.user.id as string;
149+
150+
const groupResp = await request.post('/groups', {
151+
headers: authHeaders,
152+
data: { name: 'Lifecycle Group', currency: 'USD' },
153+
});
154+
expect(groupResp.ok()).toBeTruthy();
155+
const group = await groupResp.json();
156+
157+
const invite = await request.post(`/groups/${group.id}/invite`, {
158+
headers: authHeaders,
159+
data: { email: emailParticipant },
160+
});
161+
expect(invite.ok()).toBeTruthy();
162+
163+
await test.step('add expense', async () => {
164+
const expense = await request.post(`/groups/${group.id}/expenses`, {
165+
headers: authHeaders,
166+
data: {
167+
payerId,
168+
description: 'Lifecycle Expense',
169+
totalAmountCents: '2000',
170+
currency: 'USD',
171+
splits: [
172+
{ userId: payerId, owedAmountCents: '1000', paidAmountCents: '2000' },
173+
{ userId: participantId, owedAmountCents: '1000', paidAmountCents: '0' },
174+
],
175+
},
176+
});
177+
expect(expense.ok()).toBeTruthy();
178+
});
179+
180+
await test.step('simplify & settle', async () => {
181+
const suggestions = await request.get(`/groups/${group.id}/simplify`, { headers: authHeaders });
182+
expect(suggestions.ok()).toBeTruthy();
183+
const suggestionPayload = (await suggestions.json()) as Array<{ fromUserId: string; toUserId: string; amountCents: string }>;
184+
const firstSuggestion = suggestionPayload[0];
185+
expect(firstSuggestion).toBeTruthy();
186+
187+
const settle = await request.post(`/groups/${group.id}/settlements`, {
188+
headers: authHeaders,
189+
data: {
190+
payerId: firstSuggestion.fromUserId,
191+
receiverId: firstSuggestion.toUserId,
192+
amountCents: firstSuggestion.amountCents,
193+
},
194+
});
195+
expect(settle.ok()).toBeTruthy();
196+
});
197+
});

0 commit comments

Comments
 (0)