Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
http: Add missing issue and patch endpoint tests
Sebastian Martinez committed 1 year ago
commit 76fb2e2dc6249a77575f05c79580407132895bc0
parent 6fd6375
2 files changed +169 -0
modified radicle-httpd/src/api/v1/projects.rs
@@ -1636,6 +1636,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();
        let ctx = seed(tmp.path());
modified 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";