Skip to content

Commit

Permalink
add arch-unit-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannbr committed Nov 14, 2024
1 parent ec206ac commit 21ae8f5
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 534 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
"jestCommandLine": "source ~/.zshrc && nvm use && npm run test --",
"runMode": "watch"
}
],
"typescript.tsdk": "node_modules/typescript/lib"
]
}
4 changes: 4 additions & 0 deletions apiv2/arch-unit-ts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"showImportsWarning": false,
"failOnEmptyShould": false
}
2 changes: 1 addition & 1 deletion apiv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"arch-unit-ts": "^1.0.8",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
Expand All @@ -69,7 +70,6 @@
"ts-jest": "^29.2.5",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsarch": "^5.4.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3"
},
Expand Down
1 change: 0 additions & 1 deletion apiv2/src/admin/infra/iam/auth/ReferentAuth.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AuthProvider } from "./Auth.provider";
import * as bcrypt from "bcrypt";
import { ReferentMapper } from "../repository/mongo/Referent.mapper";
import { TechnicalException, TechnicalExceptionType } from "@shared/infra/TechnicalException";
import { error } from "console";

@Injectable()
export class ReferentAuthFacade implements ReferentAuthGateway {
Expand Down
40 changes: 0 additions & 40 deletions apiv2/test/architecture/arch.spec.ts

This file was deleted.

85 changes: 85 additions & 0 deletions apiv2/test/architecture/architecture.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { RelativePath } from "arch-unit-ts/dist/arch-unit/core/domain/RelativePath";
import { TypeScriptProject } from "arch-unit-ts/dist/arch-unit/core/domain/TypeScriptProject";
import { Architectures } from "arch-unit-ts/dist/arch-unit/library/Architectures";
import { classes, noClasses } from "arch-unit-ts/dist/main";
import { MatchingPattern } from "./folderPattern";
describe("Architecture test", () => {
const srcProject = new TypeScriptProject(RelativePath.of("src"));

describe("Application", () => {
it("Should not depend on infrastructure", () => {
noClasses()
.that()
.resideInAPackage(MatchingPattern.CORE)
.should()
.dependOnClassesThat()
.resideInAnyPackage(MatchingPattern.INFRA)
.because("core should not depend on infrastructure")
.check(srcProject.allClasses());
});
it("Should only have few dependencies", () => {
classes()
.that()
.resideInAPackage(MatchingPattern.CORE)
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage(
MatchingPattern.SNU_LIB,
MatchingPattern.CORE,
MatchingPattern.NESTJS_COMMON,
MatchingPattern.NESTJS_TESTING,
)
.because("Core should not depend on any other dependencies")
.check(srcProject.allClasses());
});
});

describe("Admin", () => {
it("Should implement an hexagonal architecture", async () => {
Architectures.layeredArchitecture()
.consideringOnlyDependenciesInAnyPackage(MatchingPattern.ADMIN_CORE, MatchingPattern.ADMIN_INFRA)
.layer("useCase", MatchingPattern.ADMIN_USECASE)
.layer("repository", MatchingPattern.ADMIN_REPOSITORY)
.layer("infra", MatchingPattern.ADMIN_INFRA)
.layer("core", MatchingPattern.ADMIN_CORE)
.whereLayer("useCase")
.mayOnlyBeAccessedByLayers("infra", "useCase")
.whereLayer("repository")
.mayOnlyBeAccessedByLayers("infra")
.whereLayer("infra")
.mayNotBeAccessedByAnyLayer()
.because("Each bounded context should implement an hexagonal architecture")
.check(srcProject.allClasses());
});
it("Should depend on specific dependencies", async () => {
classes()
.that()
.resideInAPackage(MatchingPattern.ADMIN_CORE)
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage(
MatchingPattern.SNU_LIB,
MatchingPattern.NOTIFICATION_CORE,
MatchingPattern.SHARED_CORE,
MatchingPattern.ADMIN_CORE,
MatchingPattern.NESTJS_COMMON,
MatchingPattern.NESTJS_TESTING,
)
.because("Core should not depend on any other dependencies")
.check(srcProject.allClasses());
});
});

describe("Shared", () => {
it("Should depend on specific dependencies", async () => {
classes()
.that()
.resideInAPackage(MatchingPattern.SHARED_CORE)
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage(MatchingPattern.SHARED_CORE, MatchingPattern.NESTJS_COMMON)
.because("Core should not depend on any other dependencies")
.check(srcProject.allClasses());
});
});
});
7 changes: 0 additions & 7 deletions apiv2/test/architecture/folder.ts

This file was deleted.

18 changes: 18 additions & 0 deletions apiv2/test/architecture/folderPattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum MatchingPattern {
CORE = "..core..",
INFRA = "..infra..",

ADMIN_CORE = "src.admin.core..",
ADMIN_USECASE = "src.admin..core..useCase..",
ADMIN_INFRA = "src.admin..infra..",
ADMIN_REPOSITORY = "src.admin..infra..repository..",

NOTIFICATION_CORE = "src.notification.core..",

SHARED_CORE = "..shared.core..",

NESTJS_COMMON = "@nestjs.common",
NESTJS_TESTING = "@nestjs.testing",

SNU_LIB = "packages",
}
Loading

0 comments on commit 21ae8f5

Please sign in to comment.