1
- use crate :: domain:: SubscriberEmail ;
2
1
use reqwest:: Client ;
3
2
use secrecy:: { ExposeSecret , Secret } ;
4
3
4
+ use crate :: domain:: SubscriberEmail ;
5
+
5
6
#[ derive( Clone ) ]
6
7
pub struct EmailClient {
7
8
http_client : Client ,
@@ -18,12 +19,7 @@ impl EmailClient {
18
19
timeout : std:: time:: Duration ,
19
20
) -> Self {
20
21
let http_client = Client :: builder ( ) . timeout ( timeout) . build ( ) . unwrap ( ) ;
21
- Self {
22
- http_client,
23
- base_url,
24
- sender,
25
- authorization_token,
26
- }
22
+ Self { http_client, base_url, sender, authorization_token }
27
23
}
28
24
}
29
25
@@ -46,10 +42,7 @@ impl EmailClient {
46
42
47
43
self . http_client
48
44
. post ( & url)
49
- . header (
50
- "X-Postmark-Server-Token" ,
51
- self . authorization_token . expose_secret ( ) ,
52
- )
45
+ . header ( "X-Postmark-Server-Token" , self . authorization_token . expose_secret ( ) )
53
46
. json ( & request_body)
54
47
. send ( )
55
48
. await ?
@@ -70,18 +63,16 @@ pub struct SendEmailRequest<'a> {
70
63
71
64
#[ cfg( test) ]
72
65
mod tests {
73
- use crate :: { domain:: SubscriberEmail , email_client:: EmailClient } ;
74
66
use claim:: { assert_err, assert_ok} ;
75
- use fake:: {
76
- faker:: internet:: en:: SafeEmail ,
77
- faker:: lorem:: en:: { Paragraph , Sentence } ,
78
- Fake , Faker ,
79
- } ;
67
+ use fake:: faker:: internet:: en:: SafeEmail ;
68
+ use fake:: faker:: lorem:: en:: { Paragraph , Sentence } ;
69
+ use fake:: { Fake , Faker } ;
80
70
use secrecy:: Secret ;
81
- use wiremock:: {
82
- matchers:: { any, header, header_exists, method, path} ,
83
- Mock , MockServer , Request , ResponseTemplate ,
84
- } ;
71
+ use wiremock:: matchers:: { any, header, header_exists, method, path} ;
72
+ use wiremock:: { Mock , MockServer , Request , ResponseTemplate } ;
73
+
74
+ use crate :: domain:: SubscriberEmail ;
75
+ use crate :: email_client:: EmailClient ;
85
76
86
77
struct SendEmailBodyMatcher ;
87
78
@@ -140,12 +131,7 @@ mod tests {
140
131
let recipient = get_email ( ) ;
141
132
142
133
let _ = email_client
143
- . send_email (
144
- & recipient,
145
- & generate_subject ( ) ,
146
- & generate_content ( ) ,
147
- & generate_content ( ) ,
148
- )
134
+ . send_email ( & recipient, & generate_subject ( ) , & generate_content ( ) , & generate_content ( ) )
149
135
. await ;
150
136
}
151
137
@@ -208,11 +194,7 @@ mod tests {
208
194
209
195
let response = ResponseTemplate :: new ( 200 ) . set_delay ( std:: time:: Duration :: from_secs ( 180 ) ) ;
210
196
211
- Mock :: given ( any ( ) )
212
- . respond_with ( response)
213
- . expect ( 1 )
214
- . mount ( & mock_server)
215
- . await ;
197
+ Mock :: given ( any ( ) ) . respond_with ( response) . expect ( 1 ) . mount ( & mock_server) . await ;
216
198
217
199
let outcome = email_client
218
200
. send_email (
0 commit comments