Skip to content

Commit ab45d8f

Browse files
committed
tests: Move crate following tests to krate::following module
1 parent ca83d0d commit ab45d8f

File tree

2 files changed

+60
-56
lines changed

2 files changed

+60
-56
lines changed

src/tests/krate/following.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use crate::builders::CrateBuilder;
2+
use crate::util::{RequestHelper, TestApp};
3+
use crate::OkBool;
4+
5+
#[test]
6+
fn diesel_not_found_results_in_404() {
7+
let (_, _, user) = TestApp::init().with_user();
8+
9+
user.get("/api/v1/crates/foo_following/following")
10+
.assert_not_found();
11+
}
12+
13+
#[test]
14+
fn following() {
15+
// TODO: Test anon requests as well?
16+
let (app, _, user) = TestApp::init().with_user();
17+
18+
app.db(|conn| {
19+
CrateBuilder::new("foo_following", user.as_model().id).expect_build(conn);
20+
});
21+
22+
let is_following = || -> bool {
23+
#[derive(Deserialize)]
24+
struct F {
25+
following: bool,
26+
}
27+
28+
user.get::<F>("/api/v1/crates/foo_following/following")
29+
.good()
30+
.following
31+
};
32+
33+
let follow = || {
34+
assert!(
35+
user.put::<OkBool>("/api/v1/crates/foo_following/follow", b"")
36+
.good()
37+
.ok
38+
);
39+
};
40+
41+
let unfollow = || {
42+
assert!(
43+
user.delete::<OkBool>("api/v1/crates/foo_following/follow")
44+
.good()
45+
.ok
46+
);
47+
};
48+
49+
assert!(!is_following());
50+
follow();
51+
follow();
52+
assert!(is_following());
53+
assert_eq!(user.search("following=1").crates.len(), 1);
54+
55+
unfollow();
56+
unfollow();
57+
assert!(!is_following());
58+
assert_eq!(user.search("following=1").crates.len(), 0);
59+
}

src/tests/krate/mod.rs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use diesel::{dsl::*, prelude::*, update};
1313

1414
mod dependencies;
1515
mod downloads;
16+
mod following;
1617
mod publish;
1718
mod summary;
1819
mod versions;
@@ -634,62 +635,6 @@ fn yanked_versions_are_not_considered_for_max_version() {
634635
assert_eq!(json.crates[0].max_version, "1.0.0");
635636
}
636637

637-
#[test]
638-
fn diesel_not_found_results_in_404() {
639-
let (_, _, user) = TestApp::init().with_user();
640-
641-
user.get("/api/v1/crates/foo_following/following")
642-
.assert_not_found();
643-
}
644-
645-
#[test]
646-
fn following() {
647-
// TODO: Test anon requests as well?
648-
let (app, _, user) = TestApp::init().with_user();
649-
650-
app.db(|conn| {
651-
CrateBuilder::new("foo_following", user.as_model().id).expect_build(conn);
652-
});
653-
654-
let is_following = || -> bool {
655-
#[derive(Deserialize)]
656-
struct F {
657-
following: bool,
658-
}
659-
660-
user.get::<F>("/api/v1/crates/foo_following/following")
661-
.good()
662-
.following
663-
};
664-
665-
let follow = || {
666-
assert!(
667-
user.put::<OkBool>("/api/v1/crates/foo_following/follow", b"")
668-
.good()
669-
.ok
670-
);
671-
};
672-
673-
let unfollow = || {
674-
assert!(
675-
user.delete::<OkBool>("api/v1/crates/foo_following/follow")
676-
.good()
677-
.ok
678-
);
679-
};
680-
681-
assert!(!is_following());
682-
follow();
683-
follow();
684-
assert!(is_following());
685-
assert_eq!(user.search("following=1").crates.len(), 1);
686-
687-
unfollow();
688-
unfollow();
689-
assert!(!is_following());
690-
assert_eq!(user.search("following=1").crates.len(), 0);
691-
}
692-
693638
#[test]
694639
fn yank_works_as_intended() {
695640
let (app, anon, cookie, token) = TestApp::full().with_token();

0 commit comments

Comments
 (0)