-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_test.go
44 lines (37 loc) · 1.01 KB
/
comment_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package lain
import (
"context"
"strings"
"testing"
"github.com/alecthomas/assert/v2"
)
func TestService_CreateComment(t *testing.T) {
svc := &Service{Queries: testQueries}
ctx := context.Background()
t.Run("invalid_post_id", func(t *testing.T) {
_, err := svc.CreateComment(ctx, CreateCommentInput{PostID: "@nope@"})
assert.EqualError(t, err, "invalid post ID")
})
t.Run("empty_content", func(t *testing.T) {
_, err := svc.CreateComment(ctx, CreateCommentInput{
PostID: genID(),
Content: "",
})
assert.EqualError(t, err, "invalid comment content")
})
t.Run("too_long_content", func(t *testing.T) {
s := strings.Repeat("a", 1001)
_, err := svc.CreateComment(ctx, CreateCommentInput{
PostID: genID(),
Content: s,
})
assert.EqualError(t, err, "invalid comment content")
})
t.Run("unauthenticated", func(t *testing.T) {
_, err := svc.CreateComment(ctx, CreateCommentInput{
PostID: genID(),
Content: "Bhupendra Jogi",
})
assert.EqualError(t, err, "unauthenticated")
})
}