Skip to content

Commit 654719e

Browse files
Format Rust code using rustfmt
1 parent fa2035d commit 654719e

File tree

2 files changed

+66
-35
lines changed

2 files changed

+66
-35
lines changed

functions/fetch-quote/src/fetcher.rs

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ mod tests {
3434
let server = MockServer::start();
3535

3636
// Create a mock on the server that can be called multiple times
37-
server.mock_async(|when, then| {
38-
when.method(GET).path("/quotes/stats.json");
39-
then.status(200)
40-
.header("content-type", "application/json")
41-
.body(
42-
r#"
37+
server
38+
.mock_async(|when, then| {
39+
when.method(GET).path("/quotes/stats.json");
40+
then.status(200)
41+
.header("content-type", "application/json")
42+
.body(
43+
r#"
4344
{
4445
"total": 3,
4546
"all": "https://fullStackbulletin.github.io/tech-quotes/quotes/all.json",
@@ -48,15 +49,18 @@ mod tests {
4849
"urlPrefix": "https://fullStackbulletin.github.io/tech-quotes/quotes"
4950
}
5051
"#,
51-
);
52-
}).await;
52+
);
53+
})
54+
.await;
5355

5456
// Mock all possible quote IDs (0, 1, 2) since we're using a small total
55-
server.mock_async(|when, then| {
56-
when.method(GET).path("/quotes/0.json");
57-
then.status(200)
58-
.header("content-type", "application/json")
59-
.body(r#"
57+
server
58+
.mock_async(|when, then| {
59+
when.method(GET).path("/quotes/0.json");
60+
then.status(200)
61+
.header("content-type", "application/json")
62+
.body(
63+
r#"
6064
{
6165
"id": 0,
6266
"text": "Test quote 0",
@@ -69,14 +73,18 @@ mod tests {
6973
},
7074
"url": "https://fullStackbulletin.github.io/tech-quotes/quotes/0.json"
7175
}
72-
"#);
73-
}).await;
76+
"#,
77+
);
78+
})
79+
.await;
7480

75-
server.mock_async(|when, then| {
76-
when.method(GET).path("/quotes/1.json");
77-
then.status(200)
78-
.header("content-type", "application/json")
79-
.body(r#"
81+
server
82+
.mock_async(|when, then| {
83+
when.method(GET).path("/quotes/1.json");
84+
then.status(200)
85+
.header("content-type", "application/json")
86+
.body(
87+
r#"
8088
{
8189
"id": 1,
8290
"text": "Test quote 1",
@@ -88,14 +96,18 @@ mod tests {
8896
},
8997
"url": "https://fullStackbulletin.github.io/tech-quotes/quotes/1.json"
9098
}
91-
"#);
92-
}).await;
99+
"#,
100+
);
101+
})
102+
.await;
93103

94-
server.mock_async(|when, then| {
95-
when.method(GET).path("/quotes/2.json");
96-
then.status(200)
97-
.header("content-type", "application/json")
98-
.body(r#"
104+
server
105+
.mock_async(|when, then| {
106+
when.method(GET).path("/quotes/2.json");
107+
then.status(200)
108+
.header("content-type", "application/json")
109+
.body(
110+
r#"
99111
{
100112
"id": 2,
101113
"text": "Test quote 2",
@@ -108,13 +120,19 @@ mod tests {
108120
},
109121
"url": "https://fullStackbulletin.github.io/tech-quotes/quotes/2.json"
110122
}
111-
"#);
112-
}).await;
123+
"#,
124+
);
125+
})
126+
.await;
113127

114128
// Test that the function successfully fetches a random quote
115129
let response = fetch_quote(&server.base_url(), 0).await;
116130

117-
assert!(response.is_ok(), "Failed to fetch quote: {:?}", response.err());
131+
assert!(
132+
response.is_ok(),
133+
"Failed to fetch quote: {:?}",
134+
response.err()
135+
);
118136

119137
let quote = response.unwrap();
120138
// Verify the quote ID is in the valid range

functions/fetch-quote/src/models.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,24 @@ mod tests {
127127
}
128128
"#;
129129

130-
let input_quote: InputQuote = serde_json::from_str(input_json).expect("Failed to deserialize InputQuote");
130+
let input_quote: InputQuote =
131+
serde_json::from_str(input_json).expect("Failed to deserialize InputQuote");
131132
let quote: Quote = input_quote.into();
132133

133134
// Serialize to JSON
134135
let serialized = serde_json::to_string(&quote).expect("Failed to serialize Quote");
135136
println!("Serialized Quote: {}", serialized);
136137

137138
// Verify that authorUrl field is omitted (not null) when None
138-
assert!(!serialized.contains("authorUrl"), "authorUrl field should be omitted when None, but found in: {}", serialized);
139+
assert!(
140+
!serialized.contains("authorUrl"),
141+
"authorUrl field should be omitted when None, but found in: {}",
142+
serialized
143+
);
139144

140145
// Deserialize back
141-
let deserialized: Quote = serde_json::from_str(&serialized).expect("Failed to deserialize Quote");
146+
let deserialized: Quote =
147+
serde_json::from_str(&serialized).expect("Failed to deserialize Quote");
142148

143149
assert_eq!(deserialized.id, 22);
144150
assert_eq!(deserialized.author, "Francis Glassborow");
@@ -160,7 +166,14 @@ mod tests {
160166
println!("Serialized Quote with URL: {}", serialized);
161167

162168
// Verify that authorUrl field IS included when Some
163-
assert!(serialized.contains("authorUrl"), "authorUrl field should be included when Some, but not found in: {}", serialized);
164-
assert!(serialized.contains("https://example.com"), "authorUrl value should be in serialized output");
169+
assert!(
170+
serialized.contains("authorUrl"),
171+
"authorUrl field should be included when Some, but not found in: {}",
172+
serialized
173+
);
174+
assert!(
175+
serialized.contains("https://example.com"),
176+
"authorUrl value should be in serialized output"
177+
);
165178
}
166179
}

0 commit comments

Comments
 (0)