mrapids 0.1.31

Your OpenAPI, but executable
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# MicroRapid Run Command - Complete Test Suite

## Overview
This comprehensive test suite covers all functionality of the simplified `mrapids run` command, from basic initialization to complex real-world scenarios.

## Prerequisites
- MicroRapid CLI installed (`mrapids`)
- Internet connection (for Petstore API)
- Unix-like environment (Mac/Linux) or Git Bash on Windows

## Test Environment Setup

### Step 1: Initialize Project
```bash
# Create a test directory and initialize with Petstore API
mkdir mrapids-test && cd mrapids-test
mrapids init --from-url https://petstore.swagger.io/v2/swagger.json --force

# Verify initialization
ls -la
# Expected: specs/, requests/, data/, .mrapids/
```

### Step 2: Analyze API and Generate Request Configs
```bash
# Analyze all operations to generate request examples
mrapids analyze --all

# Check generated files
ls requests/examples/
# Expected: get-pet-by-id.yaml, find-pets-by-status.yaml, etc.

ls data/examples/
# Expected: new-pet.json, new-user.json, etc.
```

## Test Cases

### 1. Discovery and Listing Operations
```bash
# See all available operations
mrapids list operations

# Filter by method
mrapids list operations --method GET
mrapids list operations --method POST

# Filter by keyword
mrapids list operations --filter pet
mrapids list operations --filter user
mrapids list operations --filter store

# List in different formats
mrapids list operations --format json
mrapids list operations --format simple
mrapids list operations --format table
```

### 2. Basic GET Operations (Direct Execution)
```bash
# Get pet by ID (direct operation)
mrapids run getPetById --id 10
mrapids run getPetById --id 1
mrapids run getPetById --id 2

# Find pets by status
mrapids run findPetsByStatus --status available
mrapids run findPetsByStatus --status pending
mrapids run findPetsByStatus --status sold

# With pagination
mrapids run findPetsByStatus --status available --limit 5
mrapids run findPetsByStatus --status available --limit 10 --offset 5

# Get store inventory
mrapids run getInventory

# Get user
mrapids run getUserByName --name user1
mrapids run getUserByName --name johndoe
```

### 3. Request Config File Execution
```bash
# Run using generated config files
mrapids run requests/examples/get-pet-by-id.yaml
mrapids run requests/examples/find-pets-by-status.yaml
mrapids run requests/examples/get-inventory.yaml
mrapids run requests/examples/get-user-by-name.yaml

# Override parameters in config
mrapids run requests/examples/get-pet-by-id.yaml --id 20
mrapids run requests/examples/find-pets-by-status.yaml --status sold
```

### 4. POST Operations - Creating Resources
```bash
# Create a new pet using default example
mrapids run addPet

# Create pet with inline JSON
mrapids run addPet --data '{
  "id": 1001,
  "name": "Fluffy",
  "category": {"id": 1, "name": "Dogs"},
  "photoUrls": ["http://example.com/photo1.jpg"],
  "tags": [{"id": 1, "name": "friendly"}],
  "status": "available"
}'

# Create pet from file
mrapids run addPet --file data/examples/new-pet.json

# Create using @ syntax
mrapids run addPet --data @data/examples/new-pet.json

# Create a new user
mrapids run createUser --data '{
  "id": 1001,
  "username": "testuser",
  "firstName": "Test",
  "lastName": "User",
  "email": "test@example.com",
  "password": "password123",
  "phone": "555-0123",
  "userStatus": 1
}'

# Create store order
mrapids run placeOrder --data '{
  "id": 1001,
  "petId": 10,
  "quantity": 1,
  "shipDate": "2024-01-15T10:00:00.000Z",
  "status": "placed",
  "complete": true
}'
```

### 5. PUT Operations - Updating Resources
```bash
# Update existing pet
mrapids run updatePet --data '{
  "id": 10,
  "name": "Updated Fluffy",
  "category": {"id": 1, "name": "Dogs"},
  "photoUrls": ["http://example.com/photo2.jpg"],
  "tags": [{"id": 1, "name": "friendly"}, {"id": 2, "name": "trained"}],
  "status": "sold"
}'

# Update with form data
mrapids run updatePetWithForm --id 10 --name "New Name" --status sold

# Update user
mrapids run updateUser --name testuser --data '{
  "id": 1001,
  "username": "testuser",
  "firstName": "Updated",
  "lastName": "User",
  "email": "updated@example.com",
  "password": "newpassword",
  "phone": "555-9999",
  "userStatus": 1
}'
```

