Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/web/response_test.go
988 views
1
package web
2
3
import (
4
"testing"
5
6
assertion "github.com/stretchr/testify/assert"
7
)
8
9
func TestResponse(t *testing.T) {
10
assert := assertion.New(t)
11
12
t.Run("successResponse", func(t *testing.T) {
13
t.Run("should return success response", func(t *testing.T) {
14
result := successResponse()
15
16
assert.IsType(JSONResponse{}, result)
17
assert.Equal(result.Success, true, "they should be equal")
18
assert.Equal(result.Error, "", "they should be equal")
19
})
20
21
t.Run("should return success response with custom message", func(t *testing.T) {
22
result := successResponse("test")
23
24
assert.IsType(JSONResponse{}, result)
25
assert.Equal(result.Success, true, "they should be equal")
26
assert.Equal(result.Error, "", "they should be equal")
27
assert.Equal(result.Message, "test", "they should be equal")
28
})
29
})
30
31
t.Run("errorResponse", func(t *testing.T) {
32
t.Run("should return error response", func(t *testing.T) {
33
result := errorResponse()
34
35
assert.IsType(JSONResponse{}, result)
36
assert.Equal(result.Success, false, "they should be equal")
37
assert.Equal(result.Error, "An error occurred", "they should be equal")
38
})
39
40
t.Run("should return error response with custom message", func(t *testing.T) {
41
result := errorResponse("test")
42
43
assert.IsType(JSONResponse{}, result)
44
assert.Equal(result.Success, false, "they should be equal")
45
assert.Equal(result.Error, "test", "they should be equal")
46
})
47
})
48
}
49
50