diff --git a/.github/workflows/playwright-parallel-test.yml b/.github/workflows/playwright-parallel-test.yml new file mode 100644 index 00000000..38c156c8 --- /dev/null +++ b/.github/workflows/playwright-parallel-test.yml @@ -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 . + +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/test@1.34.3 + 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 + diff --git a/.gitignore b/.gitignore index 10bf3587..17ad7c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/subscribie/blueprints/admin/__init__.py b/subscribie/blueprints/admin/__init__.py index aa5534f3..cd247d74 100644 --- a/subscribie/blueprints/admin/__init__.py +++ b/subscribie/blueprints/admin/__init__.py @@ -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: @@ -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) @@ -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)) @@ -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: @@ -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]) @@ -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]) diff --git a/subscribie/blueprints/checkout/templates/new_customer.html b/subscribie/blueprints/checkout/templates/new_customer.html index 54f790b3..6394de71 100644 --- a/subscribie/blueprints/checkout/templates/new_customer.html +++ b/subscribie/blueprints/checkout/templates/new_customer.html @@ -166,7 +166,13 @@

{{ _('Choices') }}

- +