@@ -6,7 +6,6 @@ use crates_io_database::schema::{emails, trustpub_configs_github};
6
6
use crates_io_github:: { GitHubError , GitHubUser , MockGitHubClient } ;
7
7
use diesel:: prelude:: * ;
8
8
use diesel_async:: RunQueryDsl ;
9
- use http:: StatusCode ;
10
9
use insta:: { assert_json_snapshot, assert_snapshot} ;
11
10
use serde_json:: json;
12
11
@@ -61,7 +60,7 @@ async fn test_happy_path() -> anyhow::Result<()> {
61
60
} ) ) ?;
62
61
63
62
let ( app, response) = run_test ( body) . await ;
64
- assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
63
+ assert_snapshot ! ( response. status( ) , @ "200 OK" ) ;
65
64
assert_json_snapshot ! ( response. json( ) , { ".github_config.created_at" => "[datetime]" } ) ;
66
65
67
66
assert_snapshot ! ( app. emails_snapshot( ) . await ) ;
@@ -91,7 +90,7 @@ async fn test_happy_path_with_environment() -> anyhow::Result<()> {
91
90
} ) ) ?;
92
91
93
92
let ( _app, response) = run_test ( body) . await ;
94
- assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
93
+ assert_snapshot ! ( response. status( ) , @ "200 OK" ) ;
95
94
assert_json_snapshot ! ( response. json( ) , { ".github_config.created_at" => "[datetime]" } ) ;
96
95
97
96
Ok ( ( ) )
@@ -100,7 +99,7 @@ async fn test_happy_path_with_environment() -> anyhow::Result<()> {
100
99
#[ tokio:: test( flavor = "multi_thread" ) ]
101
100
async fn test_empty_body ( ) -> anyhow:: Result < ( ) > {
102
101
let ( _app, response) = run_test ( "" ) . await ;
103
- assert_eq ! ( response. status( ) , StatusCode :: UNSUPPORTED_MEDIA_TYPE ) ;
102
+ assert_snapshot ! ( response. status( ) , @ "415 Unsupported Media Type" ) ;
104
103
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Expected request with `Content-Type: application/json`"}]}"# ) ;
105
104
106
105
Ok ( ( ) )
@@ -109,7 +108,7 @@ async fn test_empty_body() -> anyhow::Result<()> {
109
108
#[ tokio:: test( flavor = "multi_thread" ) ]
110
109
async fn test_empty_json_object ( ) -> anyhow:: Result < ( ) > {
111
110
let ( _app, response) = run_test ( "{}" ) . await ;
112
- assert_eq ! ( response. status( ) , StatusCode :: UNPROCESSABLE_ENTITY ) ;
111
+ assert_snapshot ! ( response. status( ) , @ "422 Unprocessable Entity" ) ;
113
112
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Failed to deserialize the JSON body into the target type: missing field `github_config` at line 1 column 2"}]}"# ) ;
114
113
115
114
Ok ( ( ) )
@@ -128,7 +127,7 @@ async fn test_invalid_owner() -> anyhow::Result<()> {
128
127
} ) ) ?;
129
128
130
129
let ( _app, response) = run_test ( body) . await ;
131
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
130
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
132
131
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid GitHub repository owner name"}]}"# ) ;
133
132
134
133
Ok ( ( ) )
@@ -147,7 +146,7 @@ async fn test_invalid_repo() -> anyhow::Result<()> {
147
146
} ) ) ?;
148
147
149
148
let ( _app, response) = run_test ( body) . await ;
150
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
149
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
151
150
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid GitHub repository name"}]}"# ) ;
152
151
153
152
Ok ( ( ) )
@@ -166,7 +165,7 @@ async fn test_invalid_workflow() -> anyhow::Result<()> {
166
165
} ) ) ?;
167
166
168
167
let ( _app, response) = run_test ( body) . await ;
169
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
168
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
170
169
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Workflow filename must end with `.yml` or `.yaml`"}]}"# ) ;
171
170
172
171
Ok ( ( ) )
@@ -185,7 +184,7 @@ async fn test_invalid_environment() -> anyhow::Result<()> {
185
184
} ) ) ?;
186
185
187
186
let ( _app, response) = run_test ( body) . await ;
188
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
187
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
189
188
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Environment name may not be empty (use `null` to omit)"}]}"# ) ;
190
189
191
190
Ok ( ( ) )
@@ -215,7 +214,7 @@ async fn test_unauthenticated() -> anyhow::Result<()> {
215
214
} ) ) ?;
216
215
217
216
let response = client. put :: < ( ) > ( URL , body) . await ;
218
- assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
217
+ assert_snapshot ! ( response. status( ) , @ "403 Forbidden" ) ;
219
218
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"this action requires authentication"}]}"# ) ;
220
219
221
220
Ok ( ( ) )
@@ -245,7 +244,7 @@ async fn test_token_auth() -> anyhow::Result<()> {
245
244
} ) ) ?;
246
245
247
246
let response = token_client. put :: < ( ) > ( URL , body) . await ;
248
- assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
247
+ assert_snapshot ! ( response. status( ) , @ "403 Forbidden" ) ;
249
248
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"this action can only be performed on the crates.io website"}]}"# ) ;
250
249
251
250
Ok ( ( ) )
@@ -269,7 +268,7 @@ async fn test_missing_crate() -> anyhow::Result<()> {
269
268
} ) ) ?;
270
269
271
270
let response = cookie_client. put :: < ( ) > ( URL , body) . await ;
272
- assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
271
+ assert_snapshot ! ( response. status( ) , @ "404 Not Found" ) ;
273
272
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"crate `foo` does not exist"}]}"# ) ;
274
273
275
274
Ok ( ( ) )
@@ -301,7 +300,7 @@ async fn test_non_owner() -> anyhow::Result<()> {
301
300
} ) ) ?;
302
301
303
302
let response = other_client. put :: < ( ) > ( URL , body) . await ;
304
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
303
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
305
304
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"You are not an owner of this crate"}]}"# ) ;
306
305
307
306
Ok ( ( ) )
@@ -333,7 +332,7 @@ async fn test_unknown_github_user() -> anyhow::Result<()> {
333
332
} ) ) ?;
334
333
335
334
let response = cookie_client. put :: < ( ) > ( URL , body) . await ;
336
- assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
335
+ assert_snapshot ! ( response. status( ) , @ "400 Bad Request" ) ;
337
336
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Unknown GitHub user or organization"}]}"# ) ;
338
337
339
338
Ok ( ( ) )
@@ -365,7 +364,7 @@ async fn test_github_error() -> anyhow::Result<()> {
365
364
} ) ) ?;
366
365
367
366
let response = cookie_client. put :: < ( ) > ( URL , body) . await ;
368
- assert_eq ! ( response. status( ) , StatusCode :: INTERNAL_SERVER_ERROR ) ;
367
+ assert_snapshot ! ( response. status( ) , @ "500 Internal Server Error" ) ;
369
368
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Internal Server Error"}]}"# ) ;
370
369
371
370
Ok ( ( ) )
@@ -400,7 +399,7 @@ async fn test_unverified_email() -> anyhow::Result<()> {
400
399
} ) ) ?;
401
400
402
401
let response = cookie_client. put :: < ( ) > ( URL , body) . await ;
403
- assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
402
+ assert_snapshot ! ( response. status( ) , @ "403 Forbidden" ) ;
404
403
assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"You must verify your email address to create a Trusted Publishing config"}]}"# ) ;
405
404
406
405
Ok ( ( ) )
0 commit comments