Add depot, attendant, jetfire, optimus, ota services with kustomize overlays
This commit is contained in:
58
services/ota_update_go/handlers/sub_package_delete_test.go
Normal file
58
services/ota_update_go/handlers/sub_package_delete_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package handlers_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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 TestSubscriptionPackageDelete(t *testing.T) {
|
||||
results := mocks.MockORMResults{
|
||||
ReturnedRows: 1,
|
||||
AffectedRows: 1,
|
||||
}
|
||||
mock := mocks.MockSubscriptionPackages{
|
||||
DBMockHelper: mocks.DBMockHelper{
|
||||
ORMResponse: &results,
|
||||
},
|
||||
}
|
||||
services.GetDB().SetSubPackages(&mock)
|
||||
|
||||
tests := []mocks.DBHttpTest{
|
||||
{
|
||||
Name: "No id",
|
||||
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/subscriptionpackage", nil),
|
||||
ExpectedStatus: http.StatusBadRequest,
|
||||
ExpectedResponse: `{"message":"primary key required","error":"Bad Request"}`,
|
||||
},
|
||||
{
|
||||
Name: "Zero id",
|
||||
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/subscriptionpackage?id=0", nil),
|
||||
ExpectedStatus: http.StatusBadRequest,
|
||||
ExpectedResponse: `{"message":"primary key required","error":"Bad Request"}`,
|
||||
},
|
||||
{
|
||||
Name: "Good id",
|
||||
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/subscriptionpackage?id=0557bd1d-76d3-41e5-a44e-13c479e55ab0", nil),
|
||||
ExpectedStatus: http.StatusOK,
|
||||
ExpectedResponse: `{"message":"Deleted"}`,
|
||||
},
|
||||
{
|
||||
Name: "DB error",
|
||||
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/subscriptionpackage?id=0557bd1d-76d3-41e5-a44e-13c479e55ab0", nil),
|
||||
ExpectedStatus: http.StatusServiceUnavailable,
|
||||
ExpectedResponse: `{"message":"something went wrong","error":"Service Unavailable"}`,
|
||||
DBTestCase: mocks.DBTestCase{
|
||||
MockError: fmt.Errorf("something went wrong"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
mocks.RunDBTests(t, tests, handlers.HandleSubscriptionPackageDelete, &mock)
|
||||
}
|
||||
Reference in New Issue
Block a user