Skip to content
Merged
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
46 changes: 46 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: E2E Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Create required files
run: |
touch dbinit.sql
cp env.example env.local.test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build application
run: npm run build

- name: Run e2e tests
run: make e2e-tests
timeout-minutes: 15

- name: Cleanup Docker containers
if: always()
run: |
docker compose down -v || true
docker system prune -f || true
41 changes: 26 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ endif
.PHONY: e2e-tests
e2e-tests: ## Start end2end tests
@make up &

@# wait until server is ready and the connection to the db is ready
@- while ! curl -s -f -LI http://localhost:8080/health >> /dev/null; do echo "waiting until server is ready for tests..." && sleep 3; done

@set -a && source env.local.test && set +a && npx jest ./tests/api_e2e --verbose true || true

@docker compose down

@echo "Done - Some important information for debugging:"
@echo " - If the tests fail, consider to refresh the db by running 'make down-db' first"
@echo " - To have data for spotify, apple, and anchor, use podcast_id 3 for the tests"
@UP_PID=$$!; \
echo "Starting services (PID: $$UP_PID)..."; \
trap 'docker compose down; kill $$UP_PID 2>/dev/null || true' EXIT; \
while ! curl -s -f -LI http://localhost:8080/health >> /dev/null; do \
echo "waiting until server is ready for tests..." && sleep 3; \
done; \
echo "Server is ready, running tests..."; \
set -a && source env.local.test && set +a && npx jest ./tests/api_e2e --verbose true; \
TEST_EXIT_CODE=$$?; \
docker compose down; \
echo "Done - Some important information for debugging:"; \
echo " - If the tests fail, consider to refresh the db by running 'make down' first"; \
echo " - To have data for spotify, apple, and anchor, use podcast_id 3 for the tests"; \
exit $$TEST_EXIT_CODE

.PHONY: status
status: ## Send status request
Expand All @@ -111,7 +114,15 @@ send-api-req-prod: ## Send request to production
db-shell: ## Opens the mysql shell inside the db container
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast'

.PHONY: test-one-e2e-%
test-one-e2e-%: ## Run end2end tests for a specific test case
@echo "Running end2end test for: $*"
npx jest ./tests/api_e2e --verbose true --testNamePattern="$*"
.PHONY: db-init-auth
db-init-auth: ## Initialize the auth db after api is up
# creates the auth schema
docker cp ./db_schema/auth.sql $$(docker compose ps -q db):/tmp/auth.sql
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth.sql'

# creates some dummy auth data
docker cp ./db_auth_data.sql $$(docker compose ps -q db):/tmp/auth_data.sql
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth_data.sql'
docker cp ./db_auth_data.sql api-db-1:/tmp/auth_data.sql
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth_data.sql'

Loading