forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert thirdparty donation tests to Playwright (freeCodeCamp#5…
- Loading branch information
Showing
5 changed files
with
145 additions
and
39 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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
{ | ||
"id": "pm_1PRWUAFI1KEgscdTFyjUCbcd", | ||
"object": "payment_method", | ||
"allow_redisplay": "unspecified", | ||
"billing_details": { | ||
"address": { | ||
"city": null, | ||
"country": null, | ||
"line1": null, | ||
"line2": null, | ||
"postal_code": null, | ||
"state": null | ||
}, | ||
"email": null, | ||
"name": null, | ||
"phone": null | ||
}, | ||
"card": { | ||
"brand": "visa", | ||
"checks": { | ||
"address_line1_check": null, | ||
"address_postal_code_check": null, | ||
"cvc_check": null | ||
}, | ||
"country": "US", | ||
"display_brand": "visa", | ||
"exp_month": 10, | ||
"exp_year": 2025, | ||
"funding": "credit", | ||
"generated_from": null, | ||
"last4": "4242", | ||
"networks": { | ||
"available": [ | ||
"visa" | ||
], | ||
"preferred": null | ||
}, | ||
"three_d_secure_usage": { | ||
"supported": true | ||
}, | ||
"wallet": null | ||
}, | ||
"created": 1718357514, | ||
"customer": null, | ||
"livemode": false, | ||
"radar_options": {}, | ||
"type": "card" | ||
} |
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,75 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
import stripeJson from './fixtures/donation/stripe.json'; | ||
|
||
test.describe('third-party donation tests', () => { | ||
test.use({ storageState: 'playwright/.auth/certified-user.json' }); | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/donate'); | ||
}); | ||
|
||
test('All elements are present in the widget', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Donate', exact: true }).click(); | ||
|
||
// Paypal button should be present | ||
|
||
const paypalButtonIframe = page.frameLocator('.component-frame'); | ||
const paypalButton = paypalButtonIframe.getByRole('link'); | ||
await expect(paypalButton).toBeVisible(); | ||
await expect(paypalButton).toHaveAttribute('aria-label', 'PayPal'); | ||
|
||
// Patreon button should be present | ||
|
||
const patreonButton = page.locator('.patreon-button'); | ||
await expect(patreonButton).toBeVisible(); | ||
|
||
// "Or dontate with card" button should be present | ||
|
||
await expect(page.getByText('Or donate with card')).toBeVisible(); | ||
}); | ||
|
||
test('It is possible to donate with a card', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Donate', exact: true }).click(); | ||
|
||
const cardNumberIframe = page | ||
.frameLocator('iframe[src*="elements-inner-card"]') | ||
.nth(0); | ||
|
||
const cardExpiryIframe = page | ||
.frameLocator('iframe[src*="elements-inner-card"]') | ||
.nth(1); | ||
|
||
await cardNumberIframe | ||
.locator('input[data-elements-stable-field-name="cardNumber"]') | ||
.fill('4242424242424242'); | ||
|
||
await cardExpiryIframe | ||
.locator('input[data-elements-stable-field-name="cardExpiry"]') | ||
.fill('1025'); | ||
|
||
await page.getByRole('button', { name: 'Donate', exact: true }).click(); | ||
|
||
await page.route( | ||
'https://api.stripe.com/v1/payment_methods', | ||
async route => { | ||
await route.fulfill({ json: stripeJson }); | ||
} | ||
); | ||
|
||
await page.route( | ||
'http://localhost:3000/donate/charge-stripe-card', | ||
async route => { | ||
await route.fulfill({ json: { isDonating: true } }); | ||
} | ||
); | ||
|
||
await expect(page.getByRole('alert')).toBeVisible(); | ||
|
||
await expect(page.getByRole('alert')).toContainText( | ||
'Your donations will support free technology education for people all over the world.' | ||
); | ||
await expect(page.getByRole('alert')).toContainText( | ||
'Visit supporters page to learn about your supporter benefits.' | ||
); | ||
}); | ||
}); |