|
1 |
| -use svix::api::ListResponseApplicationOut; |
| 1 | +use std::fmt::Debug; |
| 2 | + |
| 3 | +use serde::de::DeserializeOwned; |
| 4 | +use serde_json::json; |
| 5 | +use svix::api::{ |
| 6 | + CronConfig, IngestSourceIn, IngestSourceInConfig, IngestSourceOut, IngestSourceOutConfig, |
| 7 | + ListResponseApplicationOut, SegmentConfig, SegmentConfigOut, SvixConfig, SvixConfigOut, |
| 8 | +}; |
2 | 9 |
|
3 | 10 | #[test]
|
4 | 11 | fn test_list_response_xxx_out() {
|
@@ -28,3 +35,166 @@ fn test_list_response_xxx_out() {
|
28 | 35 |
|
29 | 36 | assert_eq!(expected_model, loaded_json);
|
30 | 37 | }
|
| 38 | + |
| 39 | +#[test] |
| 40 | +fn test_ingest_source_in() { |
| 41 | + assert_eq!( |
| 42 | + json!(IngestSourceIn { |
| 43 | + name: "foo".to_owned(), |
| 44 | + uid: None, |
| 45 | + config: IngestSourceInConfig::GenericWebhook, |
| 46 | + }), |
| 47 | + json!({ |
| 48 | + "name": "foo", |
| 49 | + "type": "generic-webhook", |
| 50 | + }), |
| 51 | + ); |
| 52 | + |
| 53 | + assert_eq!( |
| 54 | + json!(IngestSourceIn { |
| 55 | + name: "foo".to_owned(), |
| 56 | + uid: None, |
| 57 | + config: IngestSourceInConfig::Svix(SvixConfig { |
| 58 | + secret: "xxx".to_owned() |
| 59 | + }), |
| 60 | + }), |
| 61 | + json!({ |
| 62 | + "name": "foo", |
| 63 | + "type": "svix", |
| 64 | + "config": { "secret": "xxx" }, |
| 65 | + }), |
| 66 | + ); |
| 67 | + |
| 68 | + assert_eq!( |
| 69 | + json!(IngestSourceIn { |
| 70 | + name: "foo".to_owned(), |
| 71 | + uid: None, |
| 72 | + config: IngestSourceInConfig::Segment(SegmentConfig { secret: None }) |
| 73 | + }), |
| 74 | + json!({ |
| 75 | + "name": "foo", |
| 76 | + "type": "segment", |
| 77 | + "config": {}, |
| 78 | + }), |
| 79 | + ); |
| 80 | + |
| 81 | + assert_eq!( |
| 82 | + json!(IngestSourceIn { |
| 83 | + name: "foo".to_owned(), |
| 84 | + uid: None, |
| 85 | + config: IngestSourceInConfig::Cron(CronConfig { |
| 86 | + content_type: None, |
| 87 | + payload: "💣".to_owned(), |
| 88 | + schedule: "* * * * *".to_owned(), |
| 89 | + }) |
| 90 | + }), |
| 91 | + json!({ |
| 92 | + "name": "foo", |
| 93 | + "type": "cron", |
| 94 | + "config": { |
| 95 | + "payload": "💣", |
| 96 | + "schedule": "* * * * *", |
| 97 | + }, |
| 98 | + }), |
| 99 | + ); |
| 100 | +} |
| 101 | + |
| 102 | +#[test] |
| 103 | +fn test_ingest_source_out() { |
| 104 | + assert_deserializes_to( |
| 105 | + json!({ |
| 106 | + "id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr", |
| 107 | + "createdAt": "2006-01-02T15:04:05Z", |
| 108 | + "updatedAt": "2006-01-02T15:04:05Z", |
| 109 | + "name": "foo", |
| 110 | + "ingestUrl": "https://in.example.invalid/xyz", |
| 111 | + "type": "generic-webhook", |
| 112 | + }), |
| 113 | + IngestSourceOut { |
| 114 | + created_at: "2006-01-02T15:04:05Z".to_owned(), |
| 115 | + id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(), |
| 116 | + ingest_url: Some("https://in.example.invalid/xyz".to_owned()), |
| 117 | + name: "foo".to_owned(), |
| 118 | + uid: None, |
| 119 | + updated_at: "2006-01-02T15:04:05Z".to_owned(), |
| 120 | + config: IngestSourceOutConfig::GenericWebhook, |
| 121 | + }, |
| 122 | + ); |
| 123 | + |
| 124 | + assert_deserializes_to( |
| 125 | + json!({ |
| 126 | + "id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr", |
| 127 | + "createdAt": "2006-01-02T15:04:05Z", |
| 128 | + "updatedAt": "2006-01-02T15:04:05Z", |
| 129 | + "name": "foo", |
| 130 | + "ingestUrl": "https://in.example.invalid/xyz", |
| 131 | + "type": "svix", |
| 132 | + "config": { "secret": "xxx" }, |
| 133 | + }), |
| 134 | + IngestSourceOut { |
| 135 | + created_at: "2006-01-02T15:04:05Z".to_owned(), |
| 136 | + id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(), |
| 137 | + ingest_url: Some("https://in.example.invalid/xyz".to_owned()), |
| 138 | + name: "foo".to_owned(), |
| 139 | + uid: None, |
| 140 | + updated_at: "2006-01-02T15:04:05Z".to_owned(), |
| 141 | + config: IngestSourceOutConfig::Svix(SvixConfigOut {}), |
| 142 | + }, |
| 143 | + ); |
| 144 | + |
| 145 | + assert_deserializes_to( |
| 146 | + json!({ |
| 147 | + "id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr", |
| 148 | + "createdAt": "2006-01-02T15:04:05Z", |
| 149 | + "updatedAt": "2006-01-02T15:04:05Z", |
| 150 | + "name": "foo", |
| 151 | + "ingestUrl": "https://in.example.invalid/xyz", |
| 152 | + "type": "segment", |
| 153 | + "config": {}, |
| 154 | + }), |
| 155 | + IngestSourceOut { |
| 156 | + created_at: "2006-01-02T15:04:05Z".to_owned(), |
| 157 | + id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(), |
| 158 | + ingest_url: Some("https://in.example.invalid/xyz".to_owned()), |
| 159 | + name: "foo".to_owned(), |
| 160 | + uid: None, |
| 161 | + updated_at: "2006-01-02T15:04:05Z".to_owned(), |
| 162 | + config: IngestSourceOutConfig::Segment(SegmentConfigOut::default()), |
| 163 | + }, |
| 164 | + ); |
| 165 | + |
| 166 | + assert_deserializes_to( |
| 167 | + json!({ |
| 168 | + "id": "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr", |
| 169 | + "createdAt": "2006-01-02T15:04:05Z", |
| 170 | + "updatedAt": "2006-01-02T15:04:05Z", |
| 171 | + "name": "foo", |
| 172 | + "type": "cron", |
| 173 | + "config": { |
| 174 | + "payload": "💣", |
| 175 | + "schedule": "* * * * *", |
| 176 | + }, |
| 177 | + }), |
| 178 | + IngestSourceOut { |
| 179 | + created_at: "2006-01-02T15:04:05Z".to_owned(), |
| 180 | + id: "Rjb52OFZK6aYPfF4EpqYqD8Ptcyr".to_owned(), |
| 181 | + ingest_url: None, |
| 182 | + name: "foo".to_owned(), |
| 183 | + uid: None, |
| 184 | + updated_at: "2006-01-02T15:04:05Z".to_owned(), |
| 185 | + config: IngestSourceOutConfig::Cron(CronConfig { |
| 186 | + content_type: None, |
| 187 | + payload: "💣".to_owned(), |
| 188 | + schedule: "* * * * *".to_owned(), |
| 189 | + }), |
| 190 | + }, |
| 191 | + ); |
| 192 | +} |
| 193 | + |
| 194 | +fn assert_deserializes_to<T: Debug + PartialEq + DeserializeOwned>( |
| 195 | + value: serde_json::Value, |
| 196 | + expected: T, |
| 197 | +) { |
| 198 | + let actual = T::deserialize(value).unwrap(); |
| 199 | + assert_eq!(actual, expected); |
| 200 | +} |
0 commit comments