-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathtenant_id_prod_test.rs
More file actions
57 lines (47 loc) · 1.91 KB
/
Copy pathtenant_id_prod_test.rs
File metadata and controls
57 lines (47 loc) · 1.91 KB
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
use serde_json::json;
#[test]
fn test_tenant_id_functionality_in_production() {
let function_name =
std::env::var("TENANT_ID_TEST_FUNCTION").expect("TENANT_ID_TEST_FUNCTION environment variable not set");
// Test with tenant ID
let payload_with_tenant = json!({
"test": "tenant_id_test",
"message": "Testing with tenant ID"
});
let output = std::process::Command::new("aws")
.args([
"lambda",
"invoke",
"--function-name",
&function_name,
"--payload",
&payload_with_tenant.to_string(),
"--cli-binary-format",
"raw-in-base64-out",
"/tmp/tenant_response.json",
])
.output()
.expect("Failed to invoke Lambda function");
assert!(
output.status.success(),
"Lambda invocation failed: {}",
String::from_utf8_lossy(&output.stderr)
);
// Read and verify response
let response = std::fs::read_to_string("/tmp/tenant_response.json").expect("Failed to read response file");
let response_json: serde_json::Value = serde_json::from_str(&response).expect("Failed to parse response JSON");
// Verify the function executed successfully
assert_eq!(response_json["statusCode"], 200);
// Parse the body to check tenant_id field exists (even if null)
let body: serde_json::Value =
serde_json::from_str(response_json["body"].as_str().expect("Body should be a string"))
.expect("Failed to parse body JSON");
assert!(
body.get("tenant_id").is_some(),
"tenant_id field should be present in response"
);
assert!(body.get("request_id").is_some(), "request_id should be present");
assert_eq!(body["message"], "Tenant ID test successful");
println!("✅ Tenant ID production test passed");
println!("Response: {}", serde_json::to_string_pretty(&response_json).unwrap());
}