feat: gamemaster
This commit is contained in:
@@ -31,15 +31,15 @@ func TestGameOpenAPISpecFreezesResponseSchemas(t *testing.T) {
|
||||
wantRef string
|
||||
}{
|
||||
{
|
||||
name: "get game status",
|
||||
path: "/api/v1/status",
|
||||
name: "admin get game status",
|
||||
path: "/api/v1/admin/status",
|
||||
method: http.MethodGet,
|
||||
status: http.StatusOK,
|
||||
wantRef: "#/components/schemas/StateResponse",
|
||||
},
|
||||
{
|
||||
name: "init game",
|
||||
path: "/api/v1/init",
|
||||
name: "admin init game",
|
||||
path: "/api/v1/admin/init",
|
||||
method: http.MethodPost,
|
||||
status: http.StatusCreated,
|
||||
wantRef: "#/components/schemas/StateResponse",
|
||||
@@ -52,8 +52,8 @@ func TestGameOpenAPISpecFreezesResponseSchemas(t *testing.T) {
|
||||
wantRef: "#/components/schemas/Report",
|
||||
},
|
||||
{
|
||||
name: "generate turn",
|
||||
path: "/api/v1/turn",
|
||||
name: "admin generate turn",
|
||||
path: "/api/v1/admin/turn",
|
||||
method: http.MethodPut,
|
||||
status: http.StatusOK,
|
||||
wantRef: "#/components/schemas/StateResponse",
|
||||
@@ -81,7 +81,7 @@ func TestGameOpenAPISpecFreezesInitRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
doc := loadOpenAPISpec(t)
|
||||
operation := getOpenAPIOperation(t, doc, "/api/v1/init", http.MethodPost)
|
||||
operation := getOpenAPIOperation(t, doc, "/api/v1/admin/init", http.MethodPost)
|
||||
|
||||
assertSchemaRef(t, requestSchemaRef(t, operation), "#/components/schemas/InitRequest", "init request schema")
|
||||
|
||||
@@ -93,6 +93,68 @@ func TestGameOpenAPISpecFreezesInitRequest(t *testing.T) {
|
||||
require.Equal(t, uint64(10), racesSchema.Value.MinItems, "InitRequest.races minItems must be 10")
|
||||
}
|
||||
|
||||
func TestGameOpenAPISpecFreezesAdminOperationIDs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
doc := loadOpenAPISpec(t)
|
||||
|
||||
tests := []struct {
|
||||
path string
|
||||
method string
|
||||
opID string
|
||||
}{
|
||||
{"/api/v1/admin/init", http.MethodPost, "adminInitGame"},
|
||||
{"/api/v1/admin/status", http.MethodGet, "adminGetGameStatus"},
|
||||
{"/api/v1/admin/turn", http.MethodPut, "adminGenerateTurn"},
|
||||
{"/api/v1/admin/race/banish", http.MethodPost, "adminBanishRace"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.opID, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
operation := getOpenAPIOperation(t, doc, tt.path, tt.method)
|
||||
require.Equal(t, tt.opID, operation.OperationID, "operation id for %s %s", tt.method, tt.path)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGameOpenAPISpecFreezesBanishRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
doc := loadOpenAPISpec(t)
|
||||
operation := getOpenAPIOperation(t, doc, "/api/v1/admin/race/banish", http.MethodPost)
|
||||
|
||||
assertSchemaRef(t, requestSchemaRef(t, operation), "#/components/schemas/BanishRequest", "banish request schema")
|
||||
|
||||
if operation.Responses == nil {
|
||||
require.FailNow(t, "banish operation is missing responses")
|
||||
}
|
||||
noContent := operation.Responses.Status(http.StatusNoContent)
|
||||
require.NotNil(t, noContent, "banish operation must declare 204 response")
|
||||
require.NotNil(t, noContent.Value, "banish 204 response must have a value")
|
||||
|
||||
schema := componentSchemaRef(t, doc, "BanishRequest")
|
||||
assertRequiredFields(t, schema, "race_name")
|
||||
|
||||
raceNameSchema := schema.Value.Properties["race_name"]
|
||||
require.NotNil(t, raceNameSchema, "BanishRequest.race_name schema must exist")
|
||||
require.Equal(t, uint64(1), raceNameSchema.Value.MinLength, "BanishRequest.race_name minLength must be 1")
|
||||
}
|
||||
|
||||
func TestGameOpenAPISpecFreezesStateResponseFinished(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
doc := loadOpenAPISpec(t)
|
||||
schema := componentSchemaRef(t, doc, "StateResponse")
|
||||
|
||||
assertRequiredFields(t, schema, "id", "turn", "stage", "player", "finished")
|
||||
|
||||
finishedSchema := schema.Value.Properties["finished"]
|
||||
require.NotNil(t, finishedSchema, "StateResponse.finished schema must exist")
|
||||
require.True(t, finishedSchema.Value.Type.Is("boolean"), "StateResponse.finished must be boolean")
|
||||
}
|
||||
|
||||
func TestGameOpenAPISpecFreezesCommandRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user