Skip to content

Commit

Permalink
Added tests and workflows for sub product with signup fee (#1809)
Browse files Browse the repository at this point in the history
* Added tests and workflows for sub product with signup fee

* Break out function

* Minor change to setup checkout function

* Update API and e2e utils packages and delete user via rest API
  • Loading branch information
zhongruige authored May 25, 2021
1 parent 56b0e2b commit 6fb8d94
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 14 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/env/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
} );
} );
}
);
4 changes: 1 addition & 3 deletions tests/e2e/specs/subscriptions/subscription-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
36 changes: 36 additions & 0 deletions tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
},
};
4 changes: 4 additions & 0 deletions tests/e2e/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 6 additions & 0 deletions tests/e2e/utils/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 6fb8d94

Please sign in to comment.