|
| 1 | +const nock = require("nock"); |
| 2 | +nock.disableNetConnect(); |
| 3 | + |
| 4 | +const log = require("../src/mock-debug"); |
| 5 | +const githubPages = require("./github-pages"); |
| 6 | + |
| 7 | +const createBranch = require("./github-pages"); |
| 8 | +const octokit = require("../src/octokit")(); |
| 9 | + |
| 10 | +afterEach(() => { |
| 11 | + if (!nock.isDone()) { |
| 12 | + throw new Error("Not all nock interceptors were used"); |
| 13 | + } |
| 14 | + log.cleanAll(); |
| 15 | + nock.cleanAll(); |
| 16 | +}); |
| 17 | + |
| 18 | +describe("#github-pages", () => { |
| 19 | + it("continues with a log if pages is not enabled", async () => { |
| 20 | + nock("https://api.github.com/").get("/repos/demo/repo/pages").reply(404); |
| 21 | + |
| 22 | + await githubPages({ |
| 23 | + owner: "demo", |
| 24 | + repo: "repo", |
| 25 | + old: "master", |
| 26 | + target: "main", |
| 27 | + octokit, |
| 28 | + log, |
| 29 | + }); |
| 30 | + |
| 31 | + expect(log.logger).toBeCalledWith("No GitHub Pages found for [demo/repo]"); |
| 32 | + }); |
| 33 | + |
| 34 | + it("logs if the configured branch does not match the old branch", async () => { |
| 35 | + nock("https://api.github.com/") |
| 36 | + .get("/repos/demo/repo/pages") |
| 37 | + .reply(200, { |
| 38 | + source: { |
| 39 | + branch: "custom", |
| 40 | + path: "/", |
| 41 | + }, |
| 42 | + }); |
| 43 | + |
| 44 | + await githubPages({ |
| 45 | + owner: "demo", |
| 46 | + repo: "repo", |
| 47 | + old: "master", |
| 48 | + target: "main", |
| 49 | + octokit, |
| 50 | + log, |
| 51 | + }); |
| 52 | + |
| 53 | + expect(log.logger).toBeCalledWith( |
| 54 | + "Skipping GitHub pages as [custom] does not match [master]" |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + it("configures actions with the new branch", async () => { |
| 59 | + nock("https://api.github.com/") |
| 60 | + .get("/repos/demo/repo/pages") |
| 61 | + .reply(200, { |
| 62 | + source: { |
| 63 | + branch: "master", |
| 64 | + path: "/", |
| 65 | + }, |
| 66 | + }); |
| 67 | + |
| 68 | + nock("https://api.github.com/") |
| 69 | + .put("/repos/demo/repo/pages", { source: { branch: "main", path: "/" } }) |
| 70 | + .reply(200); |
| 71 | + |
| 72 | + await githubPages({ |
| 73 | + owner: "demo", |
| 74 | + repo: "repo", |
| 75 | + old: "master", |
| 76 | + target: "main", |
| 77 | + octokit, |
| 78 | + log, |
| 79 | + }); |
| 80 | + |
| 81 | + expect(log.logger).toBeCalledWith( |
| 82 | + "Updated GitHub pages from [master] to [main] with path [/]" |
| 83 | + ); |
| 84 | + }); |
| 85 | + |
| 86 | + it("configures actions with the new branch (custom path)", async () => { |
| 87 | + nock("https://api.github.com/") |
| 88 | + .get("/repos/demo/repo/pages") |
| 89 | + .reply(200, { |
| 90 | + source: { |
| 91 | + branch: "master", |
| 92 | + path: "/docs", |
| 93 | + }, |
| 94 | + }); |
| 95 | + |
| 96 | + nock("https://api.github.com/") |
| 97 | + .put("/repos/demo/repo/pages", { |
| 98 | + source: { branch: "main", path: "/docs" }, |
| 99 | + }) |
| 100 | + .reply(200); |
| 101 | + |
| 102 | + await githubPages({ |
| 103 | + owner: "demo", |
| 104 | + repo: "repo", |
| 105 | + old: "master", |
| 106 | + target: "main", |
| 107 | + octokit, |
| 108 | + log, |
| 109 | + }); |
| 110 | + |
| 111 | + expect(log.logger).toBeCalledWith( |
| 112 | + "Updated GitHub pages from [master] to [main] with path [/docs]" |
| 113 | + ); |
| 114 | + }); |
| 115 | +}); |
0 commit comments