<commit_before>{-# LANGUAGE OverloadedStrings #-}
module CreateCommentTest
    ( createCommentSpecs
    ) where

import TestImport

createCommentSpecs :: Spec
createCommentSpecs =
    ydescribe "POST /api/v1/comments" $ do
        yit "responds with 201 created" $ do
            postBody CommentsR $ commentJSON "" ""

            statusIs 201

        yit "creates a comment in the database" $ do
            clearComments
            let (thread, body) = ("A thread", "A body")

            postBody CommentsR $ commentJSON thread body

            ((Entity _ c):_) <- runDB $ selectList [] []
            assertEqual' (commentThread c) thread
            assertEqual' (commentBody c) body

commentJSON :: Text -> Text -> ByteString
commentJSON thread body = encode $ object ["thread" .= thread, "body" .= body]<commit_msg>Add spec for error handling<commit_after>{-# LANGUAGE OverloadedStrings #-}
module CreateCommentTest
    ( createCommentSpecs
    ) where

import TestImport

createCommentSpecs :: Spec
createCommentSpecs =
    ydescribe "POST /api/v1/comments" $ do
        yit "responds with 201 created" $ do
            postBody CommentsR $ commentJSON "" ""

            statusIs 201

        yit "creates a comment in the database" $ do
            clearComments
            let (thread, body) = ("A thread", "A body")

            postBody CommentsR $ commentJSON thread body

            ((Entity _ c):_) <- runDB $ selectList [] []
            assertEqual' (commentThread c) thread
            assertEqual' (commentBody c) body

        yit "responds with a 400 for invalid requests" $ do
            postBody CommentsR $ encode $ object []

            statusIs 400

commentJSON :: Text -> Text -> ByteString
commentJSON thread body = encode $ object ["thread" .= thread, "body" .= body]
{'fraction_non_alphanumeric': 0.0925207756232687, 'fraction_numerical': 0.0110803324099723, 'mean_word_length': 2.3820224719101124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190883', 'n_tokens_mistral': 504, 'n_tokens_neox': 465, 'n_words': 164}