diff --git a/package-lock.json b/package-lock.json index c077df8c186..2c40a27dbd5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3484,9 +3484,9 @@ "dev": true }, "@woocommerce/api": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@woocommerce/api/-/api-0.1.2.tgz", - "integrity": "sha512-bK8kNN5sXnlZE2m72KrBnkkjsA9/0B2l/VLu5lhIuLunVZ3+mkqZGLMwATF2O09mR/EaA9tLMV0WftYWYujWiA==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@woocommerce/api/-/api-0.2.0.tgz", + "integrity": "sha512-h7PhFF+KPKZTxhvGASm0vn6N7nY3SFOEx0qJITvqaOwbqh3xvdDbiETSZ9R0BFNY5fD8blYCHblCO4VQ4CO9kA==", "dev": true, "requires": { "axios": "0.19.2", @@ -3994,9 +3994,9 @@ } }, "@woocommerce/e2e-utils": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@woocommerce/e2e-utils/-/e2e-utils-0.1.4.tgz", - "integrity": "sha512-7MZKT1hgaJWyF66YTxQvBUIgXiAuw4BNJOCX1hkWbeTEUNRp6jIXcePzHReNH4b3IXGYhS/BIqD0vKrxqg17Vw==", + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@woocommerce/e2e-utils/-/e2e-utils-0.1.5.tgz", + "integrity": "sha512-2dD3ZTyMhbQT8YXUYWF9rwmosieo6kE9zgYA7W8h2GmZVcluDvET9i5yUw5MmTq4y5MVhGf5xWZOjZLzNlwjUA==", "dev": true, "requires": { "@wordpress/deprecated": "^2.10.0", @@ -13289,9 +13289,9 @@ } }, "fishery": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/fishery/-/fishery-1.2.0.tgz", - "integrity": "sha512-0GG029KHF3p8Q0NiAl/ZOK1fvyAprOiHdtRWUNS46x9QXuQhMwzcGLNDbZ7XIEEBowwBmMsw7StkaU0ek9dSbg==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/fishery/-/fishery-1.3.1.tgz", + "integrity": "sha512-Oto2fALKmpijLbNAMHvFTrbIPPn9Ds7olDl17qFU8d9eEiro/32wF3V/6Gq0ApabyYP+VhySKqQLiCtJPMeP1A==", "dev": true, "requires": { "lodash.mergewith": "^4.6.2" diff --git a/package.json b/package.json index 0a963b83e0f..2135ccd6d40 100644 --- a/package.json +++ b/package.json @@ -90,11 +90,11 @@ "@types/react": "16.14.5", "@typescript-eslint/eslint-plugin": "4.15.2", "@typescript-eslint/parser": "4.15.2", - "@woocommerce/api": "^0.1.2", + "@woocommerce/api": "^0.2.0", "@woocommerce/components": "5.1.2", "@woocommerce/currency": "3.0.0", "@woocommerce/date": "2.1.0", - "@woocommerce/e2e-utils": "^0.1.4", + "@woocommerce/e2e-utils": "^0.1.5", "@woocommerce/eslint-plugin": "1.1.0", "@woocommerce/experimental": "1.2.0", "@wordpress/api-fetch": "3.3.0", diff --git a/tests/e2e/env/setup.sh b/tests/e2e/env/setup.sh index 1c6d5498446..a71e078463e 100755 --- a/tests/e2e/env/setup.sh +++ b/tests/e2e/env/setup.sh @@ -194,6 +194,9 @@ else echo "Skipping install of WooCommerce Subscriptions" fi +echo "Installing basic auth plugin for interfacing with the API" +cli wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate + echo "Setting redirection to local server" # host.docker.internal is not available in linux. Use ip address for docker0 interface to redirect requests from container. diff --git a/tests/e2e/specs/subscriptions/purchase-sign-up-fee-subscription.spec.js b/tests/e2e/specs/subscriptions/purchase-sign-up-fee-subscription.spec.js new file mode 100644 index 00000000000..7e7b52e6ee4 --- /dev/null +++ b/tests/e2e/specs/subscriptions/purchase-sign-up-fee-subscription.spec.js @@ -0,0 +1,71 @@ +/** + * External dependencies + */ +import config from 'config'; + +const { merchant, shopper, withRestApi } = require( '@woocommerce/e2e-utils' ); + +import { RUN_SUBSCRIPTIONS_TESTS, describeif, merchantWCP } from '../../utils'; + +import { fillCardDetails, setupCheckout } from '../../utils/payments'; + +const productName = 'Subscription signup fee product'; +const productSlug = 'subscription-signup-fee-product'; + +const customerBilling = config.get( 'addresses.customer.billing' ); + +describeif( RUN_SUBSCRIPTIONS_TESTS )( + 'Subscriptions > Purchase subscription with signup fee', + () => { + beforeAll( async () => { + await merchant.login(); + + // Create subscription product with signup fee + await merchantWCP.createSubscriptionProduct( productName, true ); + + await merchant.logout(); + } ); + + afterAll( async () => { + await merchant.logout(); + + // Delete the user created with the subscription + await withRestApi.deleteCustomerByEmail( customerBilling.email ); + } ); + + it( 'should be able to purchase a subscription with signup fee', async () => { + // Open the subscription product we created in the store + await page.goto( config.get( 'url' ) + `product/${ productSlug }`, { + waitUntil: 'networkidle0', + } ); + + // Add it to the cart and proceed to check out + await expect( page ).toClick( '.single_add_to_cart_button' ); + await page.waitForNavigation( { waitUntil: 'networkidle0' } ); + + await setupCheckout( customerBilling ); + + const card = config.get( 'cards.basic' ); + await fillCardDetails( page, card ); + await shopper.placeOrder(); + await expect( page ).toMatch( 'Order received' ); + } ); + + it( 'should have an active subscription', async () => { + await merchant.login(); + + await merchantWCP.openSubscriptions(); + + // Verify we have an active subscription for the product + await expect( page ).toMatchElement( '.subscription-status', { + text: 'Active', + } ); + await expect( page ).toMatchElement( '.order-item', { + text: productName, + } ); + await expect( page ).toMatchElement( '.recurring_total', { + text: '$9.99 / month', + } ); + } ); + } +); diff --git a/tests/e2e/specs/subscriptions/subscription-settings.spec.js b/tests/e2e/specs/subscriptions/subscription-settings.spec.js index c1e8a13b83e..aab92cfc489 100644 --- a/tests/e2e/specs/subscriptions/subscription-settings.spec.js +++ b/tests/e2e/specs/subscriptions/subscription-settings.spec.js @@ -5,9 +5,7 @@ import config from 'config'; const { merchant } = require( '@woocommerce/e2e-utils' ); -import { RUN_SUBSCRIPTIONS_TESTS } from '../../utils'; - -const describeif = ( condition ) => ( condition ? describe : describe.skip ); +import { RUN_SUBSCRIPTIONS_TESTS, describeif } from '../../utils'; describeif( RUN_SUBSCRIPTIONS_TESTS )( 'WooCommerce > Settings > Subscriptions', diff --git a/tests/e2e/utils/flows.js b/tests/e2e/utils/flows.js index 35afc96fb4e..8e529ba72b3 100644 --- a/tests/e2e/utils/flows.js +++ b/tests/e2e/utils/flows.js @@ -5,12 +5,18 @@ /** * External dependencies */ + +const { merchant, verifyAndPublish } = require( '@woocommerce/e2e-utils' ); + const config = require( 'config' ); const baseUrl = config.get( 'url' ); const SHOP_MY_ACCOUNT_PAGE = baseUrl + 'my-account/'; const MY_ACCOUNT_PAYMENT_METHODS = baseUrl + 'my-account/payment-methods'; +const WC_SUBSCRIPTIONS_PAGE = + baseUrl + 'wp-admin/edit.php?post_type=shop_subscription'; + export const RUN_SUBSCRIPTIONS_TESTS = '1' !== process.env.SKIP_WC_SUBSCRIPTIONS_TESTS; @@ -70,3 +76,33 @@ export const paymentsShopper = { await expect( page ).toClick( '#createaccount' ); }, }; + +export const merchantWCP = { + openSubscriptions: async () => { + await page.goto( WC_SUBSCRIPTIONS_PAGE, { + waitUntil: 'networkidle0', + } ); + await expect( page ).toMatchElement( 'h1', { text: 'Subscriptions' } ); + }, + + // Create a subscription product with an optional signup fee + createSubscriptionProduct: async ( + productName, + includeSignupFee = false + ) => { + // Go to "add product" page + await merchant.openNewProduct(); + + // Make sure we're on the add product page + await expect( page.title() ).resolves.toMatch( 'Add new product' ); + await expect( page ).toFill( '#title', productName ); + await expect( page ).toSelect( '#product-type', 'Simple subscription' ); + await expect( page ).toFill( '#_subscription_price', '9.99' ); + + if ( includeSignupFee ) { + await expect( page ).toFill( '#_subscription_sign_up_fee', '1.99' ); + } + + await verifyAndPublish(); + }, +}; diff --git a/tests/e2e/utils/helpers.js b/tests/e2e/utils/helpers.js index 1961d5b2e3b..ad101e70733 100644 --- a/tests/e2e/utils/helpers.js +++ b/tests/e2e/utils/helpers.js @@ -7,3 +7,7 @@ export const uiLoaded = async () => { () => ! Boolean( document.querySelector( '.is-loadable-placeholder' ) ) ); }; + +// Conditionally determine whether or not to skip a test suite +export const describeif = ( condition ) => + condition ? describe : describe.skip; diff --git a/tests/e2e/utils/payments.js b/tests/e2e/utils/payments.js index cfaeb60334f..515fd2a16f1 100644 --- a/tests/e2e/utils/payments.js +++ b/tests/e2e/utils/payments.js @@ -52,9 +52,15 @@ export async function confirmCardAuthentication( await button.click(); } +// Set up checkout with simple product export async function setupProductCheckout( billingDetails ) { await shopper.goToShop(); await shopper.addToCartFromShopPage( config.get( 'products.simple.name' ) ); + await setupCheckout( billingDetails ); +} + +// Set up checkout +export async function setupCheckout( billingDetails ) { await shopper.goToCheckout(); await uiUnblocked(); await shopper.fillBillingDetails( billingDetails );