Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1150 adding Next button to free plan and enforcing the free logic #1186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions .github/workflows/playwright-parallel-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
# When a push is made to a branch, deploy an instance of the app using
# that branch.
# The deployed url will be <branchname>.<domain>

name: playwright Parallel test
on:
pull_request:
# (pull_request_target get fired on external contributer pull requests)
#pull_request_target
paths-ignore:
- '**/README.md'
- '**/TESTING.md'
- 'docs/**'
jobs:
deploy-pr:
runs-on: ubuntu-22.04
timeout-minutes: 60
environment: testing
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- name: Dump context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo $GITHUB_CONTEXT
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: psf/black@stable # Fail early if fails Black code style
- name: Prepare runner with ssh keys
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
set -x
mkdir -p ~/.ssh
eval `ssh-agent -s`
ssh-add - <<< "$SSH_PRIVATE_KEY"
ssh-keyscan $DOKKU_HOST >> ~/.ssh/known_hosts
- name: Set subdomain (ensure is lowercase for dokku)
run: |
set -x
# Enforce max 60 chars, always end with alnum char
echo SUBDOMAIN=`echo "parallel-${{ github.head_ref }}" | tr '[:upper:]' '[:lower:]' | cut -c -50 | rev | sed 's/[^[:alnum:]]//1' | rev` >> $GITHUB_ENV
echo $GITHUB_ENV
- name: Create dokku app for pr branch if dosent already exist using dokku apps:create
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
set -x
echo The PR was raised by: ${{ github.event.pull_request.user.login }}
eval `ssh-agent -s`
ssh-add - <<< "$SSH_PRIVATE_KEY"
echo Creating dokku app ${{ env.SUBDOMAIN }}.pcpink.co.uk/
ssh dokku@$DOKKU_HOST -C "dokku apps:create ${{ env.SUBDOMAIN }}" | true
echo The url will be ${{ env.SUBDOMAIN }}.pcpink.co.uk
ssh dokku@$DOKKU_HOST -C "dokku git:initialize ${{ env.SUBDOMAIN }}"
ssh dokku@$DOKKU_HOST -C "dokku git:set ${{ env.SUBDOMAIN }} deploy-branch ${{ github.head_ref }}"
# set Stripe test keys as env vars dor dokku/docker
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_TEST_SECRET_KEY=${{ secrets.STRIPE_TEST_SECRET_KEY }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_TEST_PUBLISHABLE_KEY=${{ secrets.STRIPE_TEST_PUBLISHABLE_KEY }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST=${{ secrets.STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST }}"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} FLASK_ENV=development"
ssh dokku@$DOKKU_HOST -C "dokku config:set --no-restart ${{ env.SUBDOMAIN }} EMAIL_QUEUE_FOLDER=${{ secrets.DOKKU_EMAIL_QUEUE_FOLDER }}"
# mount email-queue folder
ssh dokku@$DOKKU_HOST -C "dokku storage:mount ${{ github.head_ref }} ${{ secrets.HOST_EMAIL_QUEUE_PATH }}:${{ secrets.DOKKU_EMAIL_QUEUE_FOLDER }} && dokku ps:restart ${{ github.head_ref }} || true"

- name: Deploy branch ${{ github.head_ref }} to dokku
uses: idoberko2/dokku-deploy-github-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
dokku-host: ${{ secrets.DOKKU_HOST }}
app-name: ${{ env.SUBDOMAIN }}
git-push-flags: '--force'
remote-branch: ${{ github.head_ref }}
- name: Merging branch with playwright parallel test branch
run: |
git config --global user.email ${{secrets.PLAYWRIGHT_EMAIL}}
git config --global user.name "github"
git merge origin/1048-parallel

- name: Click to see your PR web address
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DOKKU_HOST: ${{ secrets.DOKKU_HOST }}
run: |
echo Visit your pr here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk
- name: 'Comment PR with web address of application live preview'
uses: actions/github-script@v3
if: github.event_name == 'pull_request'
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "🙌 Live preview is here: http://${{ env.SUBDOMAIN }}.pcpink.co.uk"
})

- uses: actions/setup-node@v3

- uses: microsoft/playwright-github-action@v1

- name: Install node dependencies needed for Playwright browser tests
run: |
npm i -D @playwright/[email protected]
npx playwright install
sudo npx playwright install-deps

