Files

42 lines
1.3 KiB
Go

package handlers_test
import (
"net/http"
"testing"
"otaupdate/handlers"
"otaupdate/services"
mo "github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
)
func TestIssueGet(t *testing.T) {
mock := mo.MockIssue{}
services.GetDB().SetIssues(&mock)
tests := []th.BasicHttpTest{
{
Name: "Invalid Issue ID",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/issues/x", nil),
ExpectedStatus: http.StatusNotFound,
ExpectedResponse: `{"message":"invalid id","error":"Not Found"}`,
},
{
Name: "Zero Issue ID",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/issues/0", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"id cannot be less than 0","error":"Bad Request"}`,
},
{
Name: "Good Issue Id",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/issues/1", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"data":{"id":1,"vin":"","title":"","description":"","timestamp":"0001-01-01T00:00:00Z","images":[{"id":1,"image":"","issue_id":1}]}}`,
},
}
th.RunParamHttpTests(t, tests, handlers.HandleIssueGet, "/issues/:id")
}