jokes-bapak2/api/app/v1/handler/joke/joke_update_test.go

56 lines
1.7 KiB
Go
Raw Normal View History

package joke_test
import (
"io/ioutil"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
2021-08-04 05:56:14 +00:00
func TestUpdateJoke_200(t *testing.T) {
t.SkipNow()
2021-08-04 05:56:14 +00:00
err := setup()
if err != nil {
t.Fatal(err)
}
2021-08-04 05:56:14 +00:00
defer cleanup()
2021-08-04 10:05:58 +00:00
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"test\",\"token\":\"password\"}")
2021-08-04 05:56:14 +00:00
req, _ := http.NewRequest("PATCH", "/id/1", reqBody)
2021-08-04 10:05:58 +00:00
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
2021-08-04 05:56:14 +00:00
res, err := app.Test(req, -1)
assert.Equalf(t, false, err != nil, "joke update")
assert.Equalf(t, 200, res.StatusCode, "joke update")
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
body, err := ioutil.ReadAll(res.Body)
assert.Nilf(t, err, "joke update")
assert.Equalf(t, "{\"message\":\"specified joke id has been deleted\"}", string(body), "joke update")
}
func TestUpdateJoke_NotExists(t *testing.T) {
2021-08-04 10:05:58 +00:00
// TODO: Remove this line below, make this test works
2021-08-04 05:56:14 +00:00
t.SkipNow()
err := setup()
if err != nil {
t.Fatal(err)
}
2021-08-04 05:56:14 +00:00
defer cleanup()
2021-08-04 10:05:58 +00:00
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/9/200/300\",\"key\":\"test\",\"token\":\"password\"}")
2021-08-04 05:56:14 +00:00
req, _ := http.NewRequest("PATCH", "/id/100", reqBody)
2021-08-04 10:05:58 +00:00
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
2021-08-04 05:56:14 +00:00
res, err := app.Test(req, -1)
assert.Equalf(t, false, err != nil, "joke update")
assert.Equalf(t, 406, res.StatusCode, "joke update")
assert.NotEqualf(t, 0, res.ContentLength, "joke update")
body, err := ioutil.ReadAll(res.Body)
assert.Nilf(t, err, "joke update")
assert.Equalf(t, "{\"message\":\"specified joke id does not exists\"}", string(body), "joke update")
}