diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-16 16:52:14 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-16 16:52:14 -0400 |
| commit | 0d48769556db3ed313434c7e824339924c8df792 (patch) | |
| tree | ce584b7bd68c709beb2aad53bc0aa45f0165333d /src/routes.test.ts | |
| parent | 6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5 (diff) | |
| download | ao-coverage-0d48769556db3ed313434c7e824339924c8df792.tar.gz ao-coverage-0d48769556db3ed313434c7e824339924c8df792.tar.bz2 ao-coverage-0d48769556db3ed313434c7e824339924c8df792.zip | |
Add format to head commit info
Diffstat (limited to 'src/routes.test.ts')
| -rw-r--r-- | src/routes.test.ts | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/routes.test.ts b/src/routes.test.ts index f8bcfcd..5ffd289 100644 --- a/src/routes.test.ts +++ b/src/routes.test.ts @@ -55,7 +55,8 @@ const config = { }; const mock = ( headCommit: jest.Mock = jest.fn( - () => new Promise(solv => solv("testcommit")) + () => + new Promise(solv => solv({ commit: "testcommit", format: "tarpaulin" })) ), updateBranch: jest.Mock = jest.fn(() => new Promise(solv => solv(true))) ): MetadataMockType => ({ @@ -255,6 +256,25 @@ describe("Badges and reports", () => { expect(res.text).toEqual(buffer.toString("utf-8")); }); + it("should retrieve the marked format as stored in metadata", async () => { + const head = jest.fn( + () => + new Promise(solv => + solv({ commit: "testcommit", format: "cobertura" }) + ) + ); + const mockMeta = mock(head); + // request HTML, get XML + const res = await (await request(mockMeta)) + .get("/v1/testorg/testrepo/testbranch.html") + .expect("Content-Type", /xml/) + .expect(200); + const buffer = await fs.promises.readFile(coberturaReport); + + expect(mockMeta.getHeadCommit).toHaveBeenCalledTimes(1); + expect(res.text).toEqual(buffer.toString("utf-8")); + }); + it("should return 404 if file does not exist", async () => { await (await request()).get("/v1/neorg/nerepo/nebranch.html").expect(404); }); @@ -278,7 +298,13 @@ describe("Badges and reports", () => { describe("GET /v1/:org/:repo/:branch.xml", () => { it("should retrieve the stored report file with the associated head commit", async () => { - const mockMeta = mock(); + const head = jest.fn( + () => + new Promise(solv => + solv({ commit: "testcommit", format: "cobertura" }) + ) + ); + const mockMeta = mock(head); const res = await (await request(mockMeta)) .get("/v1/testorg/testrepo/testbranch.xml") .expect("Content-Type", /xml/) @@ -289,6 +315,25 @@ describe("Badges and reports", () => { expect(res.text).toEqual(buffer.toString("utf-8")); }); + it("should retrieve the marked format as stored in metadata", async () => { + const head = jest.fn( + () => + new Promise(solv => + solv({ commit: "testcommit", format: "tarpaulin" }) + ) + ); + const mockMeta = mock(head); + // request XML, get HTML + const res = await (await request(mockMeta)) + .get("/v1/testorg/testrepo/testbranch.xml") + .expect("Content-Type", /html/) + .expect(200); + const buffer = await fs.promises.readFile(tarpaulinReport); + + expect(mockMeta.getHeadCommit).toHaveBeenCalledTimes(1); + expect(res.text).toEqual(buffer.toString("utf-8")); + }); + it("should return 404 if file does not exist", async () => { await (await request()).get("/v1/neorg/nerepo/nebranch.xml").expect(404); }); @@ -396,7 +441,7 @@ describe("Uploads", () => { organization: "testorg", repository: "testrepo", branch: "newthis", - head: "newthat" + head: { commit: "newthat", format: "tarpaulin" } }); expect(mockMeta.updateBranch).toHaveBeenCalledTimes(1); await fs.promises.access( @@ -489,7 +534,7 @@ describe("Uploads", () => { organization: "testorg", repository: "testrepo", branch: "newthis", - head: "newthat" + head: { commit: "newthat", format: "cobertura" } }); expect(mockMeta.updateBranch).toHaveBeenCalledTimes(1); await fs.promises.access( |
