Add depot, attendant, jetfire, optimus, ota services with kustomize overlays

This commit is contained in:
Chris Rai
2026-01-31 15:35:07 -05:00
parent a0ec642ca1
commit 9a5cb2f547
404 changed files with 38817 additions and 16 deletions

View File

@@ -0,0 +1,64 @@
package handlers_test
import (
"fmt"
"net/http"
"testing"
"otaupdate/handlers"
"otaupdate/services"
"github.com/fiskerinc/cloud-services/pkg/common"
"github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
th "github.com/fiskerinc/cloud-services/pkg/testhelper"
)
func TestAPITokenDelete(t *testing.T) {
results := mocks.MockORMResults{
ReturnedRows: 1,
AffectedRows: 1,
}
mock := mocks.MockAPITokens{
DBMockHelper: mocks.DBMockHelper{
ORMResponse: &results,
},
}
services.GetDB().SetAPITokens(&mock)
tests := []mocks.DBHttpTest{
{
Name: "No id",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/apitoken", common.APIToken{}),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"primary key required","error":"Bad Request"}`,
},
{
Name: "Invalid data",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/apitoken?roles=TESTTOKEN", nil),
ExpectedStatus: http.StatusBadRequest,
ExpectedResponse: `{"message":"primary key required","error":"Bad Request"}`,
},
{
Name: "Good id",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/apitoken?token=TESTTOKEN", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"message":"Deleted"}`,
DBTestCase: mocks.DBTestCase{
ExpectedFilter: &common.APIToken{
Token: "TESTTOKEN",
},
},
},
{
Name: "DB error",
Request: th.MakeTestRequest(http.MethodDelete, "http://example.com/apitoken?token=TESTTOKEN", 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.HandleAPITokenDelete, &mock)
}