diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 626aeb73d..d99bdae29 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -1635,6 +1635,174 @@ mod routes { ); } + #[tokio::test] + async fn test_projects_issue() { + let tmp = tempfile::tempdir().unwrap(); + let app = super::router(seed(tmp.path())); + let response = get(&app, format!("/projects/{RID}/issues/{ISSUE_ID}")).await; + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.json().await, + json!({ + "id": ISSUE_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS + }, + "title": "Issue #1", + "state": { + "status": "open" + }, + "assignees": [], + "discussion": [ + { + "id": ISSUE_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS + }, + "body": "Change 'hello world' to 'hello everyone'", + "edits": [ + { + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": TIMESTAMP, + "embeds": [], + }, + ], + "embeds": [], + "reactions": [], + "timestamp": TIMESTAMP, + "replyTo": null, + "resolved": false, + } + ], + "labels": [] + }) + ); + } + + #[tokio::test] + async fn test_projects_patches_root() { + let tmp = tempfile::tempdir().unwrap(); + let app = super::router(seed(tmp.path())); + let response = get(&app, format!("/projects/{RID}/patches")).await; + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.json().await, + json!([ + { + "id": PATCH_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "title": "A new `hello world`", + "state": { + "status": "open", + }, + "target": "delegates", + "labels": [], + "merges": [], + "assignees": [], + "revisions": [ + { + "id": PATCH_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "description": "change `hello world` in README to something else", + "edits": [ + { + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "body": "change `hello world` in README to something else", + "timestamp": TIMESTAMP, + "embeds": [], + }, + ], + "reactions": [], + "base": "ee8d6a29304623a78ebfa5eeed5af674d0e58f83", + "oid": "e8c676b9e3b42308dc9d218b70faa5408f8e58ca", + "refs": [ + "refs/heads/master", + ], + "discussions": [], + "timestamp": TIMESTAMP, + "reviews": [], + }, + ], + }, + ] + ) + ); + } + + #[tokio::test] + async fn test_projects_patch() { + let tmp = tempfile::tempdir().unwrap(); + let app = super::router(seed(tmp.path())); + let response = get(&app, format!("/projects/{RID}/patches/{PATCH_ID}")).await; + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.json().await, + json!({ + "id": PATCH_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "title": "A new `hello world`", + "state": { + "status": "open", + }, + "target": "delegates", + "labels": [], + "merges": [], + "assignees": [], + "revisions": [ + { + "id": PATCH_ID, + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "description": "change `hello world` in README to something else", + "edits": [ + { + "author": { + "id": DID, + "alias": CONTRIBUTOR_ALIAS, + }, + "body": "change `hello world` in README to something else", + "timestamp": TIMESTAMP, + "embeds": [], + }, + ], + "reactions": [], + "base": "ee8d6a29304623a78ebfa5eeed5af674d0e58f83", + "oid": "e8c676b9e3b42308dc9d218b70faa5408f8e58ca", + "refs": [ + "refs/heads/master", + ], + "discussions": [], + "timestamp": TIMESTAMP, + "reviews": [], + }, + ], + }) + ); + } + #[tokio::test] async fn test_projects_private() { let tmp = tempfile::tempdir().unwrap(); diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index 500609eb8..c24310b1a 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -30,6 +30,7 @@ pub const PARENT: &str = "ee8d6a29304623a78ebfa5eeed5af674d0e58f83"; pub const INITIAL_COMMIT: &str = "f604ce9fd5b7cc77b7609beda45ea8760bee78f7"; pub const DID: &str = "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"; pub const ISSUE_ID: &str = "ca67d195c0b308b51810dedd93157a20764d5db5"; +pub const PATCH_ID: &str = "b4084412ea3644d7dd7ae075c1cbbd4d702db0ec"; pub const TIMESTAMP: u64 = 1671125284; pub const CONTRIBUTOR_ALIAS: &str = "seed";