Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
chore: get comment by post
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuoushub committed Apr 2, 2022
1 parent 3d7bc13 commit bb41f32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/src/services/comments/comments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from 'src/lib/db'

export const comments = () => {
return db.comment.findMany()
export const comments = ({ postId }) => {
return db.comment.findMany({ where: { postId } })
}

export const comment = ({ id }) => {
Expand Down
17 changes: 12 additions & 5 deletions api/src/services/comments/comments.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { comments, createComment } from './comments'
import { db } from 'src/lib/db'

// Generated boilerplate tests do not account for all circumstances
// and can fail without adjustments, e.g. Float and DateTime types.
Expand All @@ -7,11 +8,17 @@ import { comments, createComment } from './comments'
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations

describe('comments', () => {
scenario('returns all comments', async (scenario) => {
const result = await comments()

expect(result.length).toEqual(Object.keys(scenario.comment).length)
})
scenario(
'returns all comments for a single post from the database',
async (scenario) => {
const result = await comments({ postId: scenario.comment.jane.postId })
const post = await db.post.findUnique({
where: { id: scenario.comment.jane.postId },
include: { comments: true },
})
expect(result.length).toEqual(post.comments.length)
}
)

scenario('postOnly', 'creates a new comment', async (scenario) => {
const comment = await createComment({
Expand Down

0 comments on commit bb41f32

Please sign in to comment.