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 13, 2024
1 parent ec206ac commit 3794fef
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 11 deletions.
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
}
5 changes: 2 additions & 3 deletions 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 Down Expand Up @@ -98,8 +99,6 @@
},
"modulePathIgnorePatterns": [
"<rootDir>/packages"
],
"globalSetup": "./test/initMongoContainer.ts",
"globalTeardown": "./test/stopMongoContainer.ts"
]
}
}
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
25 changes: 19 additions & 6 deletions apiv2/test/architecture/arch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import "tsarch/dist/jest";

// imports the files entrypoint
import { FileConditionBuilder, filesOfProject } from "tsarch";
import { FileConditionBuilder, filesOfProject, slicesOfProject } from "tsarch";
import { Folders } from "./folder";

describe("architecture", () => {
Expand All @@ -21,14 +21,27 @@ describe("architecture", () => {
});

it.skip("business logic should exclusively depend on @notification, @shared, snu-lib, @nestjs/common", async () => {
const rule = files
.inFolder(Folders.SRC_CORE)
// const rule = await files
// .matchingPattern(Folders.SRC_ADMIN_CORE)
// .should()
// .dependOnFiles()
// .matchingPattern(`^(snu-lib|common|core)$`);

const rule = await files
.matchingPattern(Folders.SRC_ADMIN_CORE)
.should()
.dependOnFiles()
.matchingPattern(`^(snu-lib|common|core)$`);
// .matchingPattern("^(@notification|@shared|snu-lib|@nestjs/common|core)$");
.matchingPattern(`^(snu-lib|common|core)$`)
.check();

// console.log(files.matchingPattern(Folders.SRC_CORE_PATTERN));
console.log(rule);
// // .matchingPattern(`^(snu-lib|common|core)$`);
// // .matchingPattern("^(@notification|@shared|snu-lib|@nestjs/common|core)$");
// await expect(rule).toPassAsync();
//
//
//
// const rule = files.matchingPattern(Folders.CORE).shouldNot().dependOnFiles().matchingPattern();
await expect(rule).toPassAsync();
});

Expand Down
80 changes: 80 additions & 0 deletions apiv2/test/architecture/arch2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 { classes, noClasses } from "arch-unit-ts/dist/main";
import { Architectures } from "arch-unit-ts/dist/arch-unit/library/Architectures";
import { AdminModule } from "src/admin/Admin.module";
describe("Architecture test", () => {
const srcProject = new TypeScriptProject(RelativePath.of("src"));

describe("Application", () => {
it("Should not depend on infrastructure", () => {
noClasses()
.that()
.resideInAPackage("..core..")
.should()
.dependOnClassesThat()
.resideInAnyPackage("..infra..")
.because("core should not depend on infrastructure")
.check(srcProject.allClasses());
});
it("Should only have few dependencies", () => {
classes()
.that()
.resideInAPackage("..core..")
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage("packages", "core", "@nestjs.common", "@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("src.admin.core..", "src.admin.infra..")
.layer("useCase", "src.admin..core..useCase..")
.layer("repository", "src.admin..infra..repository..")
.layer("infra", "src.admin..infra..")
.layer("core", "src.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("..admin.core..")
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage(
"packages",
"notification..core",
"shared..core",
"admin..core",
"@nestjs.common",
"@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("..shared.core..")
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage("shared..core", "@nestjs.common")
.because("Core should not depend on any other dependencies")
.check(srcProject.allClasses());
});
});
});
2 changes: 1 addition & 1 deletion apiv2/test/architecture/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export enum Folders {
CORE = "core",
INFRA = "infra",
SRC_CORE_PATTERN = "^(?=.*\bsrc\b)(?=.*\bcore\b)(?!.*.spec.ts$).*",
SRC_CORE = "src/admin/core",
SRC_ADMIN_CORE = "./src/admin/core",
}
141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3794fef

Please sign in to comment.