-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
323 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"showImportsWarning": false, | ||
"failOnEmptyShould": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
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 "./MatchingPattern"; | ||
describe("Architecture test", () => { | ||
const srcProject = new TypeScriptProject(RelativePath.of("src")); | ||
console.log( | ||
srcProject | ||
.allClasses() | ||
.get() | ||
.map((c) => c.name), | ||
); | ||
|
||
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()); | ||
}); | ||
|
||
it("Repository should depend on gateway", async () => { | ||
classes() | ||
.that() | ||
.resideInAPackage(MatchingPattern.INFRA) | ||
.and() | ||
.haveSimpleNameEndingWith(MatchingPattern.REPOSITORY_SUFFIX) | ||
.should() | ||
.dependOnClassesThat() | ||
.haveSimpleNameEndingWith(MatchingPattern.GATEWAY_SUFFIX) | ||
.allowEmptyShould(false) | ||
.because("Repository should implement gateway") | ||
.check(srcProject.allClasses()); | ||
}); | ||
|
||
it("Core should not have some classes named", async () => { | ||
noClasses() | ||
.that() | ||
.resideInAPackage(MatchingPattern.CORE) | ||
.should() | ||
.haveSimpleNameEndingWith(MatchingPattern.REPOSITORY_SUFFIX) | ||
.orShould() | ||
.haveSimpleNameEndingWith(MatchingPattern.CONTROLLER_SUFFIX) | ||
.orShould() | ||
.haveSimpleNameEndingWith(MatchingPattern.CONSUMER_SUFFIX) | ||
.orShould() | ||
.haveSimpleNameEndingWith(MatchingPattern.PROVIDER_SUFFIX) | ||
.orShould() | ||
.haveSimpleNameEndingWith(MatchingPattern.FACTORY_SUFFIX) | ||
.orShould() | ||
.haveSimpleNameEndingWith(MatchingPattern.PRODUCER_SUFFIX) | ||
.because("Core should not implement repo, ...") | ||
.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()); | ||
}); | ||
}); | ||
|
||
describe("BullMQ", () => { | ||
it("Consumer should be in jobModule", async () => { | ||
classes() | ||
.that() | ||
.haveSimpleNameEndingWith(MatchingPattern.CONSUMER_SUFFIX) | ||
.should() | ||
.onlyHaveDependentClassesThat() | ||
.haveSimpleNameEndingWith(MatchingPattern.JOB_MODULE_SUFFIX) | ||
.andShould() | ||
.dependOnClassesThat() | ||
.resideInAPackage(MatchingPattern.NESTJS_BULLMQ) | ||
.allowEmptyShould(false) | ||
.because("Consumer should be in jobModule") | ||
.check(srcProject.allClasses()); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export enum MatchingPattern { | ||
CORE = "..core..", | ||
INFRA = "..infra..", | ||
GATEWAY_SUFFIX = ".gateway.ts", | ||
REPOSITORY_SUFFIX = ".repository.ts", | ||
CONTROLLER_SUFFIX = ".controller.ts", | ||
CONSUMER_SUFFIX = ".consumer.ts", | ||
PROVIDER_SUFFIX = ".provider.ts", | ||
FACTORY_SUFFIX = ".factory.ts", | ||
PRODUCER_SUFFIX = ".producer.ts", | ||
JOB_MODULE_SUFFIX = "Job.module.ts", | ||
|
||
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", | ||
NESTJS_BULLMQ = "@nestjs.bullmq", | ||
|
||
SNU_LIB = "packages", | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.