forked from sundowndev/phoneinfoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
47 lines (36 loc) · 1.34 KB
/
response_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
45
46
47
package api
import (
"testing"
assertion "github.com/stretchr/testify/assert"
)
func TestResponse(t *testing.T) {
assert := assertion.New(t)
t.Run("successResponse", func(t *testing.T) {
t.Run("should return success response", func(t *testing.T) {
result := successResponse()
assert.IsType(JSONResponse{}, result)
assert.Equal(result.Success, true, "they should be equal")
assert.Equal(result.Error, "", "they should be equal")
})
t.Run("should return success response with custom message", func(t *testing.T) {
result := successResponse("test")
assert.IsType(JSONResponse{}, result)
assert.Equal(result.Success, true, "they should be equal")
assert.Equal(result.Error, "test", "they should be equal")
})
})
t.Run("errorResponse", func(t *testing.T) {
t.Run("should return error response", func(t *testing.T) {
result := errorResponse()
assert.IsType(JSONResponse{}, result)
assert.Equal(result.Success, false, "they should be equal")
assert.Equal(result.Error, "An error occurred", "they should be equal")
})
t.Run("should return error response with custom message", func(t *testing.T) {
result := errorResponse("test")
assert.IsType(JSONResponse{}, result)
assert.Equal(result.Success, false, "they should be equal")
assert.Equal(result.Error, "test", "they should be equal")
})
})
}