Files

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"
"github.com/fiskerinc/cloud-services/pkg/mongo"
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
)
func TestVehicleGet(t *testing.T) {
client, err := services.GetMongoClient()
if err != nil {
t.Error(err)
return
}
services.GetDB().SetCars(&mocks.MockCars{})
client.SetVehicles(mongo.NewVehiclesCollection(&mongo.MockCollection{}))
tests := []th.BasicHttpTest{
{
Name: "Zero id",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/vehicle/0", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"vin '0' invalid","error":"Bad Request"}`,
},
{
Name: "Good id",
Request: th.MakeTestRequest(http.MethodGet, "http://example.com/vehicle/1G1FP87S3GN100062", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"vin":"1G1FP87S3GN100062","log_level":"trace","dlt_enabled":false,"canbus":{"enabled":false,"data_logger_enabled":false,"dtc_enabled":false},"idps_enabled":false,"fleets":null}`,
},
}
th.RunParamHttpTests(t, tests, handlers.HandleVehicleGet, "/vehicle/:vin")
}