shopify_sdk/rest/resources/v2025_10/
currency.rs1use serde::{Deserialize, Serialize};
33
34use crate::rest::{ReadOnlyResource, ResourceOperation, ResourcePath, RestResource};
35use crate::HttpMethod;
36
37#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
59pub struct Currency {
60 #[serde(skip_serializing)]
62 pub currency: Option<String>,
63
64 #[serde(skip_serializing)]
66 pub rate_updated_at: Option<String>,
67
68 #[serde(skip_serializing)]
70 pub enabled: Option<bool>,
71}
72
73impl RestResource for Currency {
74 type Id = String;
75 type FindParams = ();
76 type AllParams = ();
77 type CountParams = ();
78
79 const NAME: &'static str = "Currency";
80 const PLURAL: &'static str = "currencies";
81
82 const PATHS: &'static [ResourcePath] = &[
86 ResourcePath::new(HttpMethod::Get, ResourceOperation::All, &[], "currencies"),
87 ];
91
92 fn get_id(&self) -> Option<Self::Id> {
93 self.currency.clone()
94 }
95}
96
97impl ReadOnlyResource for Currency {}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102 use crate::rest::{get_path, ReadOnlyResource, ResourceOperation, RestResource};
103
104 #[test]
105 fn test_currency_implements_read_only_resource() {
106 fn assert_read_only<T: ReadOnlyResource>() {}
107 assert_read_only::<Currency>();
108 }
109
110 #[test]
111 fn test_currency_deserialization() {
112 let json = r#"{
113 "currency": "CAD",
114 "rate_updated_at": "2024-01-15T10:30:00-05:00",
115 "enabled": true
116 }"#;
117
118 let currency: Currency = serde_json::from_str(json).unwrap();
119
120 assert_eq!(currency.currency, Some("CAD".to_string()));
121 assert_eq!(
122 currency.rate_updated_at,
123 Some("2024-01-15T10:30:00-05:00".to_string())
124 );
125 assert_eq!(currency.enabled, Some(true));
126 }
127
128 #[test]
129 fn test_currency_list_only_paths() {
130 let all_path = get_path(Currency::PATHS, ResourceOperation::All, &[]);
132 assert!(all_path.is_some());
133 assert_eq!(all_path.unwrap().template, "currencies");
134
135 let find_path = get_path(Currency::PATHS, ResourceOperation::Find, &["id"]);
137 assert!(find_path.is_none());
138
139 let count_path = get_path(Currency::PATHS, ResourceOperation::Count, &[]);
141 assert!(count_path.is_none());
142
143 let create_path = get_path(Currency::PATHS, ResourceOperation::Create, &[]);
145 assert!(create_path.is_none());
146
147 let update_path = get_path(Currency::PATHS, ResourceOperation::Update, &["id"]);
149 assert!(update_path.is_none());
150
151 let delete_path = get_path(Currency::PATHS, ResourceOperation::Delete, &["id"]);
153 assert!(delete_path.is_none());
154 }
155
156 #[test]
157 fn test_currency_constants() {
158 assert_eq!(Currency::NAME, "Currency");
159 assert_eq!(Currency::PLURAL, "currencies");
160 }
161
162 #[test]
163 fn test_currency_get_id_returns_code() {
164 let currency_with_code = Currency {
165 currency: Some("USD".to_string()),
166 rate_updated_at: None,
167 enabled: Some(true),
168 };
169 assert_eq!(currency_with_code.get_id(), Some("USD".to_string()));
170
171 let currency_without_code = Currency::default();
172 assert_eq!(currency_without_code.get_id(), None);
173 }
174
175 #[test]
176 fn test_currency_all_fields_are_read_only() {
177 let currency = Currency {
179 currency: Some("EUR".to_string()),
180 rate_updated_at: Some("2024-01-15T10:30:00-05:00".to_string()),
181 enabled: Some(true),
182 };
183
184 let json = serde_json::to_value(¤cy).unwrap();
185 assert_eq!(json, serde_json::json!({}));
187 }
188}