|
| 1 | +import { expect } from "chai"; |
| 2 | +import { Github } from "../../../src/providers/github/Github.js"; |
| 3 | + |
| 4 | +describe("Test Github read-only methods", function () { |
| 5 | + this.timeout(10000); // Increase timeout for GitHub API calls |
| 6 | + |
| 7 | + const owner = "dappnode"; |
| 8 | + const repo = "DAppNodeSDK"; |
| 9 | + const github = new Github({ owner, repo }); |
| 10 | + |
| 11 | + describe("getRepo", () => { |
| 12 | + it("should return repository data", async () => { |
| 13 | + const result = await github.getRepo(); |
| 14 | + expect(result).to.have.property("name", repo); |
| 15 | + expect(result).to.have.property("owner"); |
| 16 | + expect(result.owner).to.have.property("login", owner); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should throw an error if repo does not exist", async () => { |
| 20 | + const invalidGithub = new Github({ |
| 21 | + owner: "invalid-owner", |
| 22 | + repo: "invalid-repo" |
| 23 | + }); |
| 24 | + try { |
| 25 | + await invalidGithub.getRepo(); |
| 26 | + throw new Error("Expected method to reject."); |
| 27 | + } catch (e) { |
| 28 | + expect(e.message).to.include("Repo does not exist"); |
| 29 | + } |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("listReleases", () => { |
| 34 | + it("should return list of releases", async () => { |
| 35 | + const result = await github.listReleases(); |
| 36 | + expect(result).to.be.an("array"); |
| 37 | + if (result.length > 0) { |
| 38 | + expect(result[0]).to.have.property("tag_name"); |
| 39 | + } |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("getBranch", () => { |
| 44 | + it("should return branch data", async () => { |
| 45 | + const result = await github.getBranch("master"); |
| 46 | + expect(result).to.have.property("name", "master"); |
| 47 | + expect(result).to.have.property("commit"); |
| 48 | + expect(result.commit).to.have.property("sha"); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + describe("listBranches", () => { |
| 53 | + it("should return list of branches", async () => { |
| 54 | + const result = await github.listBranches(); |
| 55 | + expect(result).to.be.an("array"); |
| 56 | + if (result.length > 0) { |
| 57 | + expect(result[0]).to.have.property("name"); |
| 58 | + } |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe("getOpenPrsFromBranch", () => { |
| 63 | + it("should return list of open PRs from a branch", async () => { |
| 64 | + const result = await github.getOpenPrsFromBranch("master"); |
| 65 | + expect(result).to.be.an("array"); |
| 66 | + if (result.length > 0) { |
| 67 | + expect(result[0]).to.have.property("head"); |
| 68 | + expect(result[0].head).to.have.property("ref"); |
| 69 | + } |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments