Skip to content

Commit eb07f65

Browse files
committed
add bitbucket adapter test
1 parent 28ae21d commit eb07f65

20 files changed

+169
-1261
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"values": [
3+
{
4+
"build_number": 1,
5+
"trigger": {},
6+
"target": {},
7+
"state": {
8+
"name": "COMPLETED",
9+
"result": {
10+
"name": "SUCCESSFUL"
11+
}
12+
},
13+
"uuid": 1,
14+
"created_on": "",
15+
"duration_in_seconds": 17
16+
}
17+
]
18+
}

β€Žlib/adapters/tests/bitbucket.test.tsβ€Ž

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import fs from "fs";
12
import got from "got";
3+
import path from "path";
4+
import fixturez from "fixturez";
5+
import { promisify } from "util";
26
import fetchBitbucketPipeline, { getTotalBuilds } from "../bitbucket";
37

8+
const readFile = promisify(fs.readFile);
9+
const BITBUCKET_API = "https://api.bitbucket.org/2.0/repositories";
10+
411
jest.mock("got");
12+
const f = fixturez(__dirname);
513

614
describe("bitbucket", () => {
715
describe("getTotalBuild", () => {
@@ -25,4 +33,52 @@ describe("bitbucket", () => {
2533
).rejects.toThrow("The Authorisation failed");
2634
});
2735
});
36+
37+
describe("fetchBitbucketPipeline", () => {
38+
it("should write the build info in standard format", async () => {
39+
const testUser = "test-user";
40+
const testRepo = "test-repo";
41+
const tempDir = f.temp();
42+
got.mockImplementation(async (url) => {
43+
if (url === `${BITBUCKET_API}/${testUser}/${testRepo}/pipelines/`)
44+
return Promise.resolve({ body: JSON.stringify({ size: 1 }) });
45+
if (
46+
url ===
47+
`${BITBUCKET_API}/${testUser}/${testRepo}/pipelines/?pagelen=100&page=1&sort=created_on`
48+
) {
49+
const path_to_pipelines_response = f.find(
50+
"bitbucket_pipeline_response.json"
51+
);
52+
const pipeline_response = await readFile(
53+
path_to_pipelines_response,
54+
"utf-8"
55+
);
56+
57+
return {
58+
body: JSON.stringify(JSON.parse(pipeline_response)),
59+
};
60+
}
61+
});
62+
63+
await fetchBitbucketPipeline(tempDir, {
64+
concurrency: 1,
65+
repo: testRepo,
66+
since: "4",
67+
user: testUser,
68+
});
69+
70+
const pipelineData = await readFile(
71+
path.resolve(tempDir, "1.json"),
72+
"utf-8"
73+
);
74+
75+
expect(JSON.parse(pipelineData)).toEqual({
76+
id: 1,
77+
uuid: 1,
78+
createdOn: "",
79+
duration: 17,
80+
result: "SUCCESSFUL",
81+
});
82+
});
83+
});
2884
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import travis from "../travis";
2+
3+
test.todo("travis.download()");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import history from "../history";
2+
3+
test.todo("calculate()");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import download from "../download";
2+
import fixtures from "fixturez";
3+
import adapters from "../../adapters";
4+
import path from "path";
5+
const f = fixtures(__dirname);
6+
7+
jest.mock('../../adapters');
8+
9+
test("it calls bitbucket download with appropiate path", async () => {
10+
adapters.bitbucket = jest.fn();
11+
let cwd = f.find("testRepo");
12+
await download({ cwd, host: "bitbucket", user: "test", repo: "test-repo" });
13+
expect(adapters.bitbucket).toHaveBeenCalledTimes(1);
14+
expect(adapters.bitbucket).toHaveBeenCalledWith(path.join(cwd, ".data", "bitbucket", "test", "test-repo", "builds"), expect.anything())
15+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import history from "../history";
2+
3+
test.todo("history()");

β€Žtest/utils/builds.test.tsβ€Ž renamed to β€Žlib/utils/tests/builds.test.tsβ€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import test from "ava";
21
import fixtures from "fixturez";
3-
import * as builds from "../../lib/utils/builds";
2+
import * as builds from "../builds";
43
const f = fixtures(__dirname);
54

6-
test("builds.getBuildDir()", async (t) => {
5+
test("builds.getBuildDir()", async () => {
76
let cwd = f.copy("testRepo");
87
let dirPath = await builds.getBuildDir(cwd, "bitbucket", "test", "test-repo");
9-
t.regex(dirPath, /testRepo\/\.data\/bitbucket\/test\/test-repo\/builds/);
8+
expect(dirPath).toMatch(/testRepo\/\.data\/bitbucket\/test\/test-repo\/builds/)
109
});
1110

1211
test.todo("builds.getHistory()");

β€Žlib/utils/tests/cli.test.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as cli from "../cli";
2+
3+
test.todo("cli.table");
4+
test.todo("cli.pager");

β€Žtest/utils/formatters.test.tsβ€Ž renamed to β€Žlib/utils/tests/formatters.test.tsβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import test from "ava";
2-
import * as formatters from "../../lib/utils/formatters";
1+
import * as formatters from "../formatters";
32

43
test.todo("formatters.id");
54
test.todo("formatters.duration");

β€Žtest/utils/fs.test.tsβ€Ž renamed to β€Žlib/utils/tests/fs.test.tsβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import test from "ava";
2-
import * as fs from "../../lib/utils/fs";
1+
import * as fs from "../fs";
32

43
test.todo("fs.mkdir");
54
test.todo("fs.readDir");

0 commit comments

Comments
Β (0)