-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consistency between deployment begin and end projects
- Loading branch information
1 parent
616b6ac
commit 52f0952
Showing
20 changed files
with
552 additions
and
422 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
...actice_first/deployment/assignment/begin/packages/backend/src/shared/database/database.ts
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
55 changes: 55 additions & 0 deletions
55
...eployment/assignment/end/packages/backend/src/modules/users/ports/userRepository.infra.ts
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,55 @@ | ||
|
||
import { PrismaClient } from "@prisma/client"; | ||
import { ProductionUserRepository } from "../adapters/productionUserRepository"; | ||
import { UserBuilder } from '@dddforum/shared/tests/support/builders/users' | ||
import { UsersRepository } from "./usersRepository"; | ||
import { InMemoryUserRepositorySpy } from "../adapters/inMemoryUserRepositorySpy"; | ||
|
||
describe("userRepo", () => { | ||
let userRepos: UsersRepository[] = [ | ||
new ProductionUserRepository(new PrismaClient()), | ||
new InMemoryUserRepositorySpy() | ||
]; | ||
|
||
it("can save and retrieve users by email", () => { | ||
let createUserInput = new UserBuilder() | ||
.makeValidatedUserBuilder() | ||
.withAllRandomDetails() | ||
.build() | ||
|
||
userRepos.forEach(async (userRepo) => { | ||
let savedUserResult = await userRepo.save({ | ||
...createUserInput, | ||
password: '', | ||
}); | ||
let fetchedUserResult = await userRepo.findUserByEmail( | ||
createUserInput.email, | ||
); | ||
|
||
expect(savedUserResult).toBeDefined(); | ||
expect(fetchedUserResult).toBeDefined(); | ||
expect(savedUserResult.email).toEqual(fetchedUserResult?.email); | ||
}); | ||
}); | ||
|
||
it("can find a user by username", () => { | ||
let createUserInput = new UserBuilder() | ||
.makeValidatedUserBuilder() | ||
.withAllRandomDetails() | ||
.build(); | ||
|
||
userRepos.forEach(async (userRepo) => { | ||
let savedUserResult = await userRepo.save({ | ||
...createUserInput, | ||
password: "", | ||
}); | ||
let fetchedUserResult = await userRepo.findUserByUsername( | ||
createUserInput.username, | ||
); | ||
|
||
expect(savedUserResult).toBeDefined(); | ||
expect(fetchedUserResult).toBeDefined(); | ||
expect(savedUserResult.username).toEqual(fetchedUserResult?.username); | ||
}); | ||
}); | ||
}); |
12 changes: 5 additions & 7 deletions
12
...rst/deployment/assignment/end/packages/backend/src/modules/users/ports/usersRepository.ts
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import { User } from "@dddforum/shared/src/api/users"; | ||
import { CreateUserCommand } from "../usersCommand"; | ||
|
||
import { ValidatedUser } from "@dddforum/shared/src/api/users"; | ||
import { User } from "@prisma/client"; | ||
|
||
export interface UsersRepository { | ||
findUserByEmail(email: string): Promise<User | null>; | ||
// @note The ideal return type here is a domain object, not a DTO. For | ||
// demonstration purposes, we've kept it intentionally simple to focus on testing. | ||
// @see Pattern-First for domain objects | ||
save(user: CreateUserCommand): Promise<User & { password: string }>; | ||
save(user: ValidatedUser): Promise<User>; | ||
findById(id: number): Promise<User | null>; | ||
delete(email: string): Promise<void>; | ||
findUserByUsername(username: string): Promise<User | null>; | ||
update(id: number, props: Partial<CreateUserCommand>): Promise<User | null>; | ||
update(id: number, props: Partial<ValidatedUser>): Promise<User | null>; | ||
} |
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
1 change: 0 additions & 1 deletion
1
...practice_first/deployment/assignment/end/packages/backend/src/shared/database/database.ts
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
55 changes: 55 additions & 0 deletions
55
...ckages/backend/src/shared/database/prisma/migrations/20231125035334_initial/migration.sql
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,55 @@ | ||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"email" TEXT NOT NULL, | ||
"firstName" TEXT NOT NULL, | ||
"lastName" TEXT NOT NULL, | ||
"username" TEXT NOT NULL, | ||
"password" TEXT NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Member" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"userId" INTEGER NOT NULL, | ||
CONSTRAINT "Member_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Post" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"memberId" INTEGER NOT NULL, | ||
"postType" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"dateCreated" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT "Post_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Comment" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"postId" INTEGER NOT NULL, | ||
"text" TEXT NOT NULL, | ||
"memberId" INTEGER NOT NULL, | ||
"parentCommentId" INTEGER, | ||
CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Comment_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Comment_parentCommentId_fkey" FOREIGN KEY ("parentCommentId") REFERENCES "Comment" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Vote" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"postId" INTEGER NOT NULL, | ||
"memberId" INTEGER NOT NULL, | ||
"voteType" TEXT NOT NULL, | ||
CONSTRAINT "Vote_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Vote_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Member_userId_key" ON "Member"("userId"); |
2 changes: 1 addition & 1 deletion
2
...assignment/end/packages/backend/src/shared/database/prisma/migrations/migration_lock.toml
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" | ||
provider = "sqlite" |
Oops, something went wrong.