jokes-bapak2/api/app/v1/utils/parse_test.go

44 lines
985 B
Go
Raw Normal View History

2021-07-09 12:13:19 +00:00
package utils_test
import (
"testing"
2021-07-14 18:17:01 +00:00
"jokes-bapak2-api/app/v1/utils"
2021-07-09 12:13:19 +00:00
)
func TestParseToJSONBody(t *testing.T) {
t.Run("should be able to parse a json string", func(t *testing.T) {
body := map[string]interface{}{
"name": "Scott",
"age": 32,
"fat": true,
}
parsed, err := utils.ParseToJSONBody(body)
if err != nil {
t.Error(err.Error())
}
result := "{\"age\":32,\"fat\":true,\"name\":\"Scott\"}"
if string(parsed) != result {
t.Error("parsed string is not the same as result:", string(parsed))
}
})
}
func TestParseToFormBody(t *testing.T) {
t.Run("should be able to parse a form body", func(t *testing.T) {
body := map[string]interface{}{
"name": "Scott",
"age": 32,
"fat": true,
}
parsed, err := utils.ParseToFormBody(body)
if err != nil {
t.Error(err.Error())
}
result := "name=Scott&age=32&fat=true&"
if string(parsed) != result {
t.Error("parsed string is not the same as result:", string(parsed))
}
})
}