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

51 lines
1.7 KiB
Go

package handlers_test
import (
"net/http"
"otaupdate/handlers"
"otaupdate/services"
"testing"
"github.com/fiskerinc/cloud-services/pkg/common"
mo "github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
"github.com/fiskerinc/cloud-services/pkg/utils/elptr"
)
func TestUpdateManifestAdd(t *testing.T) {
mock := mo.MockUpdateManifests{}
services.GetDB().SetUpdateManifests(&mock)
tests := []mo.DBHttpTest{
{
Name: "Valid data",
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/manifest", common.CreateUpdateManifest{
Name: "package_name",
Version: "100",
Description: "description",
ReleaseNotes: "http://releasenotes.com",
Type: "standard",
RollbackEnabled: true,
Active: elptr.ElPtr(true),
Country: "US",
PowerTrain: "MD23",
Restraint: "None",
Model: "Ocean",
Trim: "Sport",
Year: 2022,
BodyType: "truck",
}),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"id":1,"name":"package_name","version":"100","description":"description","release_notes":"http://releasenotes.com","rollback":true,"type":"standard","active":true,"country":"US","powertrain":"MD23","restraint":"None","model":"Ocean","trim":"Sport","year":2022,"body_type":"truck"}`,
},
{
Name: "No data",
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/manifest", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"Name required","error":"Bad Request"}`,
},
}
mo.RunDBTests(t, tests, handlers.HandleUpdateManifestAdd, &mock)
}