Skip to content

Commit dec123e

Browse files
committed
test: rename Tag entity to Comment
1 parent 296d609 commit dec123e

5 files changed

Lines changed: 36 additions & 36 deletions

File tree

prisma/schema.prisma

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ enum Gender {
5151
}
5252

5353
model Post {
54-
id Int @id @default(autoincrement())
55-
title String @unique @db.VarChar(255)
56-
createdAt DateTime @default(now())
57-
imprint String @default(uuid())
58-
author User @relation(fields: [authorId], references: [id])
54+
id Int @id @default(autoincrement())
55+
title String @unique @db.VarChar(255)
56+
createdAt DateTime @default(now())
57+
imprint String @default(uuid())
58+
author User @relation(fields: [authorId], references: [id])
5959
authorId Int
60-
blog Blog @relation(fields: [blogId], references: [id], onDelete: Cascade)
60+
blog Blog @relation(fields: [blogId], references: [id], onDelete: Cascade)
6161
blogId Int
62-
tags Tag[]
62+
comments Comment[]
6363
}
6464

65-
model Tag {
65+
model Comment {
6666
id Int @id @default(autoincrement())
67-
title String @unique @db.VarChar(255)
67+
body String @db.VarChar(255)
6868
posts Post[]
6969
}
7070

src/__tests__/client/client-custom.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('client (custom)', () => {
2727
profile: [],
2828
service: [],
2929
subscription: [],
30-
tag: [],
30+
comment: [],
3131
};
3232

3333
if (provider !== 'mongodb') {
@@ -64,7 +64,7 @@ describe('client (custom)', () => {
6464
profile: [],
6565
service: [],
6666
subscription: [],
67-
tag: [],
67+
comment: [],
6868
};
6969

7070
if (provider !== 'mongodb') {

src/__tests__/create/create-connect.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { PrismaClient, type Post, Tag } from '@prisma/client';
1+
import { PrismaClient, type Post, Comment } from '@prisma/client';
22

33
import { resetDb, seededPosts, simulateSeed } from '../../../testing';
44
import { PrismockClient, PrismockClientType, relationshipStore } from '../../lib/client';
55

66
jest.setTimeout(40000);
77

8-
type PostWithTags = Post & { tags: Tag[] };
8+
type PostWithComments = Post & { comments: Comment[] };
99

1010
describe('create (connect)', () => {
1111
let prismock: PrismockClientType;
@@ -104,17 +104,17 @@ describe('create (connect)', () => {
104104
title: 'Title',
105105
authorId: 1,
106106
blogId: 1,
107-
tags: {
107+
comments: {
108108
connect: [{ id: 1 }, { id: 2 }],
109109
},
110110
},
111111
};
112112
await prisma.post.create(payload);
113113
await prismock.post.create(payload);
114114

115-
const realPost = await prisma.post.findFirst({ where: { id: 99 }, include: { tags: true } });
116-
const mockPost = await prismock.post.findFirst({ where: { id: 99 }, include: { tags: true } });
115+
const realPost = await prisma.post.findFirst({ where: { id: 99 }, include: { comments: true } });
116+
const mockPost = await prismock.post.findFirst({ where: { id: 99 }, include: { comments: true } });
117117

118-
expect((mockPost as PostWithTags).tags).toMatchObject((realPost as PostWithTags).tags);
118+
expect((mockPost as PostWithComments).comments).toMatchObject((realPost as PostWithComments).comments);
119119
});
120120
});

src/__tests__/update/update-connect.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ describe('update (connect)', () => {
6262
const updatePayload = {
6363
where: { id: 1 },
6464
data: {
65-
tags: {
65+
comments: {
6666
connect: [{ id: 1 }, { id: 2 }],
6767
},
6868
},
6969
};
7070

71-
const findTagsPayload = {
71+
const findCommentsPayload = {
7272
where: {
7373
posts: {
7474
some: {
@@ -81,37 +81,37 @@ describe('update (connect)', () => {
8181
await prisma.post.update(updatePayload);
8282
await prismock.post.update(updatePayload);
8383

84-
const findPostPayload = { where: { id: 1 }, include: { tags: true } };
84+
const findPostPayload = { where: { id: 1 }, include: { comments: true } };
8585

8686
const updatedPost = await prisma.post.findFirst(findPostPayload);
8787
const updatedMockedPost = await prismock.post.findFirst(findPostPayload);
8888

89-
const updatedTags = await prisma.tag.findMany(findTagsPayload);
90-
const updatedMockedTags = await prismock.tag.findMany(findTagsPayload);
89+
const updatedComments = await prisma.comment.findMany(findCommentsPayload);
90+
const updatedMockedComments = await prismock.comment.findMany(findCommentsPayload);
9191

9292
expect(updatedPost).toMatchObject(updatedMockedPost);
93-
expect(updatedTags).toMatchObject(updatedMockedTags);
93+
expect(updatedComments).toMatchObject(updatedMockedComments);
9494
});
9595

9696
it('Should disconnect many to many relationships', async () => {
9797
const connectPayload = {
9898
where: { id: 1 },
9999
data: {
100-
tags: {
100+
comments: {
101101
connect: [{ id: 1 }, { id: 2 }],
102102
},
103103
},
104104
};
105105
const disconnectPayload = {
106106
where: { id: 1 },
107107
data: {
108-
tags: {
108+
comments: {
109109
disconnect: [{ id: 2 }],
110110
},
111111
},
112112
};
113-
const findPostPayload = { where: { id: 1 }, include: { tags: true } };
114-
const findTagsPayload = {
113+
const findPostPayload = { where: { id: 1 }, include: { comments: true } };
114+
const findCommentsPayload = {
115115
where: {
116116
posts: {
117117
some: {
@@ -131,10 +131,10 @@ describe('update (connect)', () => {
131131
const updatedPost = await prisma.post.findFirst(findPostPayload);
132132
const updatedMockedPost = await prismock.post.findFirst(findPostPayload);
133133

134-
const updatedTags = await prisma.tag.findMany(findTagsPayload);
135-
const updatedMockedTags = await prismock.tag.findMany(findTagsPayload);
134+
const updatedComments = await prisma.comment.findMany(findCommentsPayload);
135+
const updatedMockedComments = await prismock.comment.findMany(findCommentsPayload);
136136

137137
expect(updatedPost).toMatchObject(updatedMockedPost);
138-
expect(updatedTags).toMatchObject(updatedMockedTags);
138+
expect(updatedComments).toMatchObject(updatedMockedComments);
139139
});
140140
});

testing/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { exec } from 'child_process';
22

3-
import { Blog, Tag, Post, PrismaClient, Reaction, Role, Service, Subscription, User } from '@prisma/client';
3+
import { Blog, Comment, Post, PrismaClient, Reaction, Role, Service, Subscription, User } from '@prisma/client';
44
import dotenv from 'dotenv';
55
import { createId } from '@paralleldrive/cuid2';
66

@@ -15,7 +15,7 @@ export const seededReactions = [
1515
buildReaction({ userId: 1, emoji: 'rocket' }),
1616
];
1717

18-
export const seededTags = [buildTag(1), buildTag(2), buildTag(3)];
18+
export const seededComments = [buildComment(1), buildComment(2), buildComment(3)];
1919

2020
export async function simulateSeed(prisma: PrismaClient) {
2121
await prisma.user.createMany({ data: seededUsers.map(({ id, ...user }) => user) });
@@ -25,7 +25,7 @@ export async function simulateSeed(prisma: PrismaClient) {
2525
// @ts-ignore MySQL / Tags
2626
await prisma.service.createMany({ data: seededServices });
2727
await prisma.reaction.createMany({ data: seededReactions });
28-
await prisma.tag.createMany({ data: seededTags });
28+
await prisma.comment.createMany({ data: seededComments });
2929
}
3030

3131
export async function resetDb() {
@@ -64,11 +64,11 @@ export function buildPost(id: number, post: Partial<Post> & { authorId: number;
6464
};
6565
}
6666

67-
export function buildTag(id: number, tag: Partial<Tag> = {}) {
67+
export function buildComment(id: number, comment: Partial<Comment> = {}) {
6868
return {
6969
id,
70-
title: `tag${id}`,
71-
...tag,
70+
body: `comment${id}`,
71+
...comment,
7272
};
7373
}
7474

0 commit comments

Comments
 (0)