Skip to content

Commit 035f613

Browse files
calebbourgclaude
andcommitted
refactor(sse-test-client): remove test environment dependency from ForceLogoutTest
- Remove unused test_env parameter from test_force_logout function - Skip test environment setup for ForceLogoutTest scenario - Fix force_logout cookie header to use 'id' instead of 'session_id' - Update README with new connection-test scenario documentation - Clarify permission requirements for each test scenario - Add example output for connection test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 57ea759 commit 035f613

File tree

4 files changed

+64
-26
lines changed

4 files changed

+64
-26
lines changed

sse-test-client/README.md

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,56 @@ A standalone Rust binary for testing Server-Sent Events (SSE) functionality with
77
This tool validates the SSE infrastructure by:
88
1. Authenticating two users (typically a coach and coachee)
99
2. Establishing SSE connections for both users
10-
3. Creating a test coaching relationship and session
10+
3. Optionally creating a test coaching relationship and session (for action tests)
1111
4. Triggering events (create/update/delete actions, force logout)
1212
5. Verifying that the correct SSE events are received by the appropriate users
1313

1414
## Prerequisites
1515

1616
- Backend server running (default: `http://localhost:4000`)
1717
- Two valid user accounts with credentials
18-
- Users must have permission to create coaching relationships
18+
- **For action tests only**: Users must have admin permission to create coaching relationships
19+
- **For connection test**: No special permissions required
1920

2021
## Usage
2122

2223
### Run Individual Test Scenarios
2324

2425
```bash
25-
# Test action creation
26+
# Test basic SSE connection (no admin permissions required)
27+
cargo run -p sse-test-client -- \
28+
--base-url http://localhost:4000 \
29+
--user1 "user1@example.com:password123" \
30+
--user2 "user2@example.com:password456" \
31+
--scenario connection-test
32+
33+
# Test action creation (requires admin permissions)
2634
cargo run -p sse-test-client -- \
2735
--base-url http://localhost:4000 \
2836
--user1 "coach@example.com:password123" \
2937
--user2 "coachee@example.com:password456" \
3038
--scenario action-create
3139

32-
# Test action update
40+
# Test action update (requires admin permissions)
3341
cargo run -p sse-test-client -- \
3442
--base-url http://localhost:4000 \
3543
--user1 "coach@example.com:password123" \
3644
--user2 "coachee@example.com:password456" \
3745
--scenario action-update
3846

39-
# Test action delete
47+
# Test action delete (requires admin permissions)
4048
cargo run -p sse-test-client -- \
4149
--base-url http://localhost:4000 \
4250
--user1 "coach@example.com:password123" \
4351
--user2 "coachee@example.com:password456" \
4452
--scenario action-delete
4553

46-
# Test force logout
54+
# Test force logout (requires admin permissions - NOT YET IMPLEMENTED)
4755
cargo run -p sse-test-client -- \
4856
--base-url http://localhost:4000 \
4957
--user1 "admin@example.com:adminpass" \
5058
--user2 "user@example.com:userpass" \
51-
--scenario force-logout
59+
--scenario force-logout-test
5260
```
5361

5462
### Run All Tests
@@ -74,11 +82,12 @@ cargo run -p sse-test-client -- \
7482

7583
## Available Scenarios
7684

77-
- `action-create` - Tests SSE events for action creation
78-
- `action-update` - Tests SSE events for action updates
79-
- `action-delete` - Tests SSE events for action deletion
80-
- `force-logout` - Tests SSE events for force logout
81-
- `all` - Runs all test scenarios sequentially
85+
- `connection-test` - Tests basic SSE connectivity without creating any data (no admin permissions required)
86+
- `action-create` - Tests SSE events for action creation (requires admin permissions)
87+
- `action-update` - Tests SSE events for action updates (requires admin permissions)
88+
- `action-delete` - Tests SSE events for action deletion (requires admin permissions)
89+
- `force-logout-test` - Tests SSE events for force logout (requires admin permissions, NOT YET IMPLEMENTED)
90+
- `all` - Runs all test scenarios sequentially (requires admin permissions for action tests)
8291

8392
## Command-Line Arguments
8493

@@ -94,16 +103,15 @@ cargo run -p sse-test-client -- \
94103

95104
### Setup Phase
96105
1. Authenticates both users and obtains session cookies
97-
2. Creates a coaching relationship between the two users
98-
3. Creates a coaching session within that relationship
106+
2. For action tests: Creates a coaching relationship and session between the users
107+
3. For connection test: Skips coaching data setup
99108
4. Establishes SSE connections for both users
100109

