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

Commit

Permalink
chore(comments): allow/create
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuoushub committed Apr 2, 2022
1 parent e66e912 commit 461392c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
4 changes: 4 additions & 0 deletions api/src/graphql/comments.sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export const schema = gql`
body: String
postId: Int
}
type Mutation {
createComment(input: CreateCommentInput!): Comment! @skipAuth
deleteComment(id: Int!): Comment! @requireAuth
}
`
12 changes: 12 additions & 0 deletions api/src/services/comments/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ export const Comment = {
post: (_obj, { root }) =>
db.comment.findUnique({ where: { id: root.id } }).post(),
}

export const createComment = ({ input }) => {
return db.comment.create({
data: input,
})
}

export const deleteComment = ({ id }) => {
return db.comment.delete({
where: { id },
})
}
36 changes: 28 additions & 8 deletions api/src/services/comments/comments.scenarios.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
export const standard = defineScenario({
comment: {
one: {
jane: {
data: {
name: 'String',
body: 'String',
post: { create: { title: 'String', body: 'String' } },
name: 'Jane Doe',
body: 'I like trees',
post: {
create: {
title: 'Redwood Leaves',
body: 'The quick brown fox jumped over the lazy dog.',
},
},
},
},
john: {
data: {
name: 'John Doe',
body: 'Hug a tree today',
post: {
create: {
title: 'Root Systems',
body: 'The five boxing wizards jump quickly.',
},
},
},
},
},
})

two: {
export const postOnly = defineScenario({
post: {
bark: {
data: {
name: 'String',
body: 'String',
post: { create: { title: 'String', body: 'String' } },
title: 'Bark',
body: "A tree's bark is worse than its bite",
},
},
},
Expand Down
17 changes: 16 additions & 1 deletion api/src/services/comments/comments.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { comments } from './comments'
import { comments, createComment } from './comments'

// Generated boilerplate tests do not account for all circumstances
// and can fail without adjustments, e.g. Float and DateTime types.
Expand All @@ -12,4 +12,19 @@ describe('comments', () => {

expect(result.length).toEqual(Object.keys(scenario.comment).length)
})

scenario('postOnly', 'creates a new comment', async (scenario) => {
const comment = await createComment({
input: {
name: 'Billy Bob',
body: 'What is your favorite tree bark?',
postId: scenario.post.bark.id,
},
})

expect(comment.name).toEqual('Billy Bob')
expect(comment.body).toEqual('What is your favorite tree bark?')
expect(comment.postId).toEqual(scenario.post.bark.id)
expect(comment.createdAt).not.toEqual(null)
})
})

0 comments on commit 461392c

Please sign in to comment.