@pagopa/dx-cli 0.22.4 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/adapters/commander/commands/add.d.ts +2 -6
- package/dist/adapters/commander/commands/add.js +4 -8
- package/dist/adapters/commander/commands/init.d.ts +2 -6
- package/dist/adapters/commander/commands/init.js +6 -5
- package/dist/adapters/commander/commands/savemoney.d.ts +11 -0
- package/dist/adapters/commander/commands/savemoney.js +30 -5
- package/dist/adapters/commander/commands/spec.d.ts +10 -0
- package/dist/adapters/commander/commands/spec.js +13 -0
- package/dist/adapters/commander/index.js +6 -2
- package/dist/adapters/commander/spec.d.ts +16 -0
- package/dist/adapters/commander/spec.js +54 -0
- package/dist/adapters/plop/generators/environment/actions.js +3 -3
- package/dist/adapters/plop/index.js +3 -5
- package/dist/adapters/plop/templates-path.d.ts +5 -0
- package/dist/adapters/plop/templates-path.js +6 -0
- package/dist/domain/dependencies.d.ts +15 -2
- package/dist/domain/spec.d.ts +50 -0
- package/dist/domain/spec.js +8 -0
- package/dist/index.js +15 -12
- package/package.json +5 -5
- package/templates/monorepo/nx.json +0 -1
- package/dist/adapters/azure/__tests__/cloud-account-repository.test.d.ts +0 -1
- package/dist/adapters/azure/__tests__/cloud-account-repository.test.js +0 -95
- package/dist/adapters/azure/__tests__/cloud-account-service.test.d.ts +0 -1
- package/dist/adapters/azure/__tests__/cloud-account-service.test.js +0 -378
- package/dist/adapters/codemods/__tests__/registry.test.d.ts +0 -1
- package/dist/adapters/codemods/__tests__/registry.test.js +0 -56
- package/dist/adapters/codemods/__tests__/use-azure-appsvc.test.d.ts +0 -1
- package/dist/adapters/codemods/__tests__/use-azure-appsvc.test.js +0 -77
- package/dist/adapters/codemods/__tests__/use-pnpm.test.d.ts +0 -1
- package/dist/adapters/codemods/__tests__/use-pnpm.test.js +0 -148
- package/dist/adapters/commander/__tests__/env.test.d.ts +0 -1
- package/dist/adapters/commander/__tests__/env.test.js +0 -45
- package/dist/adapters/commander/__tests__/error-reporting.test.d.ts +0 -1
- package/dist/adapters/commander/__tests__/error-reporting.test.js +0 -63
- package/dist/adapters/commander/__tests__/exit-with-error.test.d.ts +0 -1
- package/dist/adapters/commander/__tests__/exit-with-error.test.js +0 -92
- package/dist/adapters/commander/__tests__/global-options.test.d.ts +0 -1
- package/dist/adapters/commander/__tests__/global-options.test.js +0 -33
- package/dist/adapters/commander/commands/__tests__/add.test.d.ts +0 -4
- package/dist/adapters/commander/commands/__tests__/add.test.js +0 -167
- package/dist/adapters/commander/commands/__tests__/init.test.d.ts +0 -4
- package/dist/adapters/commander/commands/__tests__/init.test.js +0 -48
- package/dist/adapters/commander/commands/__tests__/preconditions.test.d.ts +0 -1
- package/dist/adapters/commander/commands/__tests__/preconditions.test.js +0 -32
- package/dist/adapters/commander/presenters/__tests__/index.test.d.ts +0 -1
- package/dist/adapters/commander/presenters/__tests__/index.test.js +0 -23
- package/dist/adapters/commander/presenters/__tests__/json.test.d.ts +0 -1
- package/dist/adapters/commander/presenters/__tests__/json.test.js +0 -108
- package/dist/adapters/commander/presenters/__tests__/text.test.d.ts +0 -1
- package/dist/adapters/commander/presenters/__tests__/text.test.js +0 -60
- package/dist/adapters/github/__tests__/github-repo.spec.d.ts +0 -1
- package/dist/adapters/github/__tests__/github-repo.spec.js +0 -67
- package/dist/adapters/node/__tests__/data.d.ts +0 -18
- package/dist/adapters/node/__tests__/data.js +0 -22
- package/dist/adapters/node/__tests__/package-json.test.d.ts +0 -1
- package/dist/adapters/node/__tests__/package-json.test.js +0 -86
- package/dist/adapters/node/__tests__/repository.test.d.ts +0 -1
- package/dist/adapters/node/__tests__/repository.test.js +0 -77
- package/dist/adapters/node/fs/__tests__/file-reader.test.d.ts +0 -1
- package/dist/adapters/node/fs/__tests__/file-reader.test.js +0 -80
- package/dist/adapters/node/json/__tests__/index.test.d.ts +0 -1
- package/dist/adapters/node/json/__tests__/index.test.js +0 -14
- package/dist/adapters/octokit/__tests__/index.test.d.ts +0 -1
- package/dist/adapters/octokit/__tests__/index.test.js +0 -414
- package/dist/adapters/pagopa-technology/__tests__/authorization.test.d.ts +0 -4
- package/dist/adapters/pagopa-technology/__tests__/authorization.test.js +0 -548
- package/dist/adapters/plop/__tests__/run-actions.test.d.ts +0 -1
- package/dist/adapters/plop/__tests__/run-actions.test.js +0 -68
- package/dist/adapters/plop/actions/__tests__/init-cloud-accounts.test.d.ts +0 -1
- package/dist/adapters/plop/actions/__tests__/init-cloud-accounts.test.js +0 -171
- package/dist/adapters/plop/actions/__tests__/provision-terraform-backend.test.d.ts +0 -1
- package/dist/adapters/plop/actions/__tests__/provision-terraform-backend.test.js +0 -134
- package/dist/adapters/plop/generators/environment/__tests__/actions.test.d.ts +0 -2
- package/dist/adapters/plop/generators/environment/__tests__/actions.test.js +0 -92
- package/dist/adapters/plop/generators/environment/__tests__/prompts.test.d.ts +0 -1
- package/dist/adapters/plop/generators/environment/__tests__/prompts.test.js +0 -182
- package/dist/adapters/plop/helpers/__tests__/resource-prefix.test.d.ts +0 -1
- package/dist/adapters/plop/helpers/__tests__/resource-prefix.test.js +0 -113
- package/dist/adapters/plop/helpers/__tests__/terraform-state-key.test.d.ts +0 -1
- package/dist/adapters/plop/helpers/__tests__/terraform-state-key.test.js +0 -35
- package/dist/adapters/plop/helpers/__tests__/validate-prompt.test.d.ts +0 -1
- package/dist/adapters/plop/helpers/__tests__/validate-prompt.test.js +0 -60
- package/dist/adapters/yaml/__tests__/index.test.d.ts +0 -1
- package/dist/adapters/yaml/__tests__/index.test.js +0 -53
- package/dist/domain/__tests__/data.d.ts +0 -19
- package/dist/domain/__tests__/data.js +0 -28
- package/dist/domain/__tests__/environment.test.d.ts +0 -1
- package/dist/domain/__tests__/environment.test.js +0 -332
- package/dist/domain/__tests__/info.test.d.ts +0 -1
- package/dist/domain/__tests__/info.test.js +0 -77
- package/dist/domain/__tests__/package-json.test.d.ts +0 -1
- package/dist/domain/__tests__/package-json.test.js +0 -39
- package/dist/domain/__tests__/repository.test.d.ts +0 -1
- package/dist/domain/__tests__/repository.test.js +0 -111
- package/dist/domain/__tests__/workspace.test.d.ts +0 -1
- package/dist/domain/__tests__/workspace.test.js +0 -57
- package/dist/use-cases/__tests__/apply-codemod.test.d.ts +0 -1
- package/dist/use-cases/__tests__/apply-codemod.test.js +0 -71
- package/dist/use-cases/__tests__/list-codemods.test.d.ts +0 -1
- package/dist/use-cases/__tests__/list-codemods.test.js +0 -37
- package/dist/use-cases/__tests__/request-authorization.test.d.ts +0 -4
- package/dist/use-cases/__tests__/request-authorization.test.js +0 -43
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { errAsync, okAsync } from "neverthrow";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { getInfo } from "../info.js";
|
|
4
|
-
import { makeMockDependencies, makeMockPackageJson, makeMockRepositoryRoot, } from "./data.js";
|
|
5
|
-
describe("getInfo", () => {
|
|
6
|
-
describe("packageManager", () => {
|
|
7
|
-
it("should return default packageManager (npm) when packageManager is not detected", async () => {
|
|
8
|
-
const mockPackageJson = makeMockPackageJson({
|
|
9
|
-
packageManager: undefined,
|
|
10
|
-
});
|
|
11
|
-
const mockDependencies = makeMockDependencies();
|
|
12
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
13
|
-
mockDependencies.repositoryReader.findRepositoryRoot.mockReturnValue(okAsync(repositoryRoot));
|
|
14
|
-
mockDependencies.packageJsonReader.readPackageJson.mockReturnValue(okAsync(mockPackageJson));
|
|
15
|
-
mockDependencies.repositoryReader.fileExists.mockReturnValue(okAsync(false));
|
|
16
|
-
mockDependencies.repositoryReader.readFile.mockReturnValue(okAsync("22.0.0"));
|
|
17
|
-
const result = await getInfo(mockDependencies)();
|
|
18
|
-
expect(result.packageManager).toStrictEqual("npm");
|
|
19
|
-
expect(mockDependencies.repositoryReader.fileExists).nthCalledWith(1, "a/repo/root/pnpm-lock.yaml");
|
|
20
|
-
expect(mockDependencies.repositoryReader.fileExists).nthCalledWith(2, "a/repo/root/yarn.lock");
|
|
21
|
-
expect(mockDependencies.repositoryReader.fileExists).nthCalledWith(3, "a/repo/root/package-lock.json");
|
|
22
|
-
});
|
|
23
|
-
it("should return yarn when yarn.lock is present", async () => {
|
|
24
|
-
const mockPackageJson = makeMockPackageJson({
|
|
25
|
-
packageManager: undefined,
|
|
26
|
-
});
|
|
27
|
-
const mockDependencies = makeMockDependencies();
|
|
28
|
-
mockDependencies.packageJsonReader.readPackageJson.mockReturnValue(okAsync(mockPackageJson));
|
|
29
|
-
mockDependencies.repositoryReader.fileExists
|
|
30
|
-
.mockReturnValueOnce(okAsync(false))
|
|
31
|
-
.mockReturnValueOnce(okAsync(true)); // yarn lock file exists
|
|
32
|
-
mockDependencies.repositoryReader.readFile.mockReturnValue(okAsync("22.0.0"));
|
|
33
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
34
|
-
mockDependencies.repositoryReader.findRepositoryRoot.mockReturnValue(okAsync(repositoryRoot));
|
|
35
|
-
const result = await getInfo(mockDependencies)();
|
|
36
|
-
expect(result.packageManager).toStrictEqual("yarn");
|
|
37
|
-
expect(mockDependencies.repositoryReader.fileExists).nthCalledWith(1, "a/repo/root/pnpm-lock.yaml");
|
|
38
|
-
expect(mockDependencies.repositoryReader.fileExists).nthCalledWith(2, "a/repo/root/yarn.lock");
|
|
39
|
-
expect(mockDependencies.repositoryReader.fileExists).not.toHaveBeenCalledWith("a/repo/root/package-lock.json");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
it("should return all info", async () => {
|
|
43
|
-
const mockPackageJson = makeMockPackageJson({
|
|
44
|
-
devDependencies: new Map([["turbo", "^2.5.0"]]),
|
|
45
|
-
});
|
|
46
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
47
|
-
const mockDependencies = makeMockDependencies();
|
|
48
|
-
mockDependencies.repositoryReader.findRepositoryRoot.mockReturnValue(okAsync(repositoryRoot));
|
|
49
|
-
mockDependencies.packageJsonReader.readPackageJson.mockReturnValue(okAsync(mockPackageJson));
|
|
50
|
-
mockDependencies.repositoryReader.readFile
|
|
51
|
-
.mockReturnValueOnce(okAsync("\n22.0.0\n"))
|
|
52
|
-
.mockReturnValueOnce(okAsync("1.0.0\n"));
|
|
53
|
-
const result = await getInfo(mockDependencies)();
|
|
54
|
-
expect(result).toStrictEqual({
|
|
55
|
-
node: "22.0.0",
|
|
56
|
-
packageManager: "pnpm",
|
|
57
|
-
terraform: "1.0.0",
|
|
58
|
-
turbo: "^2.5.0",
|
|
59
|
-
});
|
|
60
|
-
expect(mockDependencies.repositoryReader.readFile).toHaveBeenCalledWith("a/repo/root/.node-version");
|
|
61
|
-
expect(mockDependencies.repositoryReader.readFile).toHaveBeenCalledWith("a/repo/root/.terraform-version");
|
|
62
|
-
});
|
|
63
|
-
it("should only required information", async () => {
|
|
64
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
65
|
-
const mockDependencies = makeMockDependencies();
|
|
66
|
-
mockDependencies.repositoryReader.findRepositoryRoot.mockReturnValue(okAsync(repositoryRoot));
|
|
67
|
-
mockDependencies.packageJsonReader.readPackageJson.mockReturnValue(okAsync(makeMockPackageJson()));
|
|
68
|
-
mockDependencies.repositoryReader.readFile.mockReturnValue(errAsync(new Error("File not found")));
|
|
69
|
-
const result = await getInfo(mockDependencies)();
|
|
70
|
-
expect(result).toStrictEqual({
|
|
71
|
-
node: undefined,
|
|
72
|
-
packageManager: "pnpm",
|
|
73
|
-
terraform: undefined,
|
|
74
|
-
turbo: undefined,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { errAsync, ok, okAsync } from "neverthrow";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { checkMonorepoScripts } from "../package-json.js";
|
|
4
|
-
import { makeMockDependencies, makeMockRepositoryRoot } from "./data.js";
|
|
5
|
-
describe("checkMonorepoScripts", () => {
|
|
6
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
7
|
-
it("should return error result when getScripts fails", async () => {
|
|
8
|
-
const deps = makeMockDependencies();
|
|
9
|
-
const errorMessage = "Oh No!";
|
|
10
|
-
deps.packageJsonReader.getScripts.mockReturnValueOnce(errAsync(new Error(errorMessage)));
|
|
11
|
-
const result = await checkMonorepoScripts(deps, repositoryRoot);
|
|
12
|
-
expect(result.isErr()).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
it("should return ok result with successful validation when all required scripts are present", async () => {
|
|
15
|
-
const deps = makeMockDependencies();
|
|
16
|
-
const scripts = new Map()
|
|
17
|
-
.set("build", "eslint .")
|
|
18
|
-
.set("code-review", "eslint .");
|
|
19
|
-
deps.packageJsonReader.getScripts.mockReturnValueOnce(okAsync(scripts));
|
|
20
|
-
deps.packageJsonReader.getRootRequiredScripts.mockReturnValueOnce(new Map().set("code-review", "eslint ."));
|
|
21
|
-
const result = await checkMonorepoScripts(deps, repositoryRoot);
|
|
22
|
-
expect(result).toStrictEqual(ok({
|
|
23
|
-
checkName: "Monorepo Scripts",
|
|
24
|
-
isValid: true,
|
|
25
|
-
successMessage: "Monorepo scripts are correctly set up",
|
|
26
|
-
}));
|
|
27
|
-
});
|
|
28
|
-
it("should return ok result with failed validation when required scripts are missing", async () => {
|
|
29
|
-
const deps = makeMockDependencies();
|
|
30
|
-
deps.packageJsonReader.getScripts.mockReturnValueOnce(okAsync(new Map()));
|
|
31
|
-
deps.packageJsonReader.getRootRequiredScripts.mockReturnValueOnce(new Map().set("code-review", "eslint ."));
|
|
32
|
-
const result = await checkMonorepoScripts(deps, repositoryRoot);
|
|
33
|
-
expect(result).toStrictEqual(ok({
|
|
34
|
-
checkName: "Monorepo Scripts",
|
|
35
|
-
errorMessage: "Missing required scripts: code-review",
|
|
36
|
-
isValid: false,
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { errAsync, ok, okAsync } from "neverthrow";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { checkNxConfig, checkPreCommitConfig } from "../repository.js";
|
|
4
|
-
import { makeMockConfig, makeMockDependencies, makeMockRepositoryRoot, } from "./data.js";
|
|
5
|
-
describe("checkPreCommitConfig", () => {
|
|
6
|
-
it("should return ok result with successful validation when .pre-commit-config.yaml exists", async () => {
|
|
7
|
-
const deps = makeMockDependencies();
|
|
8
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
9
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
10
|
-
const result = await checkPreCommitConfig(deps, repositoryRoot);
|
|
11
|
-
expect(result).toStrictEqual(ok({
|
|
12
|
-
checkName: "Pre-commit Configuration",
|
|
13
|
-
isValid: true,
|
|
14
|
-
successMessage: "Pre-commit configuration is present in the repository root",
|
|
15
|
-
}));
|
|
16
|
-
expect(deps.repositoryReader.fileExists).toHaveBeenCalledWith("a/repo/root/.pre-commit-config.yaml");
|
|
17
|
-
});
|
|
18
|
-
it("should return ok result with failed validation when .pre-commit-config.yaml does not exist", async () => {
|
|
19
|
-
const deps = makeMockDependencies();
|
|
20
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
21
|
-
const errorMessage = ".pre-commit-config.yaml not found in repository root. Make sure to have pre-commit configured for the repository.";
|
|
22
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(errAsync(new Error(errorMessage)));
|
|
23
|
-
const result = await checkPreCommitConfig(deps, repositoryRoot);
|
|
24
|
-
expect(result).toStrictEqual(ok({
|
|
25
|
-
checkName: "Pre-commit Configuration",
|
|
26
|
-
errorMessage,
|
|
27
|
-
isValid: false,
|
|
28
|
-
}));
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("checkNxConfig", () => {
|
|
32
|
-
const config = makeMockConfig();
|
|
33
|
-
const repositoryRoot = makeMockRepositoryRoot();
|
|
34
|
-
it("should return ok result with successful validation when nx.json exists and nx dependency is present", async () => {
|
|
35
|
-
const deps = makeMockDependencies();
|
|
36
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
37
|
-
deps.packageJsonReader.getDependencies.mockReturnValueOnce(okAsync(new Map().set("nx", "^22.6.1")));
|
|
38
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
39
|
-
expect(result).toStrictEqual(ok({
|
|
40
|
-
checkName: "Nx Configuration",
|
|
41
|
-
isValid: true,
|
|
42
|
-
successMessage: "Nx configuration is present in the monorepo root and Nx dependency is installed",
|
|
43
|
-
}));
|
|
44
|
-
expect(deps.repositoryReader.fileExists).toHaveBeenCalledWith("a/repo/root/nx.json");
|
|
45
|
-
});
|
|
46
|
-
it("should return ok result with failed validation when nx.json exists but Nx dependency is missing", async () => {
|
|
47
|
-
const deps = makeMockDependencies();
|
|
48
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
49
|
-
deps.packageJsonReader.getDependencies.mockReturnValueOnce(okAsync(new Map().set("eslint", "^8.0.0")));
|
|
50
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
51
|
-
expect(result).toStrictEqual(ok({
|
|
52
|
-
checkName: "Nx Configuration",
|
|
53
|
-
errorMessage: "Nx dependency not found in devDependencies. Please add 'nx' to your devDependencies.",
|
|
54
|
-
isValid: false,
|
|
55
|
-
}));
|
|
56
|
-
});
|
|
57
|
-
it("should return ok result with failed validation when nx.json does not exist", async () => {
|
|
58
|
-
const deps = makeMockDependencies();
|
|
59
|
-
const errorMessage = "nx.json not found in repository root. Make sure to have Nx configured for the monorepo.";
|
|
60
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(errAsync(new Error(errorMessage)));
|
|
61
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
62
|
-
expect(result).toStrictEqual(ok({
|
|
63
|
-
checkName: "Nx Configuration",
|
|
64
|
-
errorMessage,
|
|
65
|
-
isValid: false,
|
|
66
|
-
}));
|
|
67
|
-
});
|
|
68
|
-
it("should return ok result with failed validation when fileExists returns ok(false)", async () => {
|
|
69
|
-
const deps = makeMockDependencies();
|
|
70
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(false));
|
|
71
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
72
|
-
expect(result).toStrictEqual(ok({
|
|
73
|
-
checkName: "Nx Configuration",
|
|
74
|
-
errorMessage: "nx.json not found in repository root. Make sure to have Nx configured for the monorepo.",
|
|
75
|
-
isValid: false,
|
|
76
|
-
}));
|
|
77
|
-
});
|
|
78
|
-
it("should return the error message when nx is not listed in devDependencies", async () => {
|
|
79
|
-
const deps = makeMockDependencies();
|
|
80
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
81
|
-
deps.packageJsonReader.getDependencies.mockReturnValueOnce(okAsync(new Map().set("eslint", "^8.0.0")));
|
|
82
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
83
|
-
expect(result).toStrictEqual(ok({
|
|
84
|
-
checkName: "Nx Configuration",
|
|
85
|
-
errorMessage: "Nx dependency not found in devDependencies. Please add 'nx' to your devDependencies.",
|
|
86
|
-
isValid: false,
|
|
87
|
-
}));
|
|
88
|
-
});
|
|
89
|
-
it("should return the error message when nx version is less than minimum", async () => {
|
|
90
|
-
const deps = makeMockDependencies();
|
|
91
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
92
|
-
deps.packageJsonReader.getDependencies.mockReturnValueOnce(okAsync(new Map().set("nx", "1.0.0")));
|
|
93
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
94
|
-
expect(result).toStrictEqual(ok({
|
|
95
|
-
checkName: "Nx Configuration",
|
|
96
|
-
errorMessage: `Nx version (1.0.0) is too low. Minimum required version is ${config.minVersions.nx}.`,
|
|
97
|
-
isValid: false,
|
|
98
|
-
}));
|
|
99
|
-
});
|
|
100
|
-
it("should return the success message when nx version is ok", async () => {
|
|
101
|
-
const deps = makeMockDependencies();
|
|
102
|
-
deps.repositoryReader.fileExists.mockReturnValueOnce(okAsync(true));
|
|
103
|
-
deps.packageJsonReader.getDependencies.mockReturnValueOnce(okAsync(new Map().set("nx", config.minVersions.nx)));
|
|
104
|
-
const result = await checkNxConfig(deps, repositoryRoot, config);
|
|
105
|
-
expect(result).toStrictEqual(ok({
|
|
106
|
-
checkName: "Nx Configuration",
|
|
107
|
-
isValid: true,
|
|
108
|
-
successMessage: "Nx configuration is present in the monorepo root and Nx dependency is installed",
|
|
109
|
-
}));
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { err, ok } from "neverthrow";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { checkWorkspaces, workspaceSchema } from "../workspace.js";
|
|
4
|
-
import { makeMockDependencies } from "./data.js";
|
|
5
|
-
describe("checkWorkspaces", () => {
|
|
6
|
-
const monorepoDir = "/path/to/monorepo";
|
|
7
|
-
const validWorkspaces = [
|
|
8
|
-
workspaceSchema.parse({
|
|
9
|
-
name: "workspace1",
|
|
10
|
-
path: "/path/to/workspace1",
|
|
11
|
-
}),
|
|
12
|
-
workspaceSchema.parse({
|
|
13
|
-
name: "workspace2",
|
|
14
|
-
path: "/path/to/workspace2",
|
|
15
|
-
}),
|
|
16
|
-
];
|
|
17
|
-
it("should return the list of workspaces", async () => {
|
|
18
|
-
const deps = makeMockDependencies();
|
|
19
|
-
deps.repositoryReader.getWorkspaces.mockResolvedValueOnce(ok(validWorkspaces));
|
|
20
|
-
const result = await checkWorkspaces(deps, monorepoDir);
|
|
21
|
-
expect(result).toStrictEqual(ok({
|
|
22
|
-
checkName: "Workspaces",
|
|
23
|
-
isValid: true,
|
|
24
|
-
successMessage: "Found 2 workspaces",
|
|
25
|
-
}));
|
|
26
|
-
});
|
|
27
|
-
it("should return error when getWorkspaces fails", async () => {
|
|
28
|
-
const deps = makeMockDependencies();
|
|
29
|
-
deps.repositoryReader.getWorkspaces.mockResolvedValueOnce(err(new Error("Failed to get workspaces")));
|
|
30
|
-
const result = await checkWorkspaces(deps, monorepoDir);
|
|
31
|
-
expect(result).toStrictEqual(ok({
|
|
32
|
-
checkName: "Workspaces",
|
|
33
|
-
errorMessage: "Something is wrong with the workspaces configuration. If you need help, please contact the DevEx team.",
|
|
34
|
-
isValid: false,
|
|
35
|
-
}));
|
|
36
|
-
});
|
|
37
|
-
it("should return success when workspaces are found", async () => {
|
|
38
|
-
const deps = makeMockDependencies();
|
|
39
|
-
deps.repositoryReader.getWorkspaces.mockResolvedValueOnce(ok([validWorkspaces[0]]));
|
|
40
|
-
const result = await checkWorkspaces(deps, monorepoDir);
|
|
41
|
-
expect(result).toStrictEqual(ok({
|
|
42
|
-
checkName: "Workspaces",
|
|
43
|
-
isValid: true,
|
|
44
|
-
successMessage: "Found 1 workspace",
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
47
|
-
it("should return error when no workspace configuration is found", async () => {
|
|
48
|
-
const deps = makeMockDependencies();
|
|
49
|
-
deps.repositoryReader.getWorkspaces.mockResolvedValueOnce(ok([]));
|
|
50
|
-
const result = await checkWorkspaces(deps, monorepoDir);
|
|
51
|
-
expect(result).toStrictEqual(ok({
|
|
52
|
-
checkName: "Workspaces",
|
|
53
|
-
errorMessage: "No workspace configuration found. Make sure to configure workspaces in pnpm-workspace.yaml.",
|
|
54
|
-
isValid: false,
|
|
55
|
-
}));
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { errAsync, okAsync } from "neverthrow";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { applyCodemodById } from "../apply-codemod.js";
|
|
4
|
-
const info = vi.fn().mockResolvedValue({
|
|
5
|
-
packageManager: "npm",
|
|
6
|
-
});
|
|
7
|
-
describe("applyCodemodById", () => {
|
|
8
|
-
it("applies the codemod when found", async () => {
|
|
9
|
-
const apply = vi.fn().mockResolvedValue(undefined);
|
|
10
|
-
const codemod = {
|
|
11
|
-
apply,
|
|
12
|
-
description: "test codemod",
|
|
13
|
-
id: "foo",
|
|
14
|
-
};
|
|
15
|
-
const registry = {
|
|
16
|
-
getAll: vi.fn(),
|
|
17
|
-
getById: vi
|
|
18
|
-
.fn()
|
|
19
|
-
.mockReturnValue(okAsync(codemod)),
|
|
20
|
-
};
|
|
21
|
-
const result = await applyCodemodById(registry, info)("foo");
|
|
22
|
-
expect(result.isOk()).toBe(true);
|
|
23
|
-
expect(apply).toHaveBeenCalledTimes(1);
|
|
24
|
-
});
|
|
25
|
-
it("returns an error when codemod is not found", async () => {
|
|
26
|
-
const registry = {
|
|
27
|
-
getAll: vi.fn(),
|
|
28
|
-
getById: vi
|
|
29
|
-
.fn()
|
|
30
|
-
.mockReturnValue(okAsync(undefined)),
|
|
31
|
-
};
|
|
32
|
-
const result = await applyCodemodById(registry, info)("missing-id");
|
|
33
|
-
expect(result.isErr()).toBe(true);
|
|
34
|
-
const value = result.isErr() ? result.error : null;
|
|
35
|
-
expect(value).toBeInstanceOf(Error);
|
|
36
|
-
expect(value?.message).toBe("Codemod with id missing-id not found");
|
|
37
|
-
});
|
|
38
|
-
it("propagates getById errors", async () => {
|
|
39
|
-
const registryError = new Error("registry failed");
|
|
40
|
-
const registry = {
|
|
41
|
-
getAll: vi.fn(),
|
|
42
|
-
getById: vi
|
|
43
|
-
.fn()
|
|
44
|
-
.mockReturnValue(errAsync(registryError)),
|
|
45
|
-
};
|
|
46
|
-
const result = await applyCodemodById(registry, info)("foo");
|
|
47
|
-
expect(result.isErr()).toBe(true);
|
|
48
|
-
const value = result.isErr() ? result.error : null;
|
|
49
|
-
expect(value).toBeInstanceOf(Error);
|
|
50
|
-
expect(value?.message).toContain(registryError.message);
|
|
51
|
-
});
|
|
52
|
-
it("propagates apply errors", async () => {
|
|
53
|
-
const applyError = new Error("apply failed");
|
|
54
|
-
const codemod = {
|
|
55
|
-
apply: vi.fn().mockRejectedValue(applyError),
|
|
56
|
-
description: "test codemod",
|
|
57
|
-
id: "foo",
|
|
58
|
-
};
|
|
59
|
-
const registry = {
|
|
60
|
-
getAll: vi.fn(),
|
|
61
|
-
getById: vi
|
|
62
|
-
.fn()
|
|
63
|
-
.mockReturnValue(okAsync(codemod)),
|
|
64
|
-
};
|
|
65
|
-
const result = await applyCodemodById(registry, info)("foo");
|
|
66
|
-
expect(result.isErr()).toBe(true);
|
|
67
|
-
const value = result.isErr() ? result.error : null;
|
|
68
|
-
expect(value).toBeInstanceOf(Error);
|
|
69
|
-
expect(value?.message).toContain(applyError.message);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { errAsync, okAsync } from "neverthrow";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { listCodemods } from "../list-codemods.js";
|
|
4
|
-
describe("listCodemods", () => {
|
|
5
|
-
it("returns codemods from the registry", async () => {
|
|
6
|
-
const codemods = [
|
|
7
|
-
{
|
|
8
|
-
apply: vi.fn().mockResolvedValue(undefined),
|
|
9
|
-
description: "a",
|
|
10
|
-
id: "a",
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
apply: vi.fn().mockResolvedValue(undefined),
|
|
14
|
-
description: "b",
|
|
15
|
-
id: "b",
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
const registry = {
|
|
19
|
-
getAll: vi.fn().mockReturnValue(okAsync(codemods)),
|
|
20
|
-
getById: vi.fn(),
|
|
21
|
-
};
|
|
22
|
-
const result = await listCodemods(registry)();
|
|
23
|
-
expect(result.isOk()).toBe(true);
|
|
24
|
-
expect(registry.getAll).toHaveBeenCalledTimes(1);
|
|
25
|
-
});
|
|
26
|
-
it("propagates registry errors", async () => {
|
|
27
|
-
const error = new Error("boom");
|
|
28
|
-
const registry = {
|
|
29
|
-
getAll: vi.fn().mockReturnValue(errAsync(error)),
|
|
30
|
-
getById: vi.fn(),
|
|
31
|
-
};
|
|
32
|
-
const result = await listCodemods(registry)();
|
|
33
|
-
expect(result.isErr()).toBe(true);
|
|
34
|
-
const value = result.isErr() ? result.error : null;
|
|
35
|
-
expect(value).toBe(error);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the requestAuthorization use case.
|
|
3
|
-
*/
|
|
4
|
-
import { errAsync, okAsync } from "neverthrow";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { mock } from "vitest-mock-extended";
|
|
7
|
-
import { AuthorizationError, AuthorizationResult, requestAuthorizationInputSchema, } from "../../domain/authorization.js";
|
|
8
|
-
import { requestAuthorization } from "../request-authorization.js";
|
|
9
|
-
const makeSampleInput = () => requestAuthorizationInputSchema.parse({
|
|
10
|
-
bootstrapIdentityId: "test-bootstrap-identity-id",
|
|
11
|
-
envShort: "d",
|
|
12
|
-
prefix: "test",
|
|
13
|
-
repoName: "test-repo",
|
|
14
|
-
subscriptionName: "test-subscription",
|
|
15
|
-
});
|
|
16
|
-
describe("requestAuthorization", () => {
|
|
17
|
-
it("should return the authorization result on success", async () => {
|
|
18
|
-
const authorizationService = mock();
|
|
19
|
-
const input = makeSampleInput();
|
|
20
|
-
const expectedResult = new AuthorizationResult("https://github.com/pagopa/eng-azure-authorization/pull/42");
|
|
21
|
-
authorizationService.requestAuthorization.mockReturnValue(okAsync(expectedResult));
|
|
22
|
-
const result = await requestAuthorization(authorizationService)(input);
|
|
23
|
-
expect(result.isOk()).toBe(true);
|
|
24
|
-
expect(result._unsafeUnwrap().url).toBe("https://github.com/pagopa/eng-azure-authorization/pull/42");
|
|
25
|
-
expect(authorizationService.requestAuthorization).toHaveBeenCalledWith(input);
|
|
26
|
-
});
|
|
27
|
-
it("should propagate errors from the authorization service", async () => {
|
|
28
|
-
const authorizationService = mock();
|
|
29
|
-
const input = makeSampleInput();
|
|
30
|
-
authorizationService.requestAuthorization.mockReturnValue(errAsync(new AuthorizationError("Unable to update file")));
|
|
31
|
-
const result = await requestAuthorization(authorizationService)(input);
|
|
32
|
-
expect(result.isErr()).toBe(true);
|
|
33
|
-
expect(result._unsafeUnwrapErr()).toBeInstanceOf(AuthorizationError);
|
|
34
|
-
});
|
|
35
|
-
it("should propagate generic authorization errors", async () => {
|
|
36
|
-
const authorizationService = mock();
|
|
37
|
-
const input = makeSampleInput();
|
|
38
|
-
authorizationService.requestAuthorization.mockReturnValue(errAsync(new AuthorizationError("Something went wrong")));
|
|
39
|
-
const result = await requestAuthorization(authorizationService)(input);
|
|
40
|
-
expect(result.isErr()).toBe(true);
|
|
41
|
-
expect(result._unsafeUnwrapErr()).toBeInstanceOf(AuthorizationError);
|
|
42
|
-
});
|
|
43
|
-
});
|