jokes-bapak2/api/utils/parse_test.go

40 lines
953 B
Go
Raw Permalink Normal View History

2021-07-09 12:13:19 +00:00
package utils_test
import (
2021-10-30 03:24:53 +00:00
"jokes-bapak2-api/utils"
"strings"
2021-07-09 12:13:19 +00:00
"testing"
)
func TestParseToJSONBody(t *testing.T) {
2021-08-04 05:56:14 +00:00
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))
}
2021-07-09 12:13:19 +00:00
}
func TestParseToFormBody(t *testing.T) {
2021-08-04 05:56:14 +00:00
body := map[string]interface{}{
"age": 32,
"fat": true,
"name": "Scott",
}
parsed, err := utils.ParseToFormBody(body)
if err != nil {
t.Error(err.Error())
}
result := [3]string{"age=32&", "fat=true&", "name=Scott&"}
if !strings.Contains(string(parsed), result[0]) && !strings.Contains(string(parsed), result[1]) && !strings.Contains(string(parsed), result[2]) {
t.Error("parsed string is not the same as result:", string(parsed))
}
2021-07-09 12:13:19 +00:00
}