### 6. DELETE Operations
```bash
# Delete a pet
mrapids run deletePet --id 1001

# Delete with API key header
mrapids run deletePet --id 1001 --api-key "special-key"

# Delete order
mrapids run deleteOrder --id 1001

# Delete user
mrapids run deleteUser --name testuser
```

### 7. Advanced Options Testing

#### 7.1 Verbose and Dry Run
```bash
# Verbose mode (see all request details)
mrapids run getPetById --id 10 --verbose

# Dry run (don't actually send)
mrapids run getPetById --id 10 --dry-run
mrapids run addPet --data @data/examples/new-pet.json --dry-run

# Show as curl command
mrapids run getPetById --id 10 --as-curl
mrapids run addPet --data @data/examples/new-pet.json --as-curl

# Both curl and dry run
mrapids run getPetById --id 10 --as-curl --dry-run
```

#### 7.2 Output Formats
```bash
# JSON output
mrapids run findPetsByStatus --status available --output json

# YAML output
mrapids run findPetsByStatus --status available --output yaml

# Table output (for arrays)
mrapids run findPetsByStatus --status available --output table

# Pretty output (default)
mrapids run getPetById --id 10 --output pretty

# Save to file
mrapids run getPetById --id 10 --save pet-10.json
mrapids run findPetsByStatus --status available --save available-pets.json
```

### 8. Headers and Authentication
```bash
# Custom headers
mrapids run getPetById --id 10 --header "X-Request-ID: 12345"
mrapids run getPetById --id 10 --header "X-Custom: value1" --header "X-Another: value2"

# Authorization header
mrapids run getPetById --id 10 --auth "Bearer eyJhbGciOiJIUzI1NiIsInR..."

# API key header
mrapids run getPetById --id 10 --api-key "my-secret-api-key"

# Multiple auth methods
mrapids run deletePet --id 10 --api-key "key123" --header "X-Tenant: tenant1"
```

### 9. Error Handling and Retries
```bash
# Test with non-existent resource
mrapids run getPetById --id 99999

# Test with invalid data
mrapids run addPet --data '{"invalid": "data"}'

# Retry on failure
mrapids run getPetById --id 10 --retry 3

# Custom timeout
mrapids run getPetById --id 10 --timeout 5
mrapids run getPetById --id 10 --timeout 60
```

### 10. Complex Query Parameters
```bash
# Multiple query parameters
mrapids run findPetsByTags --param tags=friendly --param tags=trained

# Generic parameters
mrapids run findPetsByStatus --param status=available --param limit=5

# Mix of specific and generic
mrapids run findPetsByStatus --status available --limit 10 --param sort=name

# Query parameters explicitly
mrapids run findPetsByStatus --query status=available --query limit=5
```

### 11. Environment Configuration
```bash
# Create environment config
mkdir -p config
cat > config/environments.yaml << 'EOF'
environments:
  dev:
    base_url: http://localhost:8080/v2
  staging:
    base_url: https://staging-petstore.swagger.io/v2
  production:
    base_url: https://petstore.swagger.io/v2
EOF

# Test with different environments
mrapids run getPetById --id 10 --env dev
mrapids run getPetById --id 10 --env staging
mrapids run getPetById --id 10 --env production

# Override URL directly
mrapids run getPetById --id 10 --url https://petstore3.swagger.io/api/v3
```

### 12. Template System
```bash
# Create a template
mkdir -p templates
cat > templates/get-pet.yaml << 'EOF'
operation: getPetById
method: GET
path: /pet/${PET_ID:10}
headers:
  Accept: application/json
  X-Request-ID: ${REQUEST_ID:default-id}
EOF

# Use template
mrapids run my-request --template get-pet --set PET_ID=20 --set REQUEST_ID=req-123
```

### 13. Stdin Input Testing
```bash
# Pipe data through stdin
echo '{"id":8888,"name":"StdinPet","status":"available"}' | mrapids run addPet --stdin

# From file through stdin
cat data/examples/new-pet.json | mrapids run addPet --stdin
```

### 14. End-to-End Workflow Testing

#### 14.1 Simple Workflow
```bash
# Create a workflow script
cat > test-workflow.sh << 'EOF'
#!/bin/bash
echo "๐Ÿš€ Starting E2E Pet Store Workflow"

# 1. Create a pet
echo "Step 1: Creating pet..."
PET_ID=$(mrapids run addPet --data '{"id":9999,"name":"WorkflowPet","status":"available"}' --output json | grep -o '"id":[0-9]*' | grep -o '[0-9]*')

# 2. Get the pet
echo "Step 2: Getting pet $PET_ID..."
mrapids run getPetById --id $PET_ID

# 3. Update pet status
echo "Step 3: Updating pet status..."
mrapids run updatePetWithForm --id $PET_ID --status sold

# 4. Find by status
echo "Step 4: Finding sold pets..."
mrapids run findPetsByStatus --status sold --limit 5

# 5. Delete the pet
echo "Step 5: Cleaning up - deleting pet..."
mrapids run deletePet --id $PET_ID

echo "โœ… Workflow complete!"
EOF

chmod +x test-workflow.sh
./test-workflow.sh
```

#### 14.2 Complex Business Workflow
```bash
# Pet Store Business Workflow
cat > business-workflow.sh << 'EOF'
#!/bin/bash

echo "๐Ÿช Pet Store Business Workflow"

# 1. Store opens - check inventory
echo "๐Ÿ“ฆ Checking morning inventory..."
mrapids run getInventory --save morning-inventory.json

# 2. Add new pets to inventory
echo "๐Ÿ• Adding new pets..."
mrapids run addPet --data '{"id":2001,"name":"Rex","category":{"id":1,"name":"Dogs"},"status":"available"}'
mrapids run addPet --data '{"id":2002,"name":"Mittens","category":{"id":2,"name":"Cats"},"status":"available"}'

# 3. Customer searches for available pets
echo "๐Ÿ” Customer searching for pets..."
mrapids run findPetsByStatus --status available --output table

# 4. Customer creates account
echo "๐Ÿ‘ค Creating customer account..."
mrapids run createUser --data '{
  "id": 3001,
  "username": "customer1",
  "firstName": "John",
  "lastName": "Doe",
  "email": "john@example.com",
  "password": "secret",
  "phone": "555-1234",
  "userStatus": 1
}'

# 5. Customer places order
echo "๐Ÿ›’ Placing order..."
mrapids run placeOrder --data '{
  "id": 4001,
  "petId": 2001,
  "quantity": 1,
  "shipDate": "2024-01-20T10:00:00.000Z",
  "status": "placed",
  "complete": false
}'

# 6. Update pet status to sold
echo "๐Ÿ’ฐ Marking pet as sold..."
mrapids run updatePetWithForm --id 2001 --status sold

# 7. Check end of day inventory
echo "๐Ÿ“Š End of day inventory check..."
mrapids run getInventory --save evening-inventory.json

echo "โœ… Business workflow complete!"
EOF

chmod +x business-workflow.sh
./business-workflow.sh
```

### 15. Error Scenarios and Edge Cases
```bash
# Missing required parameter
mrapids run getPetById
# Expected: Error about missing --id

# Invalid operation name
mrapids run nonExistentOperation
# Expected: List of available operations

# Malformed JSON
mrapids run addPet --data '{"broken": json'
# Expected: JSON parse error

# File not found
mrapids run addPet --file non-existent-file.json
# Expected: File not found error

# Invalid status value
mrapids run findPetsByStatus --status invalid_status
# Expected: API error or empty result

# GET request with body (should be ignored)
mrapids run getPetById --id 10 --data '{"test":"data"}'
# Expected: Body ignored for GET request
```

### 16. Performance Testing
```bash
# Test with large result sets
mrapids run findPetsByStatus --status available --limit 100

# Test timeout handling
mrapids run getPetById --id 10 --timeout 1

# Test retry mechanism
mrapids run getPetById --id 10 --retry 3 --timeout 2
```

### 17. Cleanup Operations
```bash
# List what would be cleaned
mrapids cleanup --dry-run

# Clean test artifacts
mrapids cleanup --test-artifacts

# Clean backup directories
mrapids cleanup --backups

# Clean empty directories
mrapids cleanup --empty-dirs

# Clean everything
mrapids cleanup --test-artifacts --backups --empty-dirs
```

## Automated Test Scripts

### Quick Smoke Test
```bash
cat > smoke-test.sh << 'EOF'
#!/bin/bash
set -e

echo "๐Ÿงช Running MicroRapid Smoke Tests"

# Test basic GET
echo "Test 1: Basic GET..."
mrapids run getPetById --id 10 --dry-run

# Test with parameters
echo "Test 2: Query parameters..."
mrapids run findPetsByStatus --status available --limit 3 --dry-run

# Test config file
echo "Test 3: Config file..."
mrapids run requests/examples/get-pet-by-id.yaml --dry-run

# Test output formats
echo "Test 4: Output formats..."
mrapids run getInventory --output json --dry-run

echo "โœ… Smoke tests passed!"
EOF

chmod +x smoke-test.sh
./smoke-test.sh
```

### Full Test Suite
```bash
cat > full-test.sh << 'EOF'
#!/bin/bash

PASS=0
FAIL=0

run_test() {
    echo -n "Testing: $1... "
    if $2 > /dev/null 2>&1; then
        echo "โœ… PASS"
        ((PASS++))
    else
        echo "โŒ FAIL"
        ((FAIL++))
    fi
}

echo "๐Ÿงช MicroRapid Comprehensive Test Suite"
echo "======================================"

# Basic Operations
run_test "GET by ID" "mrapids run getPetById --id 10 --dry-run"
run_test "GET with query" "mrapids run findPetsByStatus --status available --dry-run"
run_test "GET inventory" "mrapids run getInventory --dry-run"

# POST Operations
run_test "POST with data" "mrapids run addPet --dry-run --as-curl"

# Config Files
run_test "Config file execution" "mrapids run requests/examples/get-pet-by-id.yaml --dry-run"

# Output Formats
run_test "JSON output" "mrapids run getPetById --id 10 --output json --dry-run"
run_test "YAML output" "mrapids run getPetById --id 10 --output yaml --dry-run"

# Advanced Options
run_test "Verbose mode" "mrapids run getPetById --id 10 --verbose --dry-run"
run_test "Curl output" "mrapids run getPetById --id 10 --as-curl --dry-run"

# Headers
run_test "Custom headers" "mrapids run getPetById --id 10 --header 'X-Test: value' --dry-run"
run_test "Auth header" "mrapids run getPetById --id 10 --auth 'Bearer token' --dry-run"

echo "======================================"
echo "Results: $PASS passed, $FAIL failed"

if [ $FAIL -eq 0 ]; then
    echo "โœ… All tests passed!"
    exit 0
else
    echo "โŒ Some tests failed"
    exit 1
fi
EOF

chmod +x full-test.sh
./full-test.sh
```

## Validation Checklist

### Core Functionality
- [ ] Direct operation execution works
- [ ] Request config file execution works
- [ ] Parameter substitution works correctly
- [ ] Path parameters are mapped correctly
- [ ] Query parameters are added properly
- [ ] Request bodies are handled correctly

### Input Methods
- [ ] Inline JSON data works
- [ ] File input with --file works
- [ ] @ syntax for files works
- [ ] Stdin input works
- [ ] Default examples load correctly

### Output Options
- [ ] JSON format displays correctly
- [ ] YAML format displays correctly
- [ ] Table format works for arrays
- [ ] Pretty format (default) works
- [ ] Save to file works

### Advanced Features
- [ ] Verbose mode shows details
- [ ] Dry run prevents execution
- [ ] Curl command generation works
- [ ] Retry mechanism works
- [ ] Timeout is respected
- [ ] Custom headers are sent
- [ ] Authentication headers work

### Error Handling
- [ ] Missing parameters show helpful errors
- [ ] Invalid operations list alternatives
- [ ] File not found errors are clear
- [ ] Network errors are handled gracefully
- [ ] JSON parse errors are informative

## Expected Results

### Successful Test Indicators
1. All GET operations return data
2. POST operations create resources (or show correct curl in dry-run)
3. Config files execute without errors
4. Output formats render correctly
5. Error messages are helpful and clear

### Common Issues and Solutions

| Issue | Solution |
|-------|----------|
| "Operation not found" | Check operation name matches exactly |
| "Missing required parameter" | Add --id or other required params |
| "File not found" | Ensure file path is correct |
| "Connection refused" | Check API endpoint is accessible |
| "Invalid JSON" | Validate JSON syntax |

## Performance Benchmarks

Expected response times:
- Simple GET: < 1 second
- Complex query: < 2 seconds
- Large result set: < 5 seconds
- With retries: < timeout ร— (retry + 1)

## Conclusion

This test suite covers:
- โœ… All HTTP methods (GET, POST, PUT, DELETE)
- โœ… All input methods (inline, file, stdin)
- โœ… All output formats (json, yaml, table, pretty)
- โœ… Authentication methods
- โœ… Error scenarios
- โœ… Advanced features (retry, timeout, dry-run)
- โœ… Real-world workflows

Run the automated test scripts to validate your MicroRapid installation is working correctly.