package joke_test import ( "io/ioutil" "net/http" "strings" "testing" "time" "github.com/stretchr/testify/assert" ) func TestAddNewJoke_201(t *testing.T) { // TODO: Remove this line below, make this test works t.SkipNow() err := setup() if err != nil { t.Fatal(err) } defer cleanup() reqBody := strings.NewReader("{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\",\"key\":\"test\",\"token\":\"password\"}") req, _ := http.NewRequest("PUT", "/", reqBody) req.Header.Set("content-type", "application/json") req.Header.Add("accept", "application/json") res, err := app.Test(req, int(time.Minute * 2)) if err != nil { t.Fatal(err) } assert.Equalf(t, false, err != nil, "joke add") assert.Equalf(t, 201, res.StatusCode, "joke add") assert.NotEqualf(t, 0, res.ContentLength, "joke add") body, err := ioutil.ReadAll(res.Body) assert.Nilf(t, err, "joke add") assert.Equalf(t, "{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\"}", string(body), "joke add") } func TestAddNewJoke_NotValidImage(t *testing.T) { // TODO: Remove this line below, make this test works t.SkipNow() err := setup() if err != nil { t.Fatal(err) } defer cleanup() reqBody := strings.NewReader("{\"link\":\"https://google.com/\",\"key\":\"test\",\"token\":\"password\"}") req, _ := http.NewRequest("PUT", "/", reqBody) req.Header.Set("content-type", "application/json") req.Header.Add("accept", "application/json") res, err := app.Test(req, int(time.Minute * 2)) if err != nil { t.Fatal(err) } assert.Equalf(t, false, err != nil, "joke add") assert.Equalf(t, 400, res.StatusCode, "joke add") body, err := ioutil.ReadAll(res.Body) if err != nil { t.Fatal(err) } defer res.Body.Close() assert.Nilf(t, err, "joke add") assert.Equalf(t, "{\"error\":\"URL provided is not a valid image\"}", string(body), "joke add") }