Files
cloud-services/services/ota_update_go/handlers/vehicle_delete_test.go

60 lines
1.6 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 TestVehicleDelete(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{}))
client.SetFleets(mongo.NewFleetsCollection(&mongo.MockCollection{
AggregateObject: []mongo.Fleet{
{
Name: "US-TEST",
Vehicles: []string{
"2HNYD18936H520501",
},
},
},
}))
tests := []th.BasicHttpTest{
{
Name: "Zero id",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/vehicle/0", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"VIN '0' invalid","error":"Bad Request"}`,
},
{
Name: "Good id",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/vehicle/1G1FP87S3GN100062", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"message":"Deleted"}`,
},
{
Name: "VIN with fleet",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/vehicle/2HNYD18936H520501", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"message":"Deleted"}`,
},
}
_ = tests
_ = handlers.HandleVehicleDeleteHoneyPot
//th.RunParamHttpTests(t, tests, handlers.HandleVehicleDelete, "/vehicle/:vin")
}