forked from rust-lang/crates.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.rs
More file actions
89 lines (68 loc) · 2.51 KB
/
Copy pathdocs.rs
File metadata and controls
89 lines (68 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::builders::{CrateBuilder, VersionBuilder};
use crate::util::{RequestHelper as _, TestApp};
use crates_io_docs_rs::MockDocsRsClient;
use crates_io_test_utils::builders::UserBuilder;
use insta::assert_snapshot;
#[tokio::test(flavor = "multi_thread")]
async fn test_trigger_rebuild_ok() -> anyhow::Result<()> {
let mut docs_rs_mock = MockDocsRsClient::new();
docs_rs_mock
.expect_rebuild_docs()
.returning(|_, _| Ok(()))
.times(1);
let (app, _client, cookie_client) =
TestApp::full().with_docs_rs(docs_rs_mock).with_user().await;
let mut conn = app.db_conn().await;
CrateBuilder::new("krate", cookie_client.as_model().id)
.version(VersionBuilder::new("0.1.0"))
.build(&mut conn)
.await?;
let response = cookie_client
.post::<()>("/api/v1/crates/krate/0.1.0/rebuild_docs", "")
.await;
assert_snapshot!(response.status(), @"201 Created");
app.run_pending_background_jobs().await;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn test_trigger_rebuild_permission_failed() -> anyhow::Result<()> {
let mut docs_rs_mock = MockDocsRsClient::new();
docs_rs_mock
.expect_rebuild_docs()
.returning(|_, _| Ok(()))
.never();
let (app, _client, cookie_client) =
TestApp::full().with_docs_rs(docs_rs_mock).with_user().await;
let mut conn = app.db_conn().await;
let other_user_id = UserBuilder::new()
.with_username("other_user")
.new_user()
.insert(&conn)
.await?;
CrateBuilder::new("krate", other_user_id)
.version(VersionBuilder::new("0.1.0"))
.build(&mut conn)
.await?;
let response = cookie_client
.post::<()>("/api/v1/crates/krate/0.1.0/rebuild_docs", "")
.await;
assert_snapshot!(response.status(), @"403 Forbidden");
app.run_pending_background_jobs().await;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn test_trigger_rebuild_unknown_crate_doesnt_queue_job() -> anyhow::Result<()> {
let mut docs_rs_mock = MockDocsRsClient::new();
docs_rs_mock
.expect_rebuild_docs()
.returning(|_, _| Ok(()))
.never();
let (app, _client, cookie_client) =
TestApp::full().with_docs_rs(docs_rs_mock).with_user().await;
let response = cookie_client
.post::<()>("/api/v1/crates/krate/0.1.0/rebuild_docs", "")
.await;
assert_snapshot!(response.status(), @"404 Not Found");
app.run_pending_background_jobs().await;
Ok(())
}