- name: Run & Record browser automated tests (Playwright)
env:
PLAYWRIGHT_HOST: http://${{ env.SUBDOMAIN }}.pcpink.co.uk/
PLAYWRIGHT_SLOWMO: 1000
PLAYWRIGHT_HEADLESS: true
SUBSCRIBER_EMAIL_HOST: ${{ secrets.SUBSCRIBER_EMAIL_HOST }}
SUBSCRIBER_EMAIL_USER: ${{ secrets.SUBSCRIBER_EMAIL_USER }}
SUBSCRIBER_EMAIL_PASSWORD: ${{ secrets.SUBSCRIBER_EMAIL_PASSWORD }}
EMAIL_SEARCH_API_HOST: ${{ secrets.EMAIL_SEARCH_API_HOST }}
RESET_PASSWORD_IMAP_SEARCH_SUBJECT: ${{ secrets.RESET_PASSWORD_IMAP_SEARCH_SUBJECT }}
IMAP_SEARCH_UNSEEN: "1"
IMAP_SEARCH_SINCE_DATE: "01-Sep-2021"
run: |
set -x
cp tests/browser-automated-tests-playwright/.env.example tests/browser-automated-tests-playwright/.env
cp .env.example .env
cd tests/browser-automated-tests-playwright; python3 run-playwright-tests.py

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ package-lock.json
test-results
tests/browser-automated-tests-playwright/index.spec.js-snapshots/*
tests/browser-automated-tests-playwright/worker*

tests/browser-automated-tests-playwright/tests/*spec.js-snapshots
21 changes: 15 additions & 6 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ def edit():
draftPlan.position = getPlan(form.position.data, index)
if getPlan(form.description.data, index) != "":
draftPlan.description = getPlan(escape(form.description.data), index)

if getPlan(form.subscription.data, index) == "yes":
plan_requirements.subscription = True
else:
Expand All @@ -548,8 +547,12 @@ def edit():
):
draftPlan.interval_unit = interval_unit

if getPlan(form.interval_amount.data, index, default=0) is None:
if (
getPlan(form.interval_amount.data, index, default=0) is None
or getPlan(form.interval_amount.data, index, default=0) == 0
):
interval_amount = 0
plan_requirements.subscription = False
else:
interval_amount = dec2pence(
getPlan(form.interval_amount.data, index, default=0)
Expand Down Expand Up @@ -585,8 +588,12 @@ def edit():

draftPlan.trial_period_days = trial_period_days

if getPlan(form.sell_price.data, index, default=0) is None:
if (
getPlan(form.sell_price.data, index, default=0) is None
or getPlan(form.sell_price.data, index, default=0) == 0
):
sell_price = 0
plan_requirements.instant_payment = False
else:
sell_price = dec2pence(getPlan(form.sell_price.data, index, default=0))

Expand Down Expand Up @@ -641,7 +648,6 @@ def add_plan():
or "weekly" in interval_unit
):
draftPlan.interval_unit = interval_unit

if form.subscription.data[0] == "yes":
plan_requirements.subscription = True
else:
Expand All @@ -668,8 +674,9 @@ def add_plan():

draftPlan.trial_period_days = trial_period_days

if form.interval_amount.data[0] is None:
if form.interval_amount.data[0] is None or form.interval_amount.data[0] == 0:
draftPlan.interval_amount = 0
plan_requirements.subscription = False
else:
draftPlan.interval_amount = dec2pence(form.interval_amount.data[0])

Expand All @@ -678,8 +685,10 @@ def add_plan():
else:
plan_requirements.instant_payment = False

if form.sell_price.data[0] is None:
if form.sell_price.data[0] is None or form.sell_price.data[0] == 0:
draftPlan.sell_price = 0
plan_requirements.instant_payment = False

else:
draftPlan.sell_price = dec2pence(form.sell_price.data[0])

Expand Down
8 changes: 7 additions & 1 deletion subscribie/blueprints/checkout/templates/new_customer.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ <h4 class="my-3">{{ _('Choices') }}</h4>
<!-- detect if embeded in iframe to trigger new tab if needed -->
<input type="hidden" name="is_iframe" id="is_iframe" value="" />
<!-- end detect if embeded in iframe to trigger new tab if needed -->
<input type=submit class="btn-primary-lg btn-block col-lg-8 my-3" value="{{ _('Continue to Payment') }}">
<input type=submit class="btn-primary-lg btn-block col-lg-8 my-3" value=
{% if plan.is_free() %}
"{{_('Next') }}"
{% else %}
"{{ _('Continue to Payment') }}"
{% endif %}
>

</form>
<script type="text/javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.describe("order free plan tests:", () => {
await page.fill('#city', 'London');
await page.fill('#postcode', 'L01 T3U');
expect(await page.screenshot()).toMatchSnapshot('freeplan-new-customer-form.png');
await page.click('text="Continue to Payment"');
await page.click('text="Next"');

// Verify get to the thank you page order complete
const order_complete_content = await page.textContent('.title-1');
Expand Down