|
| 1 | +use serde_json::json; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn test_tenant_id_functionality_in_production() { |
| 5 | + let function_name = std::env::var("TENANT_ID_TEST_FUNCTION") |
| 6 | + .expect("TENANT_ID_TEST_FUNCTION environment variable not set"); |
| 7 | + |
| 8 | + // Test with tenant ID |
| 9 | + let payload_with_tenant = json!({ |
| 10 | + "test": "tenant_id_test", |
| 11 | + "message": "Testing with tenant ID" |
| 12 | + }); |
| 13 | + |
| 14 | + let output = std::process::Command::new("aws") |
| 15 | + .args([ |
| 16 | + "lambda", "invoke", |
| 17 | + "--function-name", &function_name, |
| 18 | + "--payload", &payload_with_tenant.to_string(), |
| 19 | + "--cli-binary-format", "raw-in-base64-out", |
| 20 | + "/tmp/tenant_response.json" |
| 21 | + ]) |
| 22 | + .output() |
| 23 | + .expect("Failed to invoke Lambda function"); |
| 24 | + |
| 25 | + assert!(output.status.success(), "Lambda invocation failed: {}", |
| 26 | + String::from_utf8_lossy(&output.stderr)); |
| 27 | + |
| 28 | + // Read and verify response |
| 29 | + let response = std::fs::read_to_string("/tmp/tenant_response.json") |
| 30 | + .expect("Failed to read response file"); |
| 31 | + |
| 32 | + let response_json: serde_json::Value = serde_json::from_str(&response) |
| 33 | + .expect("Failed to parse response JSON"); |
| 34 | + |
| 35 | + // Verify the function executed successfully |
| 36 | + assert_eq!(response_json["statusCode"], 200); |
| 37 | + |
| 38 | + // Parse the body to check tenant_id field exists (even if null) |
| 39 | + let body: serde_json::Value = serde_json::from_str( |
| 40 | + response_json["body"].as_str().expect("Body should be a string") |
| 41 | + ).expect("Failed to parse body JSON"); |
| 42 | + |
| 43 | + assert!(body.get("tenant_id").is_some(), "tenant_id field should be present in response"); |
| 44 | + assert!(body.get("request_id").is_some(), "request_id should be present"); |
| 45 | + assert_eq!(body["message"], "Tenant ID test successful"); |
| 46 | + |
| 47 | + println!("✅ Tenant ID production test passed"); |
| 48 | + println!("Response: {}", serde_json::to_string_pretty(&response_json).unwrap()); |
| 49 | +} |
0 commit comments