|
| 1 | +use cubeclient::models::*; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn test_deserialize_meta_response_with_format_fields() { |
| 5 | + let json_data = r#"{ |
| 6 | + "cubes": [ |
| 7 | + { |
| 8 | + "name": "orders", |
| 9 | + "type": "cube", |
| 10 | + "title": "Orders", |
| 11 | + "isVisible": false, |
| 12 | + "public": false, |
| 13 | + "connectedComponent": 1, |
| 14 | + "measures": [ |
| 15 | + { |
| 16 | + "name": "orders.count", |
| 17 | + "title": "Orders Count", |
| 18 | + "shortTitle": "Count", |
| 19 | + "cumulativeTotal": false, |
| 20 | + "cumulative": false, |
| 21 | + "type": "number", |
| 22 | + "aggType": "count", |
| 23 | + "drillMembers": [], |
| 24 | + "drillMembersGrouped": { |
| 25 | + "measures": [], |
| 26 | + "dimensions": [] |
| 27 | + }, |
| 28 | + "meta": { |
| 29 | + "random_field_name": "My custom metadata for meta count" |
| 30 | + }, |
| 31 | + "isVisible": false, |
| 32 | + "public": false |
| 33 | + }, |
| 34 | + { |
| 35 | + "name": "orders.min_amount", |
| 36 | + "title": "Orders Min Amount", |
| 37 | + "shortTitle": "Min Amount", |
| 38 | + "format": "currency", |
| 39 | + "cumulativeTotal": false, |
| 40 | + "cumulative": false, |
| 41 | + "type": "number", |
| 42 | + "aggType": "min", |
| 43 | + "drillMembers": [], |
| 44 | + "drillMembersGrouped": { |
| 45 | + "measures": [], |
| 46 | + "dimensions": [] |
| 47 | + }, |
| 48 | + "isVisible": false, |
| 49 | + "public": false |
| 50 | + }, |
| 51 | + { |
| 52 | + "name": "orders.total_amount", |
| 53 | + "title": "Orders Total Amount", |
| 54 | + "shortTitle": "Total Amount", |
| 55 | + "format": "currency", |
| 56 | + "cumulativeTotal": false, |
| 57 | + "cumulative": false, |
| 58 | + "type": "number", |
| 59 | + "aggType": "sum", |
| 60 | + "drillMembers": [], |
| 61 | + "drillMembersGrouped": { |
| 62 | + "measures": [], |
| 63 | + "dimensions": [] |
| 64 | + }, |
| 65 | + "isVisible": false, |
| 66 | + "public": false |
| 67 | + } |
| 68 | + ], |
| 69 | + "dimensions": [ |
| 70 | + { |
| 71 | + "name": "orders.id", |
| 72 | + "title": "Orders Id", |
| 73 | + "type": "number", |
| 74 | + "shortTitle": "Id", |
| 75 | + "suggestFilterValues": true, |
| 76 | + "isVisible": false, |
| 77 | + "public": false, |
| 78 | + "primaryKey": true |
| 79 | + }, |
| 80 | + { |
| 81 | + "name": "orders.order_sum", |
| 82 | + "title": "Orders Order Sum", |
| 83 | + "type": "number", |
| 84 | + "shortTitle": "Order Sum", |
| 85 | + "suggestFilterValues": true, |
| 86 | + "format": "currency", |
| 87 | + "isVisible": false, |
| 88 | + "public": false, |
| 89 | + "primaryKey": false |
| 90 | + } |
| 91 | + ], |
| 92 | + "segments": [], |
| 93 | + "hierarchies": [], |
| 94 | + "folders": [], |
| 95 | + "nestedFolders": [] |
| 96 | + } |
| 97 | + ] |
| 98 | + }"#; |
| 99 | + |
| 100 | + // Test basic deserialization |
| 101 | + let meta_response: V1MetaResponse = |
| 102 | + serde_json::from_str(json_data).expect("Should successfully deserialize meta response"); |
| 103 | + |
| 104 | + // Verify the response structure |
| 105 | + assert!(meta_response.cubes.is_some()); |
| 106 | + let cubes = meta_response.cubes.unwrap(); |
| 107 | + assert_eq!(cubes.len(), 1); |
| 108 | +} |
| 109 | + |
| 110 | +#[test] |
| 111 | +fn test_deserialize_dimension_link_format() { |
| 112 | + let json_data = r#"{ |
| 113 | + "cubes": [ |
| 114 | + { |
| 115 | + "name": "test_cube", |
| 116 | + "type": "cube", |
| 117 | + "measures": [], |
| 118 | + "dimensions": [ |
| 119 | + { |
| 120 | + "name": "test.link_dimension", |
| 121 | + "title": "Test Link Dimension", |
| 122 | + "type": "string", |
| 123 | + "format": { |
| 124 | + "type": "link", |
| 125 | + "label": "View Details" |
| 126 | + } |
| 127 | + } |
| 128 | + ], |
| 129 | + "segments": [] |
| 130 | + } |
| 131 | + ] |
| 132 | + }"#; |
| 133 | + |
| 134 | + let meta_response: V1MetaResponse = |
| 135 | + serde_json::from_str(json_data).expect("Should successfully deserialize link format"); |
| 136 | + |
| 137 | + let cubes = meta_response.cubes.unwrap(); |
| 138 | + let dimension = &cubes[0].dimensions[0]; |
| 139 | + |
| 140 | + assert_eq!( |
| 141 | + dimension.format, |
| 142 | + Some(Box::new( |
| 143 | + V1CubeMetaDimensionFormat::V1CubeMetaDimensionLinkFormat(Box::new( |
| 144 | + V1CubeMetaDimensionLinkFormat { |
| 145 | + label: "View Details".to_string(), |
| 146 | + r#type: V1CubeMetaDimensionLinkFormatType::Link, |
| 147 | + } |
| 148 | + )) |
| 149 | + )) |
| 150 | + ); |
| 151 | +} |
0 commit comments