Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tktcorporation committed Oct 10, 2022
1 parent f06c364 commit 90c08fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 13 additions & 4 deletions api/src/services/comments/comments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { db } from 'src/lib/db'

import { comments, createComment } from './comments'
import type { StandardScenario, PostOnlyScenario } from './comments.scenarios'

Expand All @@ -8,11 +10,18 @@ import type { StandardScenario, PostOnlyScenario } from './comments.scenarios'
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations

describe('comments', () => {
scenario('returns all comments', async (scenario: StandardScenario) => {
const result = await comments()
scenario(
'returns all comments for a single post from the database',
async (scenario: StandardScenario) => {
const result = await comments({ postId: scenario.comment.jane.postId })

expect(result.length).toEqual(Object.keys(scenario.comment).length)
})
const post = await db.post.findUnique({
where: { id: scenario.comment.jane.postId },
include: { comments: true },
})
expect(result.length).toEqual(post.comments.length)
}
)

scenario(
'postOnly',
Expand Down
8 changes: 6 additions & 2 deletions api/src/services/comments/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import type { QueryResolvers, CommentRelationResolvers } from 'types/graphql'

import { db } from 'src/lib/db'

export const comments: QueryResolvers['comments'] = () => {
return db.comment.findMany()
export const comments: QueryResolvers['comments'] = ({
postId,
}: Required<Pick<Prisma.CommentWhereInput, 'postId'>>) => {
return db.comment.findMany({
where: { postId },
})
}

export const comment: QueryResolvers['comment'] = ({ id }) => {
Expand Down

0 comments on commit 90c08fb

Please sign in to comment.