Skip to content

Commit d702b01

Browse files
committed
tests::util::test_app: Extract with_scoped_token() function
1 parent 53f9b90 commit d702b01

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/tests/util/test_app.rs

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use cargo_registry_index::{Credentials, Repository as WorkerRepository, Reposito
88
use std::{rc::Rc, sync::Arc, time::Duration};
99

1010
use crate::util::github::{MockGitHubClient, MOCK_GITHUB_DATA};
11+
use cargo_registry::models::token::{CrateScope, EndpointScope};
1112
use diesel::PgConnection;
1213
use reqwest::{blocking::Client, Proxy};
1314
use std::collections::HashSet;
@@ -292,6 +293,17 @@ impl TestAppBuilder {
292293
(app, anon, user, token)
293294
}
294295

296+
pub fn with_scoped_token(
297+
self,
298+
crate_scopes: Option<Vec<CrateScope>>,
299+
endpoint_scopes: Option<Vec<EndpointScope>>,
300+
) -> (TestApp, MockAnonymousUser, MockCookieUser, MockTokenUser) {
301+
let (app, anon) = self.empty();
302+
let user = app.db_new_user("foo");
303+
let token = user.db_new_scoped_token("bar", crate_scopes, endpoint_scopes);
304+
(app, anon, user, token)
305+
}
306+
295307
pub fn with_config(mut self, f: impl FnOnce(&mut config::Server)) -> Self {
296308
f(&mut self.config);
297309
self

0 commit comments

Comments
 (0)