fix: validation didnt run properly
This commit is contained in:
parent
2237bd7efd
commit
600385b96e
|
@ -20,10 +20,10 @@ func CheckImageValidity(client *httpclient.Client, link string) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
if res.StatusCode == 200 && res.ContentLength > 0 && utils.IsIn(ValidContentType, res.Header.Get("content-type")) {
|
||||
if res.StatusCode == 200 && utils.IsIn(ValidContentType, res.Header.Get("content-type")) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.New("URL must use HTTPS protocol")
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestAddNewJoke(t *testing.T) {
|
|||
app := v1.New()
|
||||
|
||||
t.Run("Add - should return 201", func(t *testing.T) {
|
||||
reqBody := strings.NewReader("{\"link\":\"https://picsum.photos/id/1/200/300\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||
reqBody := strings.NewReader("{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\",\"key\":\"very secure\",\"token\":\"password\"}")
|
||||
req, _ := http.NewRequest("PUT", "/", reqBody)
|
||||
req.Header.Set("content-type", "application/json")
|
||||
req.Header.Add("accept", "application/json")
|
||||
|
@ -41,7 +41,21 @@ func TestAddNewJoke(t *testing.T) {
|
|||
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://picsum.photos/id/1/200/300\"}", string(body), "joke add")
|
||||
|
||||
assert.Equalf(t, "{\"link\":\"https://via.placeholder.com/300/07f/ff0000.png\"}", string(body), "joke add")
|
||||
})
|
||||
|
||||
t.Run("Add - should not be a valid image", func(t *testing.T) {
|
||||
reqBody := strings.NewReader("{\"link\":\"https://google.com/\",\"key\":\"very secure\",\"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, -1)
|
||||
|
||||
assert.Equalf(t, false, err != nil, "joke add")
|
||||
assert.Equalf(t, 400, res.StatusCode, "joke add")
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
assert.Nilf(t, err, "joke add")
|
||||
assert.Equalf(t, "{\"error\":\"URL provided is not a valid image\"}", string(body), "joke add")
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
var db = database.New()
|
||||
var jokesData = []interface{}{1, "https://picsum.photos/id/1/200/300", 1, 2, "https://picsum.photos/id/2/200/300", 1, 3, "https://picsum.photos/id/3/200/300", 1}
|
||||
var jokesData = []interface{}{1, "https://via.placeholder.com/300/06f/fff.png", 1, 2, "https://via.placeholder.com/300/07f/fff.png", 1, 3, "https://via.placeholder.com/300/08f/fff.png", 1}
|
||||
|
||||
func cleanup() {
|
||||
_, err := db.Query(context.Background(), "DROP TABLE \"jokesbapak2\"")
|
||||
|
|
Loading…
Reference in New Issue