@@ -113,7 +113,7 @@ fn get_production_configuration(secrets: &SecretStore) -> Result<Settings, confi
113113 production_settings. try_deserialize :: < Settings > ( )
114114}
115115
116- #[ derive( Debug ) ]
116+ #[ derive( Debug , PartialEq , Eq ) ]
117117pub enum Environment {
118118 Local ,
119119 Production ,
@@ -141,3 +141,51 @@ impl TryFrom<String> for Environment {
141141 }
142142 }
143143}
144+
145+ #[ cfg( test) ]
146+ mod tests {
147+ use super :: * ;
148+
149+ #[ test]
150+ fn test_environment_as_str ( ) {
151+ assert_eq ! ( Environment :: Local . as_str( ) , "local" ) ;
152+ assert_eq ! ( Environment :: Production . as_str( ) , "production" ) ;
153+ }
154+
155+ #[ test]
156+ fn test_try_from_string ( ) {
157+ assert_eq ! (
158+ Environment :: try_from( "local" . to_string( ) ) ,
159+ Ok ( Environment :: Local )
160+ ) ;
161+ assert_eq ! (
162+ Environment :: try_from( "production" . to_string( ) ) ,
163+ Ok ( Environment :: Production )
164+ ) ;
165+ assert_eq ! (
166+ Environment :: try_from( "invalid" . to_string( ) ) ,
167+ Err (
168+ "invalid is not a supported environment. Use either `local` or `production`."
169+ . to_string( )
170+ )
171+ ) ;
172+ }
173+
174+ #[ test]
175+ fn test_get_local_configuration ( ) -> Result < ( ) , config:: ConfigError > {
176+ let settings = get_local_configuration ( ) ?;
177+ assert_eq ! ( settings. email_client. sender_email, "noreply@queens.ac" ) ;
178+ assert_eq ! ( settings. email_client. timeout_seconds, 10 ) ;
179+ assert_eq ! (
180+ settings. cors. allowed_origins,
181+ vec![
182+ "http://localhost:3000" ,
183+ "https://queens.ac" ,
184+ "https://www.queens.ac"
185+ ]
186+ ) ;
187+ assert_eq ! ( settings. repository_checker. interval_seconds, 120 ) ;
188+ assert_eq ! ( settings. application. port, 8080 ) ;
189+ Ok ( ( ) )
190+ }
191+ }
0 commit comments