Skip to content

Commit eb07f65

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

20 files changed

+169
-1261
lines changed
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

+56
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
});

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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import travis from "../travis";
2+
3+
test.todo("travis.download()");
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import history from "../history";
2+
3+
test.todo("calculate()");
+15
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+
});

β€Žlib/commands/tests/history.test.ts

+3
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 β€Žlib/utils/tests/builds.test.ts

+3-4
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

+4
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 β€Žlib/utils/tests/formatters.test.ts

+1-2
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 β€Žlib/utils/tests/fs.test.ts

+1-2
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");

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as math from "../../lib/utils/math";
1+
import * as math from "../math";
22

33
test("math.getMinMax()", () => {
44
expect(math.getMinMax([1, 2, 3])).toEqual({ min: 1, max: 3 });

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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as times from "../times";
2+
3+
const NOW = Date.now();
4+
const ONE_DAY_AGO = new Date(NOW - times.daysToMs(1));
5+
const ONE_YEAR_AGO = new Date(NOW - times.daysToMs(365));
6+
7+
test("times.daysToMs()", () => {
8+
expect(times.daysToMs(1)).toBe(86400000);
9+
expect(times.daysToMs(2)).toBe(86400000 * 2);
10+
});
11+
12+
test("times.withinDays()", () => {
13+
expect(times.withinDays(NOW, ONE_YEAR_AGO, 2)).toBe(false);
14+
expect(times.withinDays(NOW, ONE_DAY_AGO, 2)).toBe(true);
15+
expect(times.withinDays(NOW, NOW, 2)).toBe(true);
16+
});
17+
18+
test("times.withinLastDays()", () => {
19+
expect(times.withinLastDays(NOW, 2)).toBe(true);
20+
expect(times.withinLastDays(ONE_DAY_AGO, 2)).toBe(true);
21+
expect(times.withinLastDays(ONE_YEAR_AGO, 2)).toBe(false);
22+
});

β€Žpackage.json

+3-14
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@
2323
"engines": {
2424
"node": ">=8.5.0"
2525
},
26-
"ava": {
27-
"files": [
28-
"!__fixtures__/**/*"
29-
],
30-
"extensions": [
31-
"ts"
32-
],
33-
"require": [
34-
"ts-node/register"
26+
"jest": {
27+
"testPathIgnorePatterns": [
28+
"__fixtures__"
3529
]
3630
},
3731
"scripts": {
@@ -61,18 +55,13 @@
6155
"@babel/core": "^7.16.0",
6256
"@babel/preset-env": "^7.16.4",
6357
"@babel/preset-typescript": "^7.16.0",
64-
"@types/chai": "^4.3.0",
65-
"@types/jest": "^27.0.3",
6658
"@types/meow": "^5.0.0",
6759
"@types/node": "^16.11.12",
68-
"@types/sinon": "^10.0.6",
69-
"ava": "^3.15.0",
7060
"babel-jest": "^27.4.4",
7161
"chai": "^4.3.4",
7262
"fixturez": "^1.0.1",
7363
"jest": "^27.4.4",
7464
"prettier": "2.5.1",
75-
"sinon": "^12.0.1",
7665
"ts-node": "^8.6.2",
7766
"typescript": "3.9.10"
7867
}

β€Žtest/adapters/travis.test.ts

-4
This file was deleted.

β€Žtest/commands/calculate.test.ts

-4
This file was deleted.

β€Žtest/commands/download.test.ts

-13
This file was deleted.

β€Žtest/commands/history.test.ts

-4
This file was deleted.

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

-5
This file was deleted.

β€Žtest/utils/times.test.ts

-23
This file was deleted.

0 commit comments

Comments
Β (0)