101110
### Test Phase
102111
For each scenario:
103-
1. User 1 triggers an action (e.g., creates an action)
104-
2. The tool waits for User 2 to receive the corresponding SSE event
105-
3. Validates that the event data matches expectations
106-
4. Records the test result (pass/fail) and duration
112+
1. **Connection Test**: Verifies SSE connections are established and remain stable
113+
2. **Action Tests**: User 1 triggers an action (e.g., creates an action), the tool waits for User 2 to receive the corresponding SSE event, and validates event data
114+
3. Records the test result (pass/fail) and duration
107115

108116
### Results Phase
109117
- Displays a summary of all test results
@@ -112,6 +120,40 @@ For each scenario:
112120

113121
## Example Output
114122

123+
### Connection Test (No Admin Required)
124+
```
125+
=== SETUP PHASE ===
126+
→ Authenticating users...
127+
✓ User 1 authenticated (ID: 123e4567-e89b-12d3-a456-426614174000)
128+
✓ User 2 authenticated (ID: 234e5678-e89b-12d3-a456-426614174001)
129+
130+
→ Skipping test environment setup (not needed for this test)
131+
132+
→ Establishing SSE connections...
133+
✓ User 1 SSE connection established
134+
✓ User 2 SSE connection established
135+
136+
=== TEST PHASE ===
137+
138+
=== TEST: Connection Test ===
139+
Testing basic SSE connectivity without creating any data
140+
✓ User 1 (123e4567-e89b-12d3-a456-426614174000) SSE connection: established
141+
✓ User 2 (234e5678-e89b-12d3-a456-426614174001) SSE connection: established
142+
→ Waiting 2 seconds to verify connections stay alive...
143+
✓ Connections remain stable
144+
✓ SSE infrastructure is working correctly
145+
146+
=== RESULTS ===
147+
=== TEST SUMMARY ===
148+
[PASS] connection_test (2.002086s)
149+
SSE connections established and maintained successfully
150+
151+
Results: 1 passed, 0 failed
152+
153+
All tests passed! ✓
154+
```
155+
156+
### Action Test (Requires Admin)
115157
```
116158
=== SETUP PHASE ===
117159
→ Authenticating users...

sse-test-client/src/api_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl ApiClient {
253253
let response = self
254254
.client
255255
.post(&url)
256-
.header("Cookie", format!("session_id={}", admin_session_cookie))
256+
.header("Cookie", format!("id={}", admin_session_cookie))
257257
.send()
258258
.await
259259
.context("Failed to force logout")?;

sse-test-client/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ async fn main() -> Result<()> {
9090
// Set up test environment only for scenarios that need coaching data
9191
let api_client = ApiClient::new(client.clone(), cli.base_url.clone());
9292
let test_env = match cli.scenario {
93-
ScenarioChoice::ConnectionTest => {
93+
ScenarioChoice::ConnectionTest | ScenarioChoice::ForceLogoutTest => {
9494
println!(
95-
"\n{} Skipping test environment setup (not needed for connection test)",
95+
"\n{} Skipping test environment setup (not needed for this test)",
9696
"→".blue()
9797
);
9898
None
@@ -162,12 +162,10 @@ async fn main() -> Result<()> {
162162
);
163163
}
164164
ScenarioChoice::ForceLogoutTest => {
165-
let env = test_env.as_ref().expect("Test environment required for ForceLogoutTest");
166165
results.push(
167166
scenarios::test_force_logout(
168167
&user1,
169168
&user2,
170-
env,
171169
&api_client,
172170
&mut sse1,
173171
&mut sse2,
@@ -227,18 +225,17 @@ async fn main() -> Result<()> {
227225
)
228226
.await?,
229227
);
230-
let env = test_env.as_ref().expect("Test environment required for All scenarios");
231228
results.push(
232229
scenarios::test_force_logout(
233230
&user1,
234231
&user2,
235-
env,
236232
&api_client,
237233
&mut sse1,
238234
&mut sse2,
239235
)
240236
.await?,
241237
);
238+
let env = test_env.as_ref().expect("Test environment required for All scenarios");
242239
results.push(
243240
scenarios::test_action_create(
244241
&user1,

sse-test-client/src/scenarios.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ pub async fn test_action_delete(
232232
pub async fn test_force_logout(
233233
user1: &AuthenticatedUser,
234234
user2: &AuthenticatedUser,
235-
_test_env: &TestEnvironment,
236235
api_client: &ApiClient,
237236
_sse1: &mut Connection,
238237
sse2: &mut Connection,

0 commit comments

Comments
 (0)