41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package handlers_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"otaupdate/handlers"
|
|
"otaupdate/services"
|
|
|
|
"github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
|
|
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
|
|
)
|
|
|
|
func TestIssuesDelete(t *testing.T) {
|
|
db := services.GetDB()
|
|
|
|
db.SetIssues(&mocks.MockIssue{})
|
|
tests := []th.BasicHttpTest{
|
|
{
|
|
Name: "Invalid ID",
|
|
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/issues/x", nil),
|
|
ExpectedStatus: http.StatusBadRequest,
|
|
ExpectedResponse: `{"message":"strconv.Atoi: parsing \"x\": invalid syntax","error":"Bad Request"}`,
|
|
},
|
|
{
|
|
Name: "Zero id",
|
|
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/issues/0", nil),
|
|
ExpectedStatus: http.StatusBadRequest,
|
|
ExpectedResponse: `{"message":"id cannot be less than 0","error":"Bad Request"}`,
|
|
},
|
|
{
|
|
Name: "Good Request",
|
|
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/issues/1", nil),
|
|
ExpectedStatus: http.StatusOK,
|
|
ExpectedResponse: `{"message":"Deleted"}`,
|
|
},
|
|
}
|
|
|
|
th.RunParamHttpTests(t, tests, handlers.HandleIssuesDelete, "/issues/:id")
|
|
}
|