|
1 | | -// Test to verify that DTO fields serialize as camelCase |
| 1 | +// Test to verify that DTO fields serialize as camelCase. |
| 2 | +// |
| 3 | +// These tests construct real Rust DTO types and verify that serde |
| 4 | +// serializes their fields using camelCase, catching regressions in |
| 5 | +// the `#[serde(rename_all = "camelCase")]` annotations. |
2 | 6 |
|
3 | | -use serde_json::json; |
| 7 | +use drasi_lib::config::QueryLanguage; |
| 8 | +use drasi_server::api::models::observability::{ |
| 9 | + ComponentEventDto, ComponentStatusDto, ComponentTypeDto, LogLevelDto, LogMessageDto, |
| 10 | +}; |
| 11 | +use drasi_server::api::models::queries::query::{QueryConfigDto, SourceSubscriptionConfigDto}; |
4 | 12 |
|
5 | 13 | #[test] |
6 | | -fn test_postgres_dto_serializes_camelcase() { |
7 | | - let json = json!({ |
8 | | - "host": "localhost", |
9 | | - "port": 5432, |
10 | | - "database": "testdb", |
11 | | - "user": "testuser", |
12 | | - "password": "testpass", |
13 | | - "tables": [], |
14 | | - "slotName": "test_slot", |
15 | | - "publicationName": "test_pub", |
16 | | - "sslMode": "disable", |
17 | | - "tableKeys": [] |
18 | | - }); |
| 14 | +fn test_query_config_dto_serializes_camelcase() { |
| 15 | + let dto = QueryConfigDto { |
| 16 | + id: "test-query".to_string(), |
| 17 | + auto_start: true, |
| 18 | + query: "MATCH (n) RETURN n".to_string(), |
| 19 | + query_language: QueryLanguage::Cypher, |
| 20 | + middleware: vec![], |
| 21 | + sources: vec![SourceSubscriptionConfigDto { |
| 22 | + source_id: "my-source".to_string(), |
| 23 | + nodes: vec![], |
| 24 | + relations: vec![], |
| 25 | + pipeline: vec![], |
| 26 | + }], |
| 27 | + enable_bootstrap: true, |
| 28 | + bootstrap_buffer_size: 500, |
| 29 | + joins: None, |
| 30 | + priority_queue_capacity: Some(1000), |
| 31 | + dispatch_buffer_capacity: None, |
| 32 | + dispatch_mode: None, |
| 33 | + storage_backend: None, |
| 34 | + }; |
19 | 35 |
|
20 | | - // Verify fields are in camelCase |
21 | | - assert!(json.get("slotName").is_some(), "slotName should exist"); |
| 36 | + let json = serde_json::to_value(&dto).unwrap(); |
| 37 | + |
| 38 | + // camelCase fields must exist |
| 39 | + assert!(json.get("autoStart").is_some(), "autoStart should exist"); |
| 40 | + assert!( |
| 41 | + json.get("queryLanguage").is_some(), |
| 42 | + "queryLanguage should exist" |
| 43 | + ); |
| 44 | + assert!( |
| 45 | + json.get("enableBootstrap").is_some(), |
| 46 | + "enableBootstrap should exist" |
| 47 | + ); |
22 | 48 | assert!( |
23 | | - json.get("publicationName").is_some(), |
24 | | - "publicationName should exist" |
| 49 | + json.get("bootstrapBufferSize").is_some(), |
| 50 | + "bootstrapBufferSize should exist" |
| 51 | + ); |
| 52 | + assert!( |
| 53 | + json.get("priorityQueueCapacity").is_some(), |
| 54 | + "priorityQueueCapacity should exist" |
25 | 55 | ); |
26 | | - assert!(json.get("tableKeys").is_some(), "tableKeys should exist"); |
27 | | - assert!(json.get("sslMode").is_some(), "sslMode should exist"); |
28 | 56 |
|
29 | | - // Verify snake_case versions don't exist |
| 57 | + // snake_case equivalents must NOT exist |
30 | 58 | assert!( |
31 | | - json.get("slot_name").is_none(), |
32 | | - "slot_name should NOT exist" |
| 59 | + json.get("auto_start").is_none(), |
| 60 | + "auto_start should NOT exist" |
33 | 61 | ); |
34 | 62 | assert!( |
35 | | - json.get("publication_name").is_none(), |
36 | | - "publication_name should NOT exist" |
| 63 | + json.get("query_language").is_none(), |
| 64 | + "query_language should NOT exist" |
37 | 65 | ); |
38 | 66 | assert!( |
39 | | - json.get("table_keys").is_none(), |
40 | | - "table_keys should NOT exist" |
| 67 | + json.get("enable_bootstrap").is_none(), |
| 68 | + "enable_bootstrap should NOT exist" |
41 | 69 | ); |
42 | | - assert!(json.get("ssl_mode").is_none(), "ssl_mode should NOT exist"); |
43 | 70 |
|
44 | | - println!("✅ Postgres source config serializes as camelCase"); |
| 71 | + // Nested source subscription DTO |
| 72 | + let source = json["sources"].as_array().unwrap().first().unwrap(); |
| 73 | + assert!(source.get("sourceId").is_some(), "sourceId should exist"); |
| 74 | + assert!( |
| 75 | + source.get("source_id").is_none(), |
| 76 | + "source_id should NOT exist" |
| 77 | + ); |
45 | 78 | } |
46 | 79 |
|
47 | 80 | #[test] |
48 | | -fn test_mock_dto_serializes_camelcase() { |
49 | | - let json = json!({ |
50 | | - "dataType": {"type": "sensorReading", "sensorCount": 5}, |
51 | | - "intervalMs": 1000 |
52 | | - }); |
| 81 | +fn test_component_event_dto_serializes_camelcase() { |
| 82 | + let dto = ComponentEventDto { |
| 83 | + component_id: "my-source".to_string(), |
| 84 | + component_type: ComponentTypeDto::Source, |
| 85 | + status: ComponentStatusDto::Running, |
| 86 | + timestamp: chrono::Utc::now(), |
| 87 | + message: Some("started".to_string()), |
| 88 | + }; |
53 | 89 |
|
54 | | - // Verify fields are in camelCase |
55 | | - assert!(json.get("dataType").is_some(), "dataType should exist"); |
56 | | - assert!(json.get("intervalMs").is_some(), "intervalMs should exist"); |
| 90 | + let json = serde_json::to_value(&dto).unwrap(); |
57 | 91 |
|
58 | | - // Verify snake_case versions don't exist |
59 | 92 | assert!( |
60 | | - json.get("data_type").is_none(), |
61 | | - "data_type should NOT exist" |
| 93 | + json.get("componentId").is_some(), |
| 94 | + "componentId should exist" |
62 | 95 | ); |
63 | 96 | assert!( |
64 | | - json.get("interval_ms").is_none(), |
65 | | - "interval_ms should NOT exist" |
| 97 | + json.get("componentType").is_some(), |
| 98 | + "componentType should exist" |
| 99 | + ); |
| 100 | + assert!( |
| 101 | + json.get("component_id").is_none(), |
| 102 | + "component_id should NOT exist" |
| 103 | + ); |
| 104 | + assert!( |
| 105 | + json.get("component_type").is_none(), |
| 106 | + "component_type should NOT exist" |
66 | 107 | ); |
67 | | - |
68 | | - println!("✅ Mock source config serializes as camelCase"); |
69 | 108 | } |
70 | 109 |
|
71 | 110 | #[test] |
72 | | -fn test_http_source_dto_serializes_camelcase() { |
73 | | - let json = json!({ |
74 | | - "host": "localhost", |
75 | | - "port": 8080, |
76 | | - "timeoutMs": 5000, |
77 | | - "adaptiveMaxBatchSize": 100, |
78 | | - "adaptiveMinBatchSize": 10, |
79 | | - "adaptiveMaxWaitMs": 500, |
80 | | - "adaptiveMinWaitMs": 10, |
81 | | - "adaptiveWindowSecs": 60, |
82 | | - "adaptiveEnabled": true |
83 | | - }); |
| 111 | +fn test_log_message_dto_serializes_camelcase() { |
| 112 | + let dto = LogMessageDto { |
| 113 | + timestamp: chrono::Utc::now(), |
| 114 | + level: LogLevelDto::Info, |
| 115 | + message: "test".to_string(), |
| 116 | + component_id: "my-source".to_string(), |
| 117 | + component_type: ComponentTypeDto::Source, |
| 118 | + }; |
| 119 | + |
| 120 | + let json = serde_json::to_value(&dto).unwrap(); |
84 | 121 |
|
85 | | - // Verify fields are in camelCase |
86 | | - assert!(json.get("timeoutMs").is_some(), "timeoutMs should exist"); |
87 | 122 | assert!( |
88 | | - json.get("adaptiveMaxBatchSize").is_some(), |
89 | | - "adaptiveMaxBatchSize should exist" |
| 123 | + json.get("componentId").is_some(), |
| 124 | + "componentId should exist" |
90 | 125 | ); |
91 | 126 | assert!( |
92 | | - json.get("adaptiveMinBatchSize").is_some(), |
93 | | - "adaptiveMinBatchSize should exist" |
| 127 | + json.get("componentType").is_some(), |
| 128 | + "componentType should exist" |
94 | 129 | ); |
95 | | - |
96 | | - // Verify snake_case versions don't exist |
97 | 130 | assert!( |
98 | | - json.get("timeout_ms").is_none(), |
99 | | - "timeout_ms should NOT exist" |
| 131 | + json.get("component_id").is_none(), |
| 132 | + "component_id should NOT exist" |
100 | 133 | ); |
101 | 134 | assert!( |
102 | | - json.get("adaptive_max_batch_size").is_none(), |
103 | | - "adaptive_max_batch_size should NOT exist" |
| 135 | + json.get("component_type").is_none(), |
| 136 | + "component_type should NOT exist" |
104 | 137 | ); |
105 | | - |
106 | | - println!("✅ HTTP source config serializes as camelCase"); |
107 | 138 | } |
0 commit comments