Skip to content

Commit 213d628

Browse files
Merge pull request #55 from Adedayo-Data/test/smoke-compose-script
test(backend): add E2E smoke script for API flows (#50)
2 parents ef48274 + 9c61bb5 commit 213d628

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Nightly Smoke Test
2+
3+
on:
4+
schedule:
5+
# Runs at 00:00 UTC every day
6+
- cron: '0 0 * * *'
7+
workflow_dispatch: # Allows manual triggering
8+
9+
jobs:
10+
smoke-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: "20"
19+
cache: "npm"
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Build
25+
run: npm run build
26+
27+
- name: Start services (Docker Compose)
28+
run: docker-compose up -d
29+
30+
- name: Run Smoke Test
31+
run: ./scripts/smoke.sh http://localhost:3000
32+
33+
- name: Stop services
34+
if: always()
35+
run: docker-compose down

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,10 @@ streampay-backend/
122122
## License
123123

124124
MIT
125+
126+
## Smoke Testing
127+
To run the E2E smoke tests against a local Docker stack:
128+
1. `docker-compose up -d`
129+
2. `./scripts/smoke.sh http://localhost:3000`
130+
131+
**Prerequisites:** `curl` must be installed.

scripts/smoke.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Configuration
5+
API_URL=${1:-"http://localhost:3000"}
6+
MAX_RETRIES=30
7+
RETRY_INTERVAL=2
8+
9+
echo "Starting StreamPay Smoke Test against $API_URL..."
10+
11+
# 1. Wait for Health Check
12+
echo "Waiting for API to be healthy..."
13+
count=0
14+
until $(curl -sf "$API_URL/health" | grep -q "ok"); do
15+
if [ $count -eq $MAX_RETRIES ]; then
16+
echo "Error: API failed to become healthy in time."
17+
exit 1
18+
fi
19+
printf '.'
20+
sleep $RETRY_INTERVAL
21+
((count++))
22+
done
23+
echo -e "\n API is healthy!"
24+
25+
# 2. Test: List Streams (Happy Path)
26+
echo "Testing: List Streams..."
27+
LIST_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL/api/v1/streams")
28+
if [ "$LIST_RESPONSE" -ne 200 ]; then
29+
echo "Error: List Streams failed with status $LIST_RESPONSE"
30+
exit 1
31+
fi
32+
echo "List Streams success (200 OK)"
33+
34+
# 3. Test: Create Stream (Happy Path)
35+
echo "Testing: Create Stream..."
36+
# Note: Using dummy data - adjust keys based on your schema
37+
CREATE_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/api/v1/streams" \
38+
-H "Content-Type: application/json" \
39+
-d '{"sender": "test_user", "receiver": "dest_user", "amount": "100", "asset": "XLM"}')
40+
41+
if [ "$CREATE_RESPONSE" -ne 201 ] && [ "$CREATE_RESPONSE" -ne 200 ]; then
42+
echo "Error: Create Stream failed with status $CREATE_RESPONSE"
43+
exit 1
44+
fi
45+
echo "Create Stream success ($CREATE_RESPONSE)"
46+
47+
echo "Smoke Test Passed Successfully!"
48+
exit 0

0 commit comments

Comments
 (0)