1
+ use crate :: insta:: rfc3339_redaction;
1
2
use crate :: { builders:: CrateBuilder , RequestHelper , TestApp } ;
2
3
use cargo_registry:: { models:: Keyword , views:: EncodableKeyword } ;
4
+ use insta:: assert_json_snapshot;
5
+ use serde_json:: Value ;
3
6
4
- #[ derive( Deserialize ) ]
5
- struct KeywordList {
6
- keywords : Vec < EncodableKeyword > ,
7
- meta : KeywordMeta ,
8
- }
9
- #[ derive( Deserialize ) ]
10
- struct KeywordMeta {
11
- total : i32 ,
12
- }
13
7
#[ derive( Deserialize ) ]
14
8
struct GoodKeyword {
15
9
keyword : EncodableKeyword ,
@@ -19,18 +13,15 @@ struct GoodKeyword {
19
13
fn index ( ) {
20
14
let url = "/api/v1/keywords" ;
21
15
let ( app, anon) = TestApp :: init ( ) . empty ( ) ;
22
- let json: KeywordList = anon. get ( url) . good ( ) ;
23
- assert_eq ! ( json. keywords. len( ) , 0 ) ;
24
- assert_eq ! ( json. meta. total, 0 ) ;
16
+ let json: Value = anon. get ( url) . good ( ) ;
17
+ assert_json_snapshot ! ( json) ;
25
18
26
19
app. db ( |conn| {
27
20
Keyword :: find_or_create_all ( conn, & [ "foo" ] ) . unwrap ( ) ;
28
21
} ) ;
29
22
30
- let json: KeywordList = anon. get ( url) . good ( ) ;
31
- assert_eq ! ( json. keywords. len( ) , 1 ) ;
32
- assert_eq ! ( json. meta. total, 1 ) ;
33
- assert_eq ! ( json. keywords[ 0 ] . keyword. as_str( ) , "foo" ) ;
23
+ let json: Value = anon. get ( url) . good ( ) ;
24
+ assert_json_snapshot ! ( json, { ".**.created_at" => rfc3339_redaction( ) } ) ;
34
25
}
35
26
36
27
#[ test]
@@ -42,8 +33,9 @@ fn show() {
42
33
app. db ( |conn| {
43
34
Keyword :: find_or_create_all ( conn, & [ "foo" ] ) . unwrap ( ) ;
44
35
} ) ;
45
- let json: GoodKeyword = anon. get ( url) . good ( ) ;
46
- assert_eq ! ( json. keyword. keyword. as_str( ) , "foo" ) ;
36
+
37
+ let json: Value = anon. get ( url) . good ( ) ;
38
+ assert_json_snapshot ! ( json, { ".**.created_at" => rfc3339_redaction( ) } ) ;
47
39
}
48
40
49
41
#[ test]
@@ -55,8 +47,9 @@ fn uppercase() {
55
47
app. db ( |conn| {
56
48
Keyword :: find_or_create_all ( conn, & [ "UPPER" ] ) . unwrap ( ) ;
57
49
} ) ;
58
- let json: GoodKeyword = anon. get ( url) . good ( ) ;
59
- assert_eq ! ( json. keyword. keyword. as_str( ) , "upper" ) ;
50
+
51
+ let json: Value = anon. get ( url) . good ( ) ;
52
+ assert_json_snapshot ! ( json, { ".**.created_at" => rfc3339_redaction( ) } ) ;
60
53
}
61
54
62
55
#[ test]
0 commit comments