feat: order processing
feat: order commands result save/load
This commit is contained in:
@@ -6,29 +6,19 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/iliadenisov/galaxy/internal/model/order"
|
||||
"github.com/iliadenisov/galaxy/internal/model/rest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
commandNoErrorsStatus = http.StatusNoContent
|
||||
commandDefaultActor = "Gorlum"
|
||||
apiCommandMethod = "PUT"
|
||||
apiCommandPath = "/api/v1/command"
|
||||
validId1 = uuid.New().String()
|
||||
validId2 = uuid.New().String()
|
||||
invalidId = "fd091c69-5976-4775-b2f9-7ba77735afb"
|
||||
)
|
||||
|
||||
func TestCommandRaceQuit(t *testing.T) {
|
||||
r := setupRouter()
|
||||
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandRaceQuit{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeRaceQuit},
|
||||
encodeCommand(&order.CommandRaceQuit{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeRaceQuit},
|
||||
}),
|
||||
},
|
||||
}
|
||||
@@ -56,8 +46,8 @@ func TestCommandRaceQuit(t *testing.T) {
|
||||
|
||||
// unrecognized command type
|
||||
payload.Commands = []json.RawMessage{
|
||||
encodeCommand(&rest.CommandRaceQuit{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandType("-unknown-")},
|
||||
encodeCommand(&order.CommandRaceQuit{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandType("-unknown-")},
|
||||
}),
|
||||
}
|
||||
w = httptest.NewRecorder()
|
||||
@@ -95,8 +85,8 @@ func TestCommandRaceVote(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandRaceVote{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeRaceVote},
|
||||
encodeCommand(&order.CommandRaceVote{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeRaceVote},
|
||||
Acceptor: tc.acceptor,
|
||||
}),
|
||||
},
|
||||
@@ -133,8 +123,8 @@ func TestCommandRaceRelation(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandRaceRelation{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeRaceRelation},
|
||||
encodeCommand(&order.CommandRaceRelation{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeRaceRelation},
|
||||
Acceptor: tc.acceptor,
|
||||
Relation: tc.relation,
|
||||
}),
|
||||
@@ -184,8 +174,8 @@ func TestCommandShipClassCreate(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipClassCreate{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipClassCreate},
|
||||
encodeCommand(&order.CommandShipClassCreate{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipClassCreate},
|
||||
Name: tc.name,
|
||||
Drive: tc.D,
|
||||
Armament: tc.A,
|
||||
@@ -227,8 +217,8 @@ func TestCommandShipClassMerge(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipClassMerge{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipClassMerge},
|
||||
encodeCommand(&order.CommandShipClassMerge{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipClassMerge},
|
||||
Name: tc.name,
|
||||
Target: tc.target,
|
||||
}),
|
||||
@@ -261,8 +251,8 @@ func TestCommandShipClassRemove(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipClassRemove{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipClassRemove},
|
||||
encodeCommand(&order.CommandShipClassRemove{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipClassRemove},
|
||||
Name: tc.name,
|
||||
}),
|
||||
},
|
||||
@@ -300,8 +290,8 @@ func TestCommandShipGroupBreak(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupBreak{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupBreak},
|
||||
encodeCommand(&order.CommandShipGroupBreak{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupBreak},
|
||||
ID: tc.id,
|
||||
NewID: tc.newId,
|
||||
Quantity: tc.quantity,
|
||||
@@ -341,8 +331,8 @@ func TestCommandShipGroupLoad(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupLoad{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupLoad},
|
||||
encodeCommand(&order.CommandShipGroupLoad{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupLoad},
|
||||
ID: tc.id,
|
||||
Cargo: tc.cargo,
|
||||
Quantity: tc.quantity,
|
||||
@@ -378,8 +368,8 @@ func TestCommandShipGroupUnload(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupUnload{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupUnload},
|
||||
encodeCommand(&order.CommandShipGroupUnload{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupUnload},
|
||||
ID: tc.id,
|
||||
Quantity: tc.quantity,
|
||||
}),
|
||||
@@ -414,8 +404,8 @@ func TestCommandShipGroupSend(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupSend{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupSend},
|
||||
encodeCommand(&order.CommandShipGroupSend{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupSend},
|
||||
ID: tc.id,
|
||||
Destination: tc.destination,
|
||||
}),
|
||||
@@ -456,8 +446,8 @@ func TestCommandShipGroupUpgrade(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupUpgrade{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupUpgrade},
|
||||
encodeCommand(&order.CommandShipGroupUpgrade{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupUpgrade},
|
||||
ID: tc.id,
|
||||
Tech: tc.tech,
|
||||
Level: tc.level,
|
||||
@@ -487,8 +477,8 @@ func TestCommandShipGroupMerge(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupMerge{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupMerge},
|
||||
encodeCommand(&order.CommandShipGroupMerge{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupMerge},
|
||||
}),
|
||||
},
|
||||
}
|
||||
@@ -518,8 +508,8 @@ func TestCommandShipGroupDismantle(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupDismantle{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupDismantle},
|
||||
encodeCommand(&order.CommandShipGroupDismantle{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupDismantle},
|
||||
ID: tc.id,
|
||||
}),
|
||||
},
|
||||
@@ -554,8 +544,8 @@ func TestCommandShipGroupTransfer(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupTransfer{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupTransfer},
|
||||
encodeCommand(&order.CommandShipGroupTransfer{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupTransfer},
|
||||
ID: tc.id,
|
||||
Acceptor: tc.acceptor,
|
||||
}),
|
||||
@@ -591,8 +581,8 @@ func TestCommandShipGroupJoinFleet(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandShipGroupJoinFleet{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeShipGroupJoinFleet},
|
||||
encodeCommand(&order.CommandShipGroupJoinFleet{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeShipGroupJoinFleet},
|
||||
ID: tc.id,
|
||||
Name: tc.name,
|
||||
}),
|
||||
@@ -628,8 +618,8 @@ func TestCommandFleetMerge(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandFleetMerge{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeFleetMerge},
|
||||
encodeCommand(&order.CommandFleetMerge{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeFleetMerge},
|
||||
Name: tc.name,
|
||||
Target: tc.target,
|
||||
}),
|
||||
@@ -664,8 +654,8 @@ func TestCommandFleetSend(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandFleetSend{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeFleetSend},
|
||||
encodeCommand(&order.CommandFleetSend{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeFleetSend},
|
||||
Name: tc.name,
|
||||
Destination: tc.destination,
|
||||
}),
|
||||
@@ -706,8 +696,8 @@ func TestCommandScienceCreate(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandScienceCreate{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeScienceCreate},
|
||||
encodeCommand(&order.CommandScienceCreate{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeScienceCreate},
|
||||
Name: tc.name,
|
||||
Drive: tc.D,
|
||||
Weapons: tc.W,
|
||||
@@ -743,8 +733,8 @@ func TestCommandScienceRemove(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandScienceRemove{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeScienceRemove},
|
||||
encodeCommand(&order.CommandScienceRemove{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeScienceRemove},
|
||||
Name: tc.name,
|
||||
}),
|
||||
},
|
||||
@@ -779,8 +769,8 @@ func TestCommandPlanetRename(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandPlanetRename{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypePlanetRename},
|
||||
encodeCommand(&order.CommandPlanetRename{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypePlanetRename},
|
||||
Number: tc.number,
|
||||
Name: tc.name,
|
||||
}),
|
||||
@@ -825,8 +815,8 @@ func TestCommandPlanetProduce(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandPlanetProduce{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypePlanetProduce},
|
||||
encodeCommand(&order.CommandPlanetProduce{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypePlanetProduce},
|
||||
Number: tc.number,
|
||||
Production: tc.production,
|
||||
Subject: tc.subject,
|
||||
@@ -866,8 +856,8 @@ func TestCommandPlanetRouteSet(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandPlanetRouteSet{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypePlanetRouteSet},
|
||||
encodeCommand(&order.CommandPlanetRouteSet{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypePlanetRouteSet},
|
||||
Origin: tc.origin,
|
||||
Destination: tc.destination,
|
||||
LoadType: tc.loadType,
|
||||
@@ -905,8 +895,8 @@ func TestCommandPlanetRouteRemove(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandPlanetRouteRemove{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypePlanetRouteRemove},
|
||||
encodeCommand(&order.CommandPlanetRouteRemove{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypePlanetRouteRemove},
|
||||
Origin: tc.origin,
|
||||
LoadType: tc.loadType,
|
||||
}),
|
||||
@@ -929,13 +919,13 @@ func TestMultipleCommands(t *testing.T) {
|
||||
payload := &rest.Command{
|
||||
Actor: commandDefaultActor,
|
||||
Commands: []json.RawMessage{
|
||||
encodeCommand(&rest.CommandRaceRelation{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeRaceRelation},
|
||||
encodeCommand(&order.CommandRaceRelation{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeRaceRelation},
|
||||
Acceptor: "Opponent",
|
||||
Relation: "PEACE",
|
||||
}),
|
||||
encodeCommand(&rest.CommandRaceVote{
|
||||
CommandMeta: rest.CommandMeta{Type: rest.CommandTypeRaceVote},
|
||||
encodeCommand(&order.CommandRaceVote{
|
||||
CommandMeta: order.CommandMeta{CmdID: id(), CmdType: order.CommandTypeRaceVote},
|
||||
Acceptor: "Opponent",
|
||||
}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user