Add depot, attendant, jetfire, optimus, ota services with kustomize overlays
This commit is contained in:
55
services/ota_update_go/handlers/sub_feature_add_test.go
Normal file
55
services/ota_update_go/handlers/sub_feature_add_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package handlers_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestSubscriptionFeatureAdd(t *testing.T) {
|
||||
mock := mo.MockSubscriptionFeatures{}
|
||||
services.GetDB().SetSubFeatures(&mock)
|
||||
validData := common.SubscriptionFeature{
|
||||
Name: "feature_name",
|
||||
Description: "description",
|
||||
}
|
||||
tests := []mo.DBHttpTest{
|
||||
{
|
||||
Name: "No data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/subscriptionfeature", nil),
|
||||
ExpectedStatus: http.StatusBadRequest,
|
||||
ExpectedResponse: `{"message":"Name required. Description required","error":"Bad Request"}`,
|
||||
},
|
||||
{
|
||||
Name: "Invalid data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/subscriptionfeature", common.SubscriptionFeature{
|
||||
Name: "feature_name",
|
||||
}),
|
||||
ExpectedStatus: http.StatusBadRequest,
|
||||
ExpectedResponse: `{"message":"Description required","error":"Bad Request"}`,
|
||||
},
|
||||
{
|
||||
Name: "Valid data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/subscriptionfeature", validData),
|
||||
ExpectedStatus: http.StatusOK,
|
||||
ExpectedResponse: `{"id":"ecfb89e0-ca03-4aa9-a43a-a9d703256edb","name":"feature_name","description":"description"}`,
|
||||
},
|
||||
{
|
||||
Name: "DB error",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/subscriptionfeature", validData),
|
||||
ExpectedStatus: http.StatusServiceUnavailable,
|
||||
ExpectedResponse: `{"message":"something went wrong","error":"Service Unavailable"}`,
|
||||
DBTestCase: mo.DBTestCase{
|
||||
MockError: fmt.Errorf("something went wrong"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
mo.RunDBTests(t, tests, handlers.HandleSubscriptionFeatureAdd, &mock)
|
||||
}
|
||||
Reference in New Issue
Block a user