radicle: UserInfo for Repository::create

The fetch V2 improvements introduced a `UserInfo` type that is used to
set the Git config's name and email when cloning a repository. This
`UserInfo` can also be used when creating a new `Repository`.

The `Storage` type now takes a `UserInfo` so that it can be passed to
`Repository::create`, for creating a new repository.

For testing, this requires adding a new `fixtures::user` so that
testing `Storage` instances can be easily constructed.

It also means that the `radicle-cli` tests all changed with new SHAs
since the name and email are used as part of the hashing input.

N.b. the order of the timelines while testing the identity cob
changed. It's not clear why that is.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2023-11-09 16:43:34 +01:00
committed by cloudhead
parent eb4712e788
commit 85be710155
2 changed files with 31 additions and 24 deletions
+21 -17
View File
@@ -1980,7 +1980,7 @@ mod routes {
#[tokio::test]
async fn test_projects_issues_create() {
const CREATED_ISSUE_ID: &str = "8b42657072f6192cba9e08561582576a975656cd";
const CREATED_ISSUE_ID: &str = "b2d0999498f98b0d1fa12d859d2d0306380333a0";
let tmp = tempfile::tempdir().unwrap();
let ctx = contributor(tmp.path());
@@ -2075,20 +2075,24 @@ mod routes {
"content": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4//8/AAX+Av4N70a4AAAAAElFTkSuQmCC"
}
],
"replyTo": CONTRIBUTOR_ISSUE_ID,
"replyTo": ISSUE_DISCUSSION_ID,
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.success().await, true);
// Get ID to redact later in the test
let response = response.json().await;
let id = &response["id"];
assert!(id.is_string());
let body = serde_json::to_vec(&json!({
"type": "comment.react",
@@ -2099,7 +2103,7 @@ mod routes {
.unwrap();
patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
@@ -2120,23 +2124,23 @@ mod routes {
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
.await;
.await;
assert_eq!(response.success().await, true);
let body = serde_json::to_vec(&json!({
"type": "comment.redact",
"id": "918fff44966e4305523c077c80ac93b1196f1a7e",
"id": id.as_str().unwrap(),
}))
.unwrap();
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
@@ -2146,14 +2150,14 @@ mod routes {
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
)
.await;
assert_eq!(
response.json().await,
json!({
"id": CONTRIBUTOR_ISSUE_ID,
"id": ISSUE_DISCUSSION_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
@@ -2215,7 +2219,7 @@ mod routes {
let _ = get(&app, format!("/projects/{CONTRIBUTOR_RID}/issues")).await;
let response = patch(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
Some(Body::from(body)),
Some(SESSION_ID.to_string()),
)
@@ -2226,14 +2230,14 @@ mod routes {
let response = get(
&app,
format!("/projects/{CONTRIBUTOR_RID}/issues/{CONTRIBUTOR_ISSUE_ID}"),
format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"),
)
.await;
assert_eq!(
response.json().await,
json!({
"id": CONTRIBUTOR_ISSUE_ID,
"id": ISSUE_DISCUSSION_ID,
"author": {
"id": CONTRIBUTOR_DID,
},
@@ -2366,7 +2370,7 @@ mod routes {
#[tokio::test]
async fn test_projects_create_patches() {
const CREATED_PATCH_ID: &str = "beaed2e1d3b9b01ef10326a9a1c951799ba5fb25";
const CREATED_PATCH_ID: &str = "e546f1784df29d0ffd424021ebae556cbd950993";
let tmp = tempfile::tempdir().unwrap();
let ctx = contributor(tmp.path());
@@ -2615,10 +2619,10 @@ mod routes {
"revisions": [
{
"id": CONTRIBUTOR_PATCH_ID,
"description": "change `hello world` in README to something else",
"author": {
"id": CONTRIBUTOR_DID,
},
"description": "change `hello world` in README to something else",
"base": PARENT,
"oid": HEAD,
"refs": [
@@ -2629,7 +2633,7 @@ mod routes {
"reviews": [],
},
{
"id": "341ba93c6db54e5891fbd3be4a4f64f4715681fa",
"id": "50d760ccbcfadddd81fe32bd94283cbfd80133fa",
"author": {
"id": CONTRIBUTOR_DID,
},
+10 -7
View File
@@ -34,23 +34,26 @@ pub const HEAD: &str = "e8c676b9e3b42308dc9d218b70faa5408f8e58ca";
pub const PARENT: &str = "ee8d6a29304623a78ebfa5eeed5af674d0e58f83";
pub const INITIAL_COMMIT: &str = "f604ce9fd5b7cc77b7609beda45ea8760bee78f7";
pub const DID: &str = "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi";
pub const ISSUE_ID: &str = "4f98396a1ac987af59ec069de9b80d9917b27050";
pub const ISSUE_DISCUSSION_ID: &str = "ceafc6629ec8dc0a17644fb5a66726aaafc3ed1c";
pub const ISSUE_COMMENT_ID: &str = "ca48480f3de728ffca0861538310c6a9704a73b7";
pub const ISSUE_ID: &str = "45d118885b6b06360ee539573f5ceb24be2979f8";
pub const ISSUE_DISCUSSION_ID: &str = "d11b03464c9bf58b09460713c8e2c74f0725d3bd";
pub const ISSUE_COMMENT_ID: &str = "e3aa754cb47d2299781fed49cc91c4b41e06c219";
pub const SESSION_ID: &str = "u9MGAkkfkMOv0uDDB2WeUHBT7HbsO2Dy";
pub const TIMESTAMP: u64 = 1671125284;
pub const CONTRIBUTOR_RID: &str = "rad:z4XaCmN3jLSeiMvW15YTDpNbDHFhG";
pub const CONTRIBUTOR_DID: &str = "did:key:z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8";
pub const CONTRIBUTOR_NID: &str = "z6Mkk7oqY4pPxhMmGEotDYsFo97vhCj85BLY1H256HrJmjN8";
pub const CONTRIBUTOR_ISSUE_ID: &str = "ceafc6629ec8dc0a17644fb5a66726aaafc3ed1c";
pub const CONTRIBUTOR_PATCH_ID: &str = "4ff2ec53a2d165da7f54705023e847d4f9230bc3";
pub const CONTRIBUTOR_PATCH_ID: &str = "0867c6389ee073304da0854a83885f47b1d7f5ed";
/// Create a new profile.
pub fn profile(home: &Path, seed: [u8; 32]) -> radicle::Profile {
let home = Home::new(home).unwrap();
let storage = Storage::open(home.storage()).unwrap();
let keystore = Keystore::new(&home.keys());
let keypair = KeyPair::from_seed(Seed::from(seed));
let alias = node::Alias::new("seed");
let storage = Storage::open(home.storage(), radicle::git::UserInfo {
alias: alias.clone(),
key: keypair.pk.into(),
}).unwrap();
radicle::storage::git::transport::local::register(storage.clone());
keystore.store(keypair.clone(), "radicle", None).unwrap();
@@ -61,7 +64,7 @@ pub fn profile(home: &Path, seed: [u8; 32]) -> radicle::Profile {
keystore,
public_key: keypair.pk.into(),
config: profile::Config {
node: node::Config::new(node::Alias::new("seed")),
node: node::Config::new(alias),
},
}
}