-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] feat: User unit tests (#33)
- Loading branch information
1 parent
0cf7348
commit 0b2ec7c
Showing
10 changed files
with
323 additions
and
76 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
backend/prisma/migrations/20240316221424_user_model/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,23 @@ | ||
-- AlterTable | ||
ALTER TABLE "Note" ADD COLUMN "user_id" INTEGER; | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" SERIAL NOT NULL, | ||
"username" TEXT NOT NULL, | ||
"password" TEXT NOT NULL, | ||
"email" TEXT, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Note" ADD CONSTRAINT "Note_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
21 changes: 21 additions & 0 deletions
21
backend/prisma/migrations/20240316224317_init/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,21 @@ | ||
/* | ||
Warnings: | ||
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "Note" DROP CONSTRAINT "Note_user_id_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Note" ALTER COLUMN "user_id" SET DATA TYPE TEXT; | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" DROP CONSTRAINT "User_pkey", | ||
ALTER COLUMN "id" DROP DEFAULT, | ||
ALTER COLUMN "id" SET DATA TYPE TEXT, | ||
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id"); | ||
DROP SEQUENCE "User_id_seq"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Note" ADD CONSTRAINT "Note_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
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 |
---|---|---|
|
@@ -8,59 +8,80 @@ export const seed = [ | |
"content": "Discussed project timelines and goals.", | ||
"createdAt": "2024-02-05T23:33:42.252Z", | ||
"updatedAt": "2024-02-05T23:33:42.252Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Shopping List", | ||
"content": "Milk, eggs, bread, and fruits.", | ||
"createdAt": "2024-02-05T23:33:42.253Z", | ||
"updatedAt": "2024-02-05T23:33:42.253Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Recipe", | ||
"content": "Ingredients: Chicken, tomatoes, onions, garlic.", | ||
"createdAt": "2024-02-05T23:33:42.254Z", | ||
"updatedAt": "2024-02-05T23:33:42.254Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Ideas", | ||
"content": "Brainstorming ideas for the next feature release. 🚀", | ||
"createdAt": "2024-02-05T23:33:42.255Z", | ||
"updatedAt": "2024-02-05T23:33:42.255Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Personal Goals", | ||
"content": "Exercise for 30 minutes daily. Read a book every week.", | ||
"createdAt": "2024-02-05T23:33:42.256Z", | ||
"updatedAt": "2024-02-05T23:33:42.256Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Fête d'anniversaire", | ||
"content": "Préparer une surprise pour la fête d'anniversaire.", | ||
"createdAt": "2024-02-05T23:33:42.257Z", | ||
"updatedAt": "2024-02-05T23:33:42.257Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "日本旅行", | ||
"content": "計画: 東京、京都、大阪を訪れる。", | ||
"createdAt": "2024-02-05T23:33:42.258Z", | ||
"updatedAt": "2024-02-05T23:33:42.258Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Семейный ужин", | ||
"content": "Приготовить вкусный ужин для всей семьи.", | ||
"createdAt": "2024-02-05T23:33:42.259Z", | ||
"updatedAt": "2024-02-05T23:33:42.259Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
}, | ||
{ | ||
"title": "Coding Project", | ||
"content": "Implement new features using React and Express.", | ||
"createdAt": "2024-02-05T23:33:42.260Z", | ||
"updatedAt": "2024-02-05T23:33:42.260Z", | ||
"userID": "ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272" | ||
} | ||
]; | ||
|
||
async function main() { | ||
// Seed data here | ||
// Seed user data | ||
await prisma.user.create({ | ||
data: { | ||
id : 'ccf89a7e-b941-4f17-bbe0-4e0c8b2cd272', | ||
email: '[email protected]', | ||
password: 'n0te$App!23', | ||
username: 'Test User', | ||
createdAt: "2024-02-05T23:33:42.260Z", | ||
updatedAt: "2024-02-05T23:33:42.260Z", | ||
} | ||
}); | ||
|
||
// Seed note data | ||
await prisma.note.createMany({ | ||
data: seed, | ||
}); | ||
|
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
Oops, something went wrong.
0b2ec7c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report