mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add create subscription e2e test
This commit is contained in:
parent
c1d7d30f04
commit
8ceb7e0664
3 changed files with 75 additions and 6 deletions
64
tests/playwright/subscriptions-api.spec.js
Normal file
64
tests/playwright/subscriptions-api.spec.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
const {test, expect} = require('@playwright/test');
|
||||
const {
|
||||
WP_MERCHANT_USER,
|
||||
WP_MERCHANT_PASSWORD,
|
||||
AUTHORIZATION
|
||||
} = process.env;
|
||||
|
||||
async function loginAsAdmin(page) {
|
||||
await page.goto('/wp-admin');
|
||||
await page.locator('input[name="log"]').fill(WP_MERCHANT_USER);
|
||||
await page.locator('input[name="pwd"]').fill(WP_MERCHANT_PASSWORD);
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('text=Log In').click()
|
||||
]);
|
||||
}
|
||||
|
||||
test.describe('Merchant', () => {
|
||||
test('Create new subscription product', async ({page, request}) => {
|
||||
await loginAsAdmin(page);
|
||||
|
||||
const title = (Math.random() + 1).toString(36).substring(7);
|
||||
await page.goto('/wp-admin/post-new.php?post_type=product');
|
||||
await page.fill('#title', title);
|
||||
await page.selectOption('select#product-type', 'subscription');
|
||||
await page.fill('#_subscription_price', '10');
|
||||
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator('#publish').click(),
|
||||
]);
|
||||
|
||||
const message = await page.locator('.notice-success');
|
||||
await expect(message).toContainText('Product published.');
|
||||
|
||||
const products = await request.get('https://api.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', {
|
||||
headers: {
|
||||
'Authorization': AUTHORIZATION,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
expect(products.ok()).toBeTruthy();
|
||||
|
||||
const productList = await products.json();
|
||||
const product = productList.products.find((p) => {
|
||||
return p.name === title;
|
||||
});
|
||||
await expect(product.id).toBeTruthy;
|
||||
|
||||
const plans = await request.get(`https://api.sandbox.paypal.com/v1/billing/plans?product_id=${product.id}&page_size=10&page=1&total_required=true`, {
|
||||
headers: {
|
||||
'Authorization': AUTHORIZATION,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
expect(plans.ok()).toBeTruthy();
|
||||
|
||||
const planList = await plans.json();
|
||||
const plan = planList.plans.find((p) => {
|
||||
return p.product_id === product.id;
|
||||
});
|
||||
await expect(plan.id).toBeTruthy;
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue