-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sdk-client.test.ts
More file actions
91 lines (82 loc) · 3.11 KB
/
Copy pathtest-sdk-client.test.ts
File metadata and controls
91 lines (82 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as sinon from "sinon";
import { GraphAPIClientMock } from "./__tests__/mock/graph-api-client.mock";
import { ToolsAPIClientMock } from "./__tests__/mock/tools-api-client.mock";
import { TestSDKClient } from "./test-sdk-client";
const graphAPIClient = new GraphAPIClientMock();
const toolsAPIClient = new ToolsAPIClientMock();
const testSDKClient = new TestSDKClient(graphAPIClient, toolsAPIClient);
const sandbox = sinon.createSandbox();
const deleteAuthTokenSpy = sandbox.spy(graphAPIClient, "deleteAuthToken");
const pollSpy = sandbox.spy(toolsAPIClient, "poll");
beforeEach(() => sandbox.resetHistory());
afterAll(() => sandbox.restore());
describe("TestSDKClient", () => {
describe("#runBuild", () => {
it("should throw error if graph api client #getAuthToken throws error", async () => {
await expect(
testSDKClient.runBuild({
userKeyId: "user-key-id-error",
userKeySecret: "user-key-secret",
testSuiteId: "test-suite-id",
}),
).rejects.toEqual(new Error("user-key-id-error"));
});
it("should throw error and delete token if tools api client #startBuild throws error", async () => {
const userKeyId = "user-key-id";
const userKeySecret = "user-key-secret";
const testSuiteId = "test-suite-id-error";
const ciBuildId = "ci-build-id";
await expect(
testSDKClient.runBuild({
userKeyId,
userKeySecret,
testSuiteId,
ciBuildId,
}),
).rejects.toEqual(new Error(testSuiteId));
expect(deleteAuthTokenSpy.calledOnceWith(`${userKeyId}|${userKeySecret}`)).toBe(true);
});
it("should throw error and delete token if tools api client #poll throws error", async () => {
const userKeyId = "user-key-id";
const userKeySecret = "user-key-secret";
const testSuiteId = "test-suite-id-build-error";
const ciBuildId = "ci-build-id";
await expect(
testSDKClient.runBuild({
userKeyId,
userKeySecret,
testSuiteId,
ciBuildId,
}),
).rejects.toEqual(new Error("build-id-error"));
});
it("should not poll and delete token in the end if start build option is set", async () => {
const userKeyId = "user-key-id";
const userKeySecret = "user-key-secret";
const testSuiteId = "test-suite-id";
const ciBuildId = "ci-build-id";
await testSDKClient.runBuild({
userKeyId,
userKeySecret,
testSuiteId,
ciBuildId,
isStartOnly: true,
});
expect(pollSpy.notCalled).toBe(true);
expect(deleteAuthTokenSpy.calledOnceWith(`${userKeyId}|${userKeySecret}`)).toBe(true);
});
it("should delete token in the end", async () => {
const userKeyId = "user-key-id";
const userKeySecret = "user-key-secret";
const testSuiteId = "test-suite-id";
const ciBuildId = "ci-build-id";
await testSDKClient.runBuild({
userKeyId,
userKeySecret,
testSuiteId,
ciBuildId,
});
expect(deleteAuthTokenSpy.calledOnceWith(`${userKeyId}|${userKeySecret}`)).toBe(true);
});
});
});