Add depot, attendant, jetfire, optimus, ota services with kustomize overlays
This commit is contained in:
51
services/ota_update_go/handlers/supplier_activate_test.go
Normal file
51
services/ota_update_go/handlers/supplier_activate_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package handlers_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"otaupdate/handlers"
|
||||
"otaupdate/services"
|
||||
|
||||
"github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
|
||||
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
|
||||
)
|
||||
|
||||
func TestHandleSupplierActivate(t *testing.T) {
|
||||
mock := mocks.MockSupplierAccounts{}
|
||||
services.GetDB().SetSupplierAccount(&mock)
|
||||
|
||||
tests := []mocks.DBHttpTest{
|
||||
{
|
||||
Name: "Good data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/supplier/activate/test@supplier.com", nil),
|
||||
ExpectedStatus: http.StatusOK,
|
||||
ExpectedResponseRegex: regexp.MustCompile(`{"activate":"[^"]+"}`),
|
||||
},
|
||||
{
|
||||
Name: "Error",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/supplier/activate/test@supplier.com", nil),
|
||||
ExpectedStatus: http.StatusServiceUnavailable,
|
||||
ExpectedResponse: `{"message":"something went wrong","error":"Service Unavailable"}`,
|
||||
DBTestCase: mocks.DBTestCase{
|
||||
MockError: fmt.Errorf("something went wrong"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "No data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/supplier/activate/", nil),
|
||||
ExpectedStatus: http.StatusNotFound,
|
||||
ExpectedResponse: err404NotFound,
|
||||
},
|
||||
{
|
||||
Name: "Bad Data",
|
||||
Request: th.MakeTestRequest(http.MethodPost, "http://example.com/supplier/activate/test", nil),
|
||||
ExpectedStatus: http.StatusBadRequest,
|
||||
ExpectedResponse: `{"message":"email email ","error":"Bad Request"}`,
|
||||
},
|
||||
}
|
||||
|
||||
mocks.RunParamHttpTests(t, tests, handlers.HandleSupplierActivate, "/supplier/activate/:email", &mock)
|
||||
}
|
||||
Reference in New Issue
Block a user