raps-cli 4.15.0

RAPS (rapeseed) - Rust Autodesk Platform Services CLI
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
//! Live API integration tests
//!
//! These tests hit the real APS API and require valid credentials.
//! Run with: `cargo test -p raps-cli --test live_api_tests -- --ignored`
//!
//! Required environment variables:
//! - APS_CLIENT_ID
//! - APS_CLIENT_SECRET
//!
//! Optional:
//! - APS_CALLBACK_URL (for 3-legged tests)
//! - APS_DA_NICKNAME (for Design Automation tests)

#![allow(deprecated)]

use assert_cmd::Command;
use predicates::prelude::PredicateBooleanExt;
use std::env;
use std::sync::Once;

static INIT: Once = Once::new();

/// Initialize test environment by loading .env file
fn init_env() {
    INIT.call_once(|| {
        // Try to load .env from the workspace root
        let _ = dotenvy::from_filename("../.env");
        // Also try from current directory
        let _ = dotenvy::dotenv();
    });
}

/// Check if credentials are available
fn has_credentials() -> bool {
    init_env();
    env::var("APS_CLIENT_ID").is_ok() && env::var("APS_CLIENT_SECRET").is_ok()
}

/// Get a command instance for the raps binary
fn raps() -> Command {
    Command::cargo_bin("raps").unwrap()
}

// ==================== AUTH TESTS ====================

/// Test 2-legged OAuth authentication
#[test]
#[ignore]
fn test_live_auth_test() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["auth", "test"])
        .assert()
        .success()
        .stdout(predicates::str::contains("success").or(predicates::str::contains("valid")));
}

/// Test auth status command
#[test]
#[ignore]
fn test_live_auth_status() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["auth", "status", "--output", "json"])
        .assert()
        .success();
}

// ==================== BUCKET TESTS ====================

/// Test bucket list (read-only, safe)
#[test]
#[ignore]
fn test_live_bucket_list() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["bucket", "list", "--output", "json"])
        .assert()
        .success();
}

/// Test bucket list with table output
#[test]
#[ignore]
fn test_live_bucket_list_table() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["bucket", "list", "--output", "table"])
        .assert()
        .success();
}

/// Test bucket info for non-existent bucket
#[test]
#[ignore]
fn test_live_bucket_info_not_found() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["bucket", "info", "nonexistent-bucket-12345xyz"])
        .assert()
        .failure();
}

// ==================== OBJECT TESTS ====================

/// Test object list on non-existent bucket
#[test]
#[ignore]
fn test_live_object_list_bucket_not_found() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["object", "list", "nonexistent-bucket-12345xyz"])
        .assert()
        .failure();
}

// ==================== WEBHOOK TESTS ====================

/// Test webhook events list (static data, always works)
#[test]
#[ignore]
fn test_live_webhook_events() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["webhook", "events"])
        .assert()
        .success()
        .stdout(predicates::str::contains("dm."));
}

/// Test webhook list
#[test]
#[ignore]
fn test_live_webhook_list() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["webhook", "list", "--output", "json"])
        .assert()
        .success();
}

// ==================== DESIGN AUTOMATION TESTS ====================

/// Test DA engines list
#[test]
#[ignore]
fn test_live_da_engines() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["da", "engines", "--output", "json"])
        .assert()
        .success()
        .stdout(predicates::str::contains("Autodesk"));
}

/// Test DA appbundles list
#[test]
#[ignore]
fn test_live_da_appbundles() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["da", "appbundles", "--output", "json"])
        .assert()
        .success();
}

/// Test DA activities list
#[test]
#[ignore]
fn test_live_da_activities() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["da", "activities", "--output", "json"])
        .assert()
        .success();
}

// ==================== TRANSLATE TESTS ====================

/// Test translate status for invalid URN
#[test]
#[ignore]
fn test_live_translate_status_invalid_urn() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    // Invalid URN should fail gracefully
    raps()
        .args(["translate", "status", "invalid-urn"])
        .assert()
        .failure();
}

// ==================== OUTPUT FORMAT TESTS ====================

/// Test JSON output for bucket list
#[test]
#[ignore]
fn test_live_output_json() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    let output = raps()
        .args(["bucket", "list", "--output", "json"])
        .output()
        .unwrap();

    if output.status.success() {
        let stdout = String::from_utf8_lossy(&output.stdout);
        // Should be valid JSON
        assert!(stdout.contains("[") || stdout.contains("{"));
    }
}

/// Test YAML output for bucket list
#[test]
#[ignore]
fn test_live_output_yaml() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    let output = raps()
        .args(["bucket", "list", "--output", "yaml"])
        .output()
        .unwrap();

    // Command should accept yaml output format
    assert!(
        output.status.success()
            || !String::from_utf8_lossy(&output.stderr).contains("invalid value 'yaml'")
    );
}

// ==================== VERBOSE/DEBUG FLAGS ====================

/// Test verbose flag with real API call
#[test]
#[ignore]
fn test_live_verbose_flag() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    let output = raps()
        .args(["--verbose", "bucket", "list"])
        .output()
        .unwrap();

    // Verbose output goes to stderr
    let stderr = String::from_utf8_lossy(&output.stderr);
    // Should show HTTP requests in verbose mode
    assert!(
        output.status.success() || stderr.contains("GET") || stderr.contains("POST"),
        "Verbose should show request info"
    );
}

/// Test debug flag with real API call
#[test]
#[ignore]
fn test_live_debug_flag() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    let output = raps().args(["--debug", "auth", "test"]).output().unwrap();

    // Debug mode should work (may show more info)
    assert!(output.status.success());
}

// ==================== TIMEOUT TESTS ====================

/// Test custom timeout
#[test]
#[ignore]
fn test_live_custom_timeout() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    raps()
        .args(["--timeout", "60", "bucket", "list"])
        .assert()
        .success();
}

// ==================== END-TO-END WORKFLOW TESTS ====================

/// Test full bucket create -> list -> delete workflow
/// WARNING: This creates and deletes a real bucket
#[test]
#[ignore]
fn test_live_bucket_workflow() {
    if !has_credentials() {
        eprintln!("Skipping: APS_CLIENT_ID and APS_CLIENT_SECRET not set");
        return;
    }

    // Generate unique bucket name
    let bucket_key = format!(
        "raps-test-{}",
        std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .unwrap()
            .as_millis()
            % 100000000
    );

    // Create bucket
    let create_result = raps()
        .args([
            "bucket",
            "create",
            "--key",
            &bucket_key,
            "--policy",
            "transient",
            "--output",
            "json",
            "--yes",
        ])
        .output()
        .unwrap();

    if !create_result.status.success() {
        eprintln!(
            "Bucket create failed (may already exist): {}",
            String::from_utf8_lossy(&create_result.stderr)
        );
        return;
    }

    println!("Created bucket: {}", bucket_key);

    // Verify bucket appears in list
    let list_result = raps()
        .args(["bucket", "list", "--output", "json"])
        .output()
        .unwrap();

    assert!(list_result.status.success());
    let stdout = String::from_utf8_lossy(&list_result.stdout);
    assert!(
        stdout.contains(&bucket_key),
        "Created bucket should appear in list"
    );

    // Get bucket info
    raps()
        .args(["bucket", "info", &bucket_key, "--output", "json"])
        .assert()
        .success();

    // Delete bucket
    raps()
        .args(["bucket", "delete", &bucket_key, "--yes"])
        .assert()
        .success();

    println!("Deleted bucket: {}", bucket_key);
}