Skip to content

Commit 9931fe3

Browse files
committed
Extract a function for requesting the category list
1 parent 28055c3 commit 9931fe3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/tests/all.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use cargo_registry::{
2121
models::{Crate, CrateOwner, Dependency, NewCategory, NewTeam, NewUser, Team, User, Version},
2222
schema::crate_owners,
2323
util::CargoResult,
24-
views::{EncodableCrate, EncodableKeyword, EncodableOwner, EncodableVersion, GoodCrate},
24+
views::{
25+
EncodableCategory, EncodableCrate, EncodableKeyword, EncodableOwner, EncodableVersion,
26+
GoodCrate,
27+
},
2528
App, Config, Env, Replica, Uploader,
2629
};
2730
use std::{
@@ -114,6 +117,15 @@ pub struct OwnersResponse {
114117
users: Vec<EncodableOwner>,
115118
}
116119
#[derive(Deserialize)]
120+
pub struct CategoryListResponse {
121+
categories: Vec<EncodableCategory>,
122+
meta: CategoryMeta,
123+
}
124+
#[derive(Deserialize)]
125+
pub struct CategoryMeta {
126+
total: i32,
127+
}
128+
#[derive(Deserialize)]
117129
pub struct OkBool {
118130
ok: bool,
119131
}

src/tests/category.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ struct CategoryWithSubcategories {
2727
#[test]
2828
fn index() {
2929
let (app, anon) = TestApp::init().empty();
30-
let url = "/api/v1/categories";
3130

3231
// List 0 categories if none exist
33-
let json: CategoryList = anon.get(url).good();
32+
let json = anon.show_category_list();
3433
assert_eq!(json.categories.len(), 0);
3534
assert_eq!(json.meta.total, 0);
3635

@@ -45,7 +44,7 @@ fn index() {
4544
});
4645

4746
// Only the top-level categories should be on the page
48-
let json: CategoryList = anon.get(url).good();
47+
let json = anon.show_category_list();
4948
assert_eq!(json.categories.len(), 1);
5049
assert_eq!(json.meta.total, 1);
5150
assert_eq!(json.categories[0].category, "foo");

src/tests/util.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! to the underlying database model value (`User` and `ApiToken` respectively).
2121
2222
use crate::{
23-
builders::PublishBuilder, record, CrateList, CrateResponse, GoodCrate,
23+
builders::PublishBuilder, record, CategoryListResponse, CrateList, CrateResponse, GoodCrate,
2424
OkBool, OwnersResponse, VersionResponse,
2525
};
2626
use cargo_registry::{
@@ -394,6 +394,11 @@ pub trait RequestHelper {
394394
let url = format!("/api/v1/crates/{}/{}", krate_name, version);
395395
self.get(&url).good()
396396
}
397+
398+
fn show_category_list(&self) -> CategoryListResponse {
399+
let url = "/api/v1/categories";
400+
self.get(url).good()
401+
}
397402
}
398403

399404
/// A type that can generate unauthenticated requests

0 commit comments

Comments
 (0)