From 73f0c4c1023da7623a83f912de77d4e31c98d512 Mon Sep 17 00:00:00 2001 From: vincanger <70215737+vincanger@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:22:38 +0100 Subject: [PATCH] add .env file and test stripe webhook --- .github/workflows/e2e-tests.yml | 79 +++++++++++++++++++++++++++ .github/workflows/opensaas-ci.yml | 44 --------------- app/package.json | 3 +- app/playwright/tests/whatever.spec.ts | 2 - 4 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/e2e-tests.yml delete mode 100644 .github/workflows/opensaas-ci.yml diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 00000000..9788e98d --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,79 @@ +name: e2e tests + +on: + push: + branches: + - main + - playwright-tests + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + + - name: Install Wasp + run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s + + - name: Docker setup + uses: docker/setup-buildx-action@v1 + + - name: Cache Node Modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: node-modules-${{ hashFiles('app/package-lock.json') }} + + - name: Install Node.js dependencies + run: | + cd app + npm ci + + - name: Install Stripe CLI + run: | + curl -o- https://raw.githubusercontent.com/stripe/stripe-cli/master/install.sh | bash + + - name: Start Stripe webhook listener + env: + STRIPE_KEY: ${{ secrets.STRIPE_KEY }} + STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }} + HOBBY_SUBSCRIPTION_PRICE_ID: ${{ secrets.HOBBY_SUBSCRIPTION_PRICE_ID }} + PRO_SUBSCRIPTION_PRICE_ID: ${{ secrets.PRO_SUBSCRIPTION_PRICE_ID }} + run: | + stripe listen --forward-to localhost:3001/stripe-webook & + + - name: Test Stripe webhook listener + run: | + RESPONSE=$(curl -so -w "%{http_code}" -X POST http://localhost:3000/webhook-path) + if [ $RESPONSE -ne 200 ]; then + echo "Webhook listener is not active" + exit 1 + fi + + - name: Setup other Env Vars + run: | + cd app + cp .env.server.example .env.server + + - name: Commit and push if it's not up-to-date + run: | + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git add -f .env.server + git commit -m "Add .env.server file" -a || echo "No changes to commit" + git push + + - name: Set up Playwright + run: | + cd app + npx playwright install --with-deps + + - name: Run Playwright tests + env: + run: | + cd app + DEBUG=pw:webserver npx playwright test tests/whatever.spec.ts \ No newline at end of file diff --git a/.github/workflows/opensaas-ci.yml b/.github/workflows/opensaas-ci.yml deleted file mode 100644 index e2ef3453..00000000 --- a/.github/workflows/opensaas-ci.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: e2e tests - -on: - push: - branches: - - main - - playwright-tests - pull_request: - branches: - - main - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout the repo - uses: actions/checkout@v3 - - - name: Install Wasp - run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s - - - name: Docker setup - uses: docker/setup-buildx-action@v1 - - - name: Cache Node Modules - uses: actions/cache@v3 - with: - path: ~/.npm - key: node-modules-${{ hashFiles('app/package-lock.json') }} - - - name: Install Node.js dependencies - run: | - cd app - npm ci - - - name: Set up Playwright - run: | - cd app - npx playwright install --with-deps - - - name: Run Playwright tests - run: | - cd app - DEBUG=pw:webserver npx playwright test tests/whatever.spec.ts \ No newline at end of file diff --git a/app/package.json b/app/package.json index 324ae298..bcdeabde 100644 --- a/app/package.json +++ b/app/package.json @@ -3,9 +3,8 @@ "scripts": { "example-app:start": "node ci-start-app.js", "example-app:start-db": "npm run example-app:cleanup-db && wasp start db", - "example-app:start-app": "npm run example-app:wait-for-db && npm run example-app:prepare-env && wasp db migrate-dev && wasp start", + "example-app:start-app": "npm run example-app:wait-for-db && wasp db migrate-dev && wasp start", "example-app:wait-for-db": "sleep 5 && ./node_modules/.bin/wait-port 5432", - "example-app:prepare-env": "cp .env.server.example .env.server", "example-app:cleanup-db": "(docker container rm $(docker container ls -f name=^wasp-dev-db-OpenSaaS- -q) -f || true) && docker volume rm $(docker volume ls -f name=^wasp-dev-db-OpenSaaS- -q) -f || true" }, "dependencies": { diff --git a/app/playwright/tests/whatever.spec.ts b/app/playwright/tests/whatever.spec.ts index 73aefdb1..4a7b41a7 100644 --- a/app/playwright/tests/whatever.spec.ts +++ b/app/playwright/tests/whatever.spec.ts @@ -81,5 +81,3 @@ test('demo-app', async ({ page }) => { // expect to find text "turtle" in a span element expect(page.getByText('turtle')).toBeTruthy(); }); - -// \ No newline at end of file