Repository navigation
Expand file tree
/
Copy pathexecution_setup_composition_root.test.ts
More file actions
117 lines (108 loc) · 5.34 KB
/
Copy pathexecution_setup_composition_root.test.ts
File metadata and controls
117 lines (108 loc) · 5.34 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const issueSetupPort = {
isPullRequest: jest.fn(),
isIssue: jest.fn(),
getHeadBranch: jest.fn(),
getLabels: jest.fn(),
getDescription: jest.fn(),
getTitle: jest.fn(),
};
const organizationSetupPort = { getUserFromToken: jest.fn() };
const configurationPort = { get: jest.fn() };
const releaseVersionUseCase = { kind: 'release-version' };
const releaseTypeUseCase = { kind: 'release-type' };
const hotfixVersionUseCase = { kind: 'hotfix-version' };
const branchVersionResolver = { kind: 'branch-version-resolver' };
const setupExecutionUseCase = { kind: 'setup-execution' };
const createExecutionIssueSetupCompositionRoot = jest.fn(() => issueSetupPort);
const createAuthenticatedUserCompositionRoot = jest.fn(() => organizationSetupPort);
const configurationHandler = jest.fn(() => configurationPort);
const getReleaseVersionUseCase = jest.fn(() => releaseVersionUseCase);
const getReleaseTypeUseCase = jest.fn(() => releaseTypeUseCase);
const getHotfixVersionUseCase = jest.fn(() => hotfixVersionUseCase);
const executionBranchVersionResolver = jest.fn(() => branchVersionResolver);
const setupExecution = jest.fn(() => setupExecutionUseCase);
jest.mock('../execution_issue_setup_composition_root', () => ({
createExecutionIssueSetupCompositionRoot,
}));
jest.mock('../authenticated_user_composition_root', () => ({
createAuthenticatedUserCompositionRoot,
}));
jest.mock('../../../manager/description/configuration_handler', () => ({
ConfigurationHandler: configurationHandler,
}));
jest.mock('../../../application/usecases/steps/common/get_release_version_use_case', () => ({
GetReleaseVersionUseCase: getReleaseVersionUseCase,
}));
jest.mock('../../../application/usecases/steps/common/get_release_type_use_case', () => ({
GetReleaseTypeUseCase: getReleaseTypeUseCase,
}));
jest.mock('../../../application/usecases/steps/common/get_hotfix_version_use_case', () => ({
GetHotfixVersionUseCase: getHotfixVersionUseCase,
}));
jest.mock('../../../application/usecases/execution/execution_branch_version_resolver', () => ({
ExecutionBranchVersionResolver: executionBranchVersionResolver,
}));
jest.mock('../../../application/usecases/execution/setup_execution_use_case', () => ({
SetupExecutionUseCase: setupExecution,
}));
import type { LatestTagQueryPort } from '../../../application/ports/branch_tag_ports';
import type {
SetupConfigurationQueryPort,
SetupIssueQueryPort,
SetupOrganizationQueryPort,
} from '../../../application/ports/setup_execution_ports';
import { createSetupExecutionUseCase } from '../execution_setup_composition_root';
describe('execution setup composition root', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('binds credentials once and exposes only semantic setup operations', async () => {
const latestTagQueryPort = { getLatestTag: jest.fn() } as LatestTagQueryPort;
const credentials = { owner: 'owner', repository: 'repository', token: 'secret-token' };
const result = createSetupExecutionUseCase(latestTagQueryPort, credentials);
expect(result).toBe(setupExecutionUseCase);
expect(configurationHandler).toHaveBeenCalledWith(issueSetupPort);
const semanticIssuePort = (getReleaseVersionUseCase.mock.calls as unknown[][])[0][0] as SetupIssueQueryPort;
expect(getReleaseTypeUseCase).toHaveBeenCalledWith(semanticIssuePort);
expect(getHotfixVersionUseCase).toHaveBeenCalledWith(semanticIssuePort);
expect(executionBranchVersionResolver).toHaveBeenCalledWith(
latestTagQueryPort,
releaseVersionUseCase,
releaseTypeUseCase,
hotfixVersionUseCase,
);
const [, semanticOrganizationPort, semanticConfigurationPort, resolver] = (
setupExecution.mock.calls as unknown[][]
)[0] as [SetupIssueQueryPort, SetupOrganizationQueryPort, SetupConfigurationQueryPort, unknown];
expect(setupExecution).toHaveBeenCalledWith(
semanticIssuePort,
semanticOrganizationPort,
semanticConfigurationPort,
branchVersionResolver,
);
expect(resolver).toBe(branchVersionResolver);
expect(createExecutionIssueSetupCompositionRoot).toHaveBeenCalledTimes(1);
expect(createAuthenticatedUserCompositionRoot).toHaveBeenCalledTimes(1);
await semanticIssuePort.isPullRequest(42);
await semanticIssuePort.isIssue(42);
await semanticIssuePort.getHeadBranch(42);
await semanticIssuePort.getLabels(42);
await semanticIssuePort.getDescription(42);
await semanticIssuePort.getTitle(42);
await semanticOrganizationPort.getTokenUser();
await semanticConfigurationPort.get(42);
expect(issueSetupPort.isPullRequest).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(issueSetupPort.isIssue).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(issueSetupPort.getHeadBranch).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(issueSetupPort.getLabels).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(issueSetupPort.getDescription).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(issueSetupPort.getTitle).toHaveBeenCalledWith('owner', 'repository', 42, 'secret-token');
expect(organizationSetupPort.getUserFromToken).toHaveBeenCalledWith('secret-token');
expect(configurationPort.get).toHaveBeenCalledWith({
owner: 'owner',
repository: 'repository',
issueNumber: 42,
token: 'secret-token',
});
});
});