From 5cb31275e514967865d817ef31621ee01d69d732 Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Mon, 26 May 2025 21:05:53 -0500 Subject: [PATCH] Migrated lib/ to modules/, added test data and schema for each data type. --- src/go.mod | 41 +- src/go.sum | 1 - src/lib/database/tier/go.mod | 48 -- src/{lib => modules}/api/api.go | 0 src/{lib => modules}/api/go.mod | 0 src/{lib => modules}/api/go.sum | 0 src/{lib => modules}/auth/discord/discord.go | 0 src/{lib => modules}/auth/discord/go.mod | 0 src/{lib => modules}/auth/discord/go.sum | 0 src/{lib => modules}/config/server/go.mod | 0 src/{lib => modules}/config/server/go.sum | 0 src/{lib => modules}/config/server/server.go | 0 .../database/character/character.go | 0 .../database/character/go.mod | 0 .../database/character/go.sum | 0 .../database/customization/customization.go | 10 +- .../database/customization/go.mod | 0 .../database/customization/go.sum | 0 src/{lib => modules}/database/database.go | 0 .../database/function/function.go | 33 +- src/{lib => modules}/database/function/go.mod | 0 src/{lib => modules}/database/function/go.sum | 0 .../database/functionset/functionset.go | 46 +- .../database/functionset/go.mod | 0 .../database/functionset/go.sum | 0 .../database/functiontag/functiontag.go | 0 .../database/functiontag/go.mod | 0 .../database/functiontag/go.sum | 0 src/{lib => modules}/database/go.mod | 0 src/{lib => modules}/database/go.sum | 0 src/{lib => modules}/database/group/go.mod | 0 src/{lib => modules}/database/group/go.sum | 0 src/{lib => modules}/database/group/group.go | 0 .../database/inventoryslot/go.mod | 0 .../database/inventoryslot/go.sum | 0 .../database/inventoryslot/inventoryslot.go | 0 src/{lib => modules}/database/item/go.mod | 0 src/{lib => modules}/database/item/go.sum | 0 src/{lib => modules}/database/item/item.go | 10 +- src/{lib => modules}/database/itemtag/go.mod | 0 src/{lib => modules}/database/itemtag/go.sum | 0 .../database/itemtag/itemtag.go | 0 src/{lib => modules}/database/person/go.mod | 0 src/{lib => modules}/database/person/go.sum | 0 .../database/person/person.go | 0 src/{lib => modules}/database/role/go.mod | 0 src/{lib => modules}/database/role/go.sum | 0 src/{lib => modules}/database/role/role.go | 0 .../database/schematic/go.mod | 0 .../database/schematic/go.sum | 0 .../database/schematic/schematic.go | 10 +- src/modules/database/tier/go.mod | 22 + src/modules/database/tier/go.sum | 8 + src/{lib => modules}/database/tier/tier.go | 12 +- src/{lib => modules}/database/user/go.mod | 0 .../tier => modules/database/user}/go.sum | 0 src/{lib => modules}/database/user/user.go | 0 test/api_test.go | 96 +--- test/fixtures/characters.json | 88 ++++ test/fixtures/customizations.json | 142 ++++++ test/fixtures/functions.json | 79 +++ test/fixtures/functionset.json | 66 +++ test/fixtures/functiontags.json | 21 + test/fixtures/groups.json | 21 + test/fixtures/inventoryslots.json | 280 +++++++++++ test/fixtures/items.json | 280 +++++++++++ test/fixtures/itemtags.json | 21 + test/fixtures/persons.json | 52 ++ test/fixtures/roles.json | 104 ++++ test/fixtures/schemas/character.schema.json | 66 +++ .../schemas/customization.schema.json | 73 +++ test/fixtures/schemas/function.schema.json | 45 ++ test/fixtures/schemas/functionset.schema.json | 34 ++ test/fixtures/schemas/functiontag.schema.json | 31 ++ test/fixtures/schemas/group.schema.json | 31 ++ .../schemas/inventoryslot.schema.json | 34 ++ test/fixtures/schemas/item.schema.json | 81 ++++ test/fixtures/schemas/itemtag.schema.json | 31 ++ test/fixtures/schemas/person.schema.json | 38 ++ test/fixtures/schemas/role.schema.json | 45 ++ test/fixtures/schemas/schematic.schema.json | 70 +++ test/fixtures/schemas/tier.schema.json | 69 +++ test/fixtures/schemas/user.schema.json | 70 +++ test/fixtures/schematics.json | 459 ++++++++++++++++++ test/fixtures/tiers.json | 76 +++ test/go.mod | 74 +-- test/go.sum | 8 +- test/lib/testsetup/go.mod | 36 +- test/unit/functionsettest/functionsettest.go | 161 ++++++ test/unit/functionsettest/go.mod | 115 +++++ .../user => test/unit/functionsettest}/go.sum | 96 ++-- test/unit/functiontagtest/functiontagtest.go | 11 +- test/unit/functiontagtest/go.mod | 38 +- test/unit/functiontest/functiontest.go | 112 ++--- test/unit/functiontest/go.mod | 48 +- test/unit/grouptest/go.mod | 38 +- test/unit/grouptest/grouptest.go | 11 +- test/unit/persontest/go.mod | 42 +- test/unit/persontest/persontest.go | 52 +- test/unit/tiertest/go.mod | 110 +++++ test/unit/tiertest/go.sum | 111 +++++ test/unit/tiertest/tiertest.go | 247 ++++++++++ 102 files changed, 3601 insertions(+), 453 deletions(-) delete mode 100644 src/lib/database/tier/go.mod rename src/{lib => modules}/api/api.go (100%) rename src/{lib => modules}/api/go.mod (100%) rename src/{lib => modules}/api/go.sum (100%) rename src/{lib => modules}/auth/discord/discord.go (100%) rename src/{lib => modules}/auth/discord/go.mod (100%) rename src/{lib => modules}/auth/discord/go.sum (100%) rename src/{lib => modules}/config/server/go.mod (100%) rename src/{lib => modules}/config/server/go.sum (100%) rename src/{lib => modules}/config/server/server.go (100%) rename src/{lib => modules}/database/character/character.go (100%) rename src/{lib => modules}/database/character/go.mod (100%) rename src/{lib => modules}/database/character/go.sum (100%) rename src/{lib => modules}/database/customization/customization.go (97%) rename src/{lib => modules}/database/customization/go.mod (100%) rename src/{lib => modules}/database/customization/go.sum (100%) rename src/{lib => modules}/database/database.go (100%) rename src/{lib => modules}/database/function/function.go (87%) rename src/{lib => modules}/database/function/go.mod (100%) rename src/{lib => modules}/database/function/go.sum (100%) rename src/{lib => modules}/database/functionset/functionset.go (77%) rename src/{lib => modules}/database/functionset/go.mod (100%) rename src/{lib => modules}/database/functionset/go.sum (100%) rename src/{lib => modules}/database/functiontag/functiontag.go (100%) rename src/{lib => modules}/database/functiontag/go.mod (100%) rename src/{lib => modules}/database/functiontag/go.sum (100%) rename src/{lib => modules}/database/go.mod (100%) rename src/{lib => modules}/database/go.sum (100%) rename src/{lib => modules}/database/group/go.mod (100%) rename src/{lib => modules}/database/group/go.sum (100%) rename src/{lib => modules}/database/group/group.go (100%) rename src/{lib => modules}/database/inventoryslot/go.mod (100%) rename src/{lib => modules}/database/inventoryslot/go.sum (100%) rename src/{lib => modules}/database/inventoryslot/inventoryslot.go (100%) rename src/{lib => modules}/database/item/go.mod (100%) rename src/{lib => modules}/database/item/go.sum (100%) rename src/{lib => modules}/database/item/item.go (97%) rename src/{lib => modules}/database/itemtag/go.mod (100%) rename src/{lib => modules}/database/itemtag/go.sum (100%) rename src/{lib => modules}/database/itemtag/itemtag.go (100%) rename src/{lib => modules}/database/person/go.mod (100%) rename src/{lib => modules}/database/person/go.sum (100%) rename src/{lib => modules}/database/person/person.go (100%) rename src/{lib => modules}/database/role/go.mod (100%) rename src/{lib => modules}/database/role/go.sum (100%) rename src/{lib => modules}/database/role/role.go (100%) rename src/{lib => modules}/database/schematic/go.mod (100%) rename src/{lib => modules}/database/schematic/go.sum (100%) rename src/{lib => modules}/database/schematic/schematic.go (97%) create mode 100644 src/modules/database/tier/go.mod create mode 100644 src/modules/database/tier/go.sum rename src/{lib => modules}/database/tier/tier.go (93%) rename src/{lib => modules}/database/user/go.mod (100%) rename src/{lib/database/tier => modules/database/user}/go.sum (100%) rename src/{lib => modules}/database/user/user.go (100%) create mode 100644 test/fixtures/characters.json create mode 100644 test/fixtures/customizations.json create mode 100644 test/fixtures/functions.json create mode 100644 test/fixtures/functionset.json create mode 100644 test/fixtures/functiontags.json create mode 100644 test/fixtures/groups.json create mode 100644 test/fixtures/inventoryslots.json create mode 100644 test/fixtures/items.json create mode 100644 test/fixtures/itemtags.json create mode 100644 test/fixtures/persons.json create mode 100644 test/fixtures/roles.json create mode 100644 test/fixtures/schemas/character.schema.json create mode 100644 test/fixtures/schemas/customization.schema.json create mode 100644 test/fixtures/schemas/function.schema.json create mode 100644 test/fixtures/schemas/functionset.schema.json create mode 100644 test/fixtures/schemas/functiontag.schema.json create mode 100644 test/fixtures/schemas/group.schema.json create mode 100644 test/fixtures/schemas/inventoryslot.schema.json create mode 100644 test/fixtures/schemas/item.schema.json create mode 100644 test/fixtures/schemas/itemtag.schema.json create mode 100644 test/fixtures/schemas/person.schema.json create mode 100644 test/fixtures/schemas/role.schema.json create mode 100644 test/fixtures/schemas/schematic.schema.json create mode 100644 test/fixtures/schemas/tier.schema.json create mode 100644 test/fixtures/schemas/user.schema.json create mode 100644 test/fixtures/schematics.json create mode 100644 test/fixtures/tiers.json create mode 100644 test/unit/functionsettest/functionsettest.go create mode 100644 test/unit/functionsettest/go.mod rename {src/lib/database/user => test/unit/functionsettest}/go.sum (50%) create mode 100644 test/unit/tiertest/go.mod create mode 100644 test/unit/tiertest/go.sum create mode 100644 test/unit/tiertest/tiertest.go diff --git a/src/go.mod b/src/go.mod index 711035c..0178553 100644 --- a/src/go.mod +++ b/src/go.mod @@ -2,48 +2,46 @@ module gin-cpularp go 1.24.2 -replace example.com/database => ./lib/database +replace example.com/database => ./modules/database -replace example.com/database/user => ./lib/database/user +replace example.com/database/user => ./modules/database/user -replace example.com/database/character => ./lib/database/character +replace example.com/database/character => ./modules/database/character -replace example.com/database/functionset => ./lib/database/functionset +replace example.com/database/functionset => ./modules/database/functionset -replace example.com/database/inventoryslot => ./lib/database/inventoryslot +replace example.com/database/inventoryslot => ./modules/database/inventoryslot -replace example.com/database/customization => ./lib/database/customization +replace example.com/database/customization => ./modules/database/customization -replace example.com/database/item => ./lib/database/item +replace example.com/database/item => ./modules/database/item -replace example.com/database/itemtag => ./lib/database/itemtag +replace example.com/database/itemtag => ./modules/database/itemtag -replace example.com/database/person => ./lib/database/person +replace example.com/database/person => ./modules/database/person -replace example.com/database/role => ./lib/database/role +replace example.com/database/role => ./modules/database/role -replace example.com/database/schematic => ./lib/database/schematic +replace example.com/database/schematic => ./modules/database/schematic -replace example.com/database/tier => ./lib/database/tier +replace example.com/database/tier => ./modules/database/tier -replace example.com/database/group => ./lib/database/group +replace example.com/database/group => ./modules/database/group -replace example.com/database/function => ./lib/database/function +replace example.com/database/function => ./modules/database/function -replace example.com/database/functiontag => ./lib/database/functiontag +replace example.com/database/functiontag => ./modules/database/functiontag -replace example.com/config/server => ./lib/config/server +replace example.com/config/server => ./modules/config/server -replace example.com/auth/discord => ./lib/auth/discord +replace example.com/auth/discord => ./modules/auth/discord -replace example.com/api => ./lib/api +replace example.com/api => ./modules/api require ( example.com/api v0.0.0 example.com/auth/discord v0.0.0 example.com/database v0.0.0 - github.com/gin-contrib/cors v1.7.5 - github.com/gin-gonic/gin v1.10.0 ) require ( @@ -66,7 +64,9 @@ require ( github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gin-contrib/cors v1.7.5 // indirect github.com/gin-contrib/sse v1.0.0 // indirect + github.com/gin-gonic/gin v1.10.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.26.0 // indirect @@ -76,7 +76,6 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect - github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.22 // indirect diff --git a/src/go.sum b/src/go.sum index a375f2d..930a2df 100644 --- a/src/go.sum +++ b/src/go.sum @@ -6,7 +6,6 @@ github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFos github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/src/lib/database/tier/go.mod b/src/lib/database/tier/go.mod deleted file mode 100644 index 7a83be0..0000000 --- a/src/lib/database/tier/go.mod +++ /dev/null @@ -1,48 +0,0 @@ -module example.com/database/tier - -go 1.24.2 - -replace example.com/database/functionset => ../functionset - -replace example.com/database/function => ../function - -replace example.com/database/functiontag => ../functiontag - -require ( - example.com/database/function v0.0.0 // indirect - example.com/database/functionset v0.0.0 - example.com/database/functiontag v0.0.0 // indirect - gorm.io/gorm v1.25.12 // direct -) - -require ( - github.com/bytedance/sonic v1.11.6 // indirect - github.com/bytedance/sonic/loader v0.1.1 // indirect - github.com/cloudwego/base64x v0.1.4 // indirect - github.com/cloudwego/iasm v0.2.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/gin-gonic/gin v1.10.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.20.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect - github.com/leodido/go-urn v1.4.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect - golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - google.golang.org/protobuf v1.34.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/src/lib/api/api.go b/src/modules/api/api.go similarity index 100% rename from src/lib/api/api.go rename to src/modules/api/api.go diff --git a/src/lib/api/go.mod b/src/modules/api/go.mod similarity index 100% rename from src/lib/api/go.mod rename to src/modules/api/go.mod diff --git a/src/lib/api/go.sum b/src/modules/api/go.sum similarity index 100% rename from src/lib/api/go.sum rename to src/modules/api/go.sum diff --git a/src/lib/auth/discord/discord.go b/src/modules/auth/discord/discord.go similarity index 100% rename from src/lib/auth/discord/discord.go rename to src/modules/auth/discord/discord.go diff --git a/src/lib/auth/discord/go.mod b/src/modules/auth/discord/go.mod similarity index 100% rename from src/lib/auth/discord/go.mod rename to src/modules/auth/discord/go.mod diff --git a/src/lib/auth/discord/go.sum b/src/modules/auth/discord/go.sum similarity index 100% rename from src/lib/auth/discord/go.sum rename to src/modules/auth/discord/go.sum diff --git a/src/lib/config/server/go.mod b/src/modules/config/server/go.mod similarity index 100% rename from src/lib/config/server/go.mod rename to src/modules/config/server/go.mod diff --git a/src/lib/config/server/go.sum b/src/modules/config/server/go.sum similarity index 100% rename from src/lib/config/server/go.sum rename to src/modules/config/server/go.sum diff --git a/src/lib/config/server/server.go b/src/modules/config/server/server.go similarity index 100% rename from src/lib/config/server/server.go rename to src/modules/config/server/server.go diff --git a/src/lib/database/character/character.go b/src/modules/database/character/character.go similarity index 100% rename from src/lib/database/character/character.go rename to src/modules/database/character/character.go diff --git a/src/lib/database/character/go.mod b/src/modules/database/character/go.mod similarity index 100% rename from src/lib/database/character/go.mod rename to src/modules/database/character/go.mod diff --git a/src/lib/database/character/go.sum b/src/modules/database/character/go.sum similarity index 100% rename from src/lib/database/character/go.sum rename to src/modules/database/character/go.sum diff --git a/src/lib/database/customization/customization.go b/src/modules/database/customization/customization.go similarity index 97% rename from src/lib/database/customization/customization.go rename to src/modules/database/customization/customization.go index 0b553df..37dc2ca 100644 --- a/src/lib/database/customization/customization.go +++ b/src/modules/database/customization/customization.go @@ -120,7 +120,10 @@ func Create(db *gorm.DB, params CustomizationParams) error { var err error var newFunctions []function.Function if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } var newTags []itemtag.ItemTag if len(params.Tags) > 0 { @@ -161,7 +164,10 @@ func Update(db *gorm.DB, params CustomizationParams) error { var err error var newFunctions []function.Function if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } var newTags []itemtag.ItemTag if len(params.Tags) > 0 { diff --git a/src/lib/database/customization/go.mod b/src/modules/database/customization/go.mod similarity index 100% rename from src/lib/database/customization/go.mod rename to src/modules/database/customization/go.mod diff --git a/src/lib/database/customization/go.sum b/src/modules/database/customization/go.sum similarity index 100% rename from src/lib/database/customization/go.sum rename to src/modules/database/customization/go.sum diff --git a/src/lib/database/database.go b/src/modules/database/database.go similarity index 100% rename from src/lib/database/database.go rename to src/modules/database/database.go diff --git a/src/lib/database/function/function.go b/src/modules/database/function/function.go similarity index 87% rename from src/lib/database/function/function.go rename to src/modules/database/function/function.go index c9fca72..8ca224b 100644 --- a/src/lib/database/function/function.go +++ b/src/modules/database/function/function.go @@ -57,9 +57,13 @@ func (function *Function) getAssociations(db *gorm.DB) { db.Model(&function).Association("Requirements").Find(&function.Requirements) } -func (function *Function) get(db *gorm.DB, inputFunction uint) { - db.Where("id = ?", inputFunction).Take(&function) +func (function *Function) get(db *gorm.DB, inputFunction uint) error { + result := db.Model(&Function{}).Where("id = ?", inputFunction).Take(&function) + if result.Error != nil { + return result.Error + } function.getAssociations(db) + return nil } func (function Function) update(db *gorm.DB) error { @@ -108,7 +112,10 @@ func Create(db *gorm.DB, params FunctionParams) error { } var newRequirements []Function if len(params.Requirements) > 0 { - newRequirements = *Get(db, params.Requirements) + newRequirements, err = Get(db, params.Requirements) + if err != nil { + return err + } } return Function{ Name: params.Name, @@ -117,17 +124,20 @@ func Create(db *gorm.DB, params FunctionParams) error { }.create(db) } -func Get(db *gorm.DB, inputFunctions []uint) *[]Function { +func Get(db *gorm.DB, inputFunctions []uint) ([]Function, error) { var outputFunctions []Function if len(inputFunctions) < 1 { db.Model(&Function{}).Select("id").Find(&inputFunctions) } for _, inputFunction := range inputFunctions { var outputFunction Function - outputFunction.get(db, inputFunction) + err := outputFunction.get(db, inputFunction) + if err != nil { + return nil, err + } outputFunctions = append(outputFunctions, outputFunction) } - return &outputFunctions + return outputFunctions, nil } func Update(db *gorm.DB, params FunctionParams) error { @@ -141,7 +151,10 @@ func Update(db *gorm.DB, params FunctionParams) error { } var newRequirements []Function if len(params.Requirements) > 0 { - newRequirements = *Get(db, params.Requirements) + newRequirements, err = Get(db, params.Requirements) + if err != nil { + return err + } } return Function{ Model: gorm.Model{ID: params.IDArray[0]}, @@ -173,17 +186,17 @@ func Delete(db *gorm.DB, inputFunctions []uint) error { return nil } -func HandleRequest(method string, db *gorm.DB, IDUintArray *[]uint, body *[]byte) (*[]Function, error) { +func HandleRequest(method string, db *gorm.DB, IDUintArray *[]uint, body *[]byte) ([]Function, error) { var err error var params FunctionParams err = params.parse(IDUintArray, body) if err != nil { return nil, err } - var result *[]Function + var result []Function switch method { case "GET": - result = Get(db, params.IDArray) + result, err = Get(db, params.IDArray) case "POST": err = Create(db, params) case "PUT": diff --git a/src/lib/database/function/go.mod b/src/modules/database/function/go.mod similarity index 100% rename from src/lib/database/function/go.mod rename to src/modules/database/function/go.mod diff --git a/src/lib/database/function/go.sum b/src/modules/database/function/go.sum similarity index 100% rename from src/lib/database/function/go.sum rename to src/modules/database/function/go.sum diff --git a/src/lib/database/functionset/functionset.go b/src/modules/database/functionset/functionset.go similarity index 77% rename from src/lib/database/functionset/functionset.go rename to src/modules/database/functionset/functionset.go index d01982b..84b08fe 100644 --- a/src/lib/database/functionset/functionset.go +++ b/src/modules/database/functionset/functionset.go @@ -46,9 +46,13 @@ func (functionSet *FunctionSet) getAssociations(db *gorm.DB) { db.Model(&functionSet).Association("Functions").Find(&functionSet.Functions) } -func (functionSet *FunctionSet) get(db *gorm.DB, inputFunctionSet uint) { - db.Where("id = ?", inputFunctionSet).Take(&functionSet) +func (functionSet *FunctionSet) get(db *gorm.DB, inputFunctionSet uint) error { + result := db.Model(&FunctionSet{}).Where("id = ?", inputFunctionSet).Take(&functionSet) + if result.Error != nil { + return result.Error + } functionSet.getAssociations(db) + return nil } func (functionSet FunctionSet) update(db *gorm.DB) error { @@ -59,9 +63,9 @@ func (functionSet FunctionSet) update(db *gorm.DB) error { return result.Error } // Set the associated values by grabbing them from the database - tagsError := db.Model(&originalFunctionSet).Association("Functions").Replace(&functionSet.Functions) - if tagsError != nil { - return tagsError + functionsError := db.Model(&originalFunctionSet).Association("Functions").Replace(&functionSet.Functions) + if functionsError != nil { + return functionsError } db.Save(&originalFunctionSet) return nil @@ -77,33 +81,45 @@ func (functionSet FunctionSet) delete(db *gorm.DB) error { func Create(db *gorm.DB, params FunctionSetParams) error { var newFunctions []function.Function + var err error if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } return FunctionSet{ Functions: newFunctions, }.create(db) } -func Get(db *gorm.DB, inputFunctionSets []uint) *[]FunctionSet { +func Get(db *gorm.DB, inputFunctionSets []uint) ([]FunctionSet, error) { var outputFunctionSets []FunctionSet if len(inputFunctionSets) < 1 { db.Model(&FunctionSet{}).Select("id").Find(&inputFunctionSets) } for _, inputFunctionSet := range inputFunctionSets { var outputFunctionSet FunctionSet - outputFunctionSet.get(db, inputFunctionSet) + err := outputFunctionSet.get(db, inputFunctionSet) + if err != nil { + return nil, err + } outputFunctionSets = append(outputFunctionSets, outputFunctionSet) } - return &outputFunctionSets + return outputFunctionSets, nil } func Update(db *gorm.DB, params FunctionSetParams) error { var newFunctions []function.Function + var err error if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } return FunctionSet{ + Model: gorm.Model{ID: params.IDArray[0]}, Functions: newFunctions, }.update(db) } @@ -121,8 +137,8 @@ func Delete(db *gorm.DB, inputFunctionSets []uint) error { functionSet.get(db, inputFunctionSet) functionSets = append(functionSets, functionSet) } - for _, function := range functionSets { - err := function.delete(db) + for _, functionSet := range functionSets { + err := functionSet.delete(db) if err != nil { return err } @@ -130,17 +146,17 @@ func Delete(db *gorm.DB, inputFunctionSets []uint) error { return nil } -func HandleRequest(method string, db *gorm.DB, IDUintArray *[]uint, body *[]byte) (*[]FunctionSet, error) { +func HandleRequest(method string, db *gorm.DB, IDUintArray *[]uint, body *[]byte) ([]FunctionSet, error) { var err error var params FunctionSetParams err = params.parse(IDUintArray, body) if err != nil { return nil, err } - var result *[]FunctionSet + var result []FunctionSet switch method { case "GET": - result = Get(db, params.IDArray) + result, err = Get(db, params.IDArray) case "POST": err = Create(db, params) case "PUT": diff --git a/src/lib/database/functionset/go.mod b/src/modules/database/functionset/go.mod similarity index 100% rename from src/lib/database/functionset/go.mod rename to src/modules/database/functionset/go.mod diff --git a/src/lib/database/functionset/go.sum b/src/modules/database/functionset/go.sum similarity index 100% rename from src/lib/database/functionset/go.sum rename to src/modules/database/functionset/go.sum diff --git a/src/lib/database/functiontag/functiontag.go b/src/modules/database/functiontag/functiontag.go similarity index 100% rename from src/lib/database/functiontag/functiontag.go rename to src/modules/database/functiontag/functiontag.go diff --git a/src/lib/database/functiontag/go.mod b/src/modules/database/functiontag/go.mod similarity index 100% rename from src/lib/database/functiontag/go.mod rename to src/modules/database/functiontag/go.mod diff --git a/src/lib/database/functiontag/go.sum b/src/modules/database/functiontag/go.sum similarity index 100% rename from src/lib/database/functiontag/go.sum rename to src/modules/database/functiontag/go.sum diff --git a/src/lib/database/go.mod b/src/modules/database/go.mod similarity index 100% rename from src/lib/database/go.mod rename to src/modules/database/go.mod diff --git a/src/lib/database/go.sum b/src/modules/database/go.sum similarity index 100% rename from src/lib/database/go.sum rename to src/modules/database/go.sum diff --git a/src/lib/database/group/go.mod b/src/modules/database/group/go.mod similarity index 100% rename from src/lib/database/group/go.mod rename to src/modules/database/group/go.mod diff --git a/src/lib/database/group/go.sum b/src/modules/database/group/go.sum similarity index 100% rename from src/lib/database/group/go.sum rename to src/modules/database/group/go.sum diff --git a/src/lib/database/group/group.go b/src/modules/database/group/group.go similarity index 100% rename from src/lib/database/group/group.go rename to src/modules/database/group/group.go diff --git a/src/lib/database/inventoryslot/go.mod b/src/modules/database/inventoryslot/go.mod similarity index 100% rename from src/lib/database/inventoryslot/go.mod rename to src/modules/database/inventoryslot/go.mod diff --git a/src/lib/database/inventoryslot/go.sum b/src/modules/database/inventoryslot/go.sum similarity index 100% rename from src/lib/database/inventoryslot/go.sum rename to src/modules/database/inventoryslot/go.sum diff --git a/src/lib/database/inventoryslot/inventoryslot.go b/src/modules/database/inventoryslot/inventoryslot.go similarity index 100% rename from src/lib/database/inventoryslot/inventoryslot.go rename to src/modules/database/inventoryslot/inventoryslot.go diff --git a/src/lib/database/item/go.mod b/src/modules/database/item/go.mod similarity index 100% rename from src/lib/database/item/go.mod rename to src/modules/database/item/go.mod diff --git a/src/lib/database/item/go.sum b/src/modules/database/item/go.sum similarity index 100% rename from src/lib/database/item/go.sum rename to src/modules/database/item/go.sum diff --git a/src/lib/database/item/item.go b/src/modules/database/item/item.go similarity index 97% rename from src/lib/database/item/item.go rename to src/modules/database/item/item.go index f4f7152..46d4cdb 100644 --- a/src/lib/database/item/item.go +++ b/src/modules/database/item/item.go @@ -132,7 +132,10 @@ func Create(db *gorm.DB, params ItemParams) error { var err error var newFunctions []function.Function if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } var newTags []itemtag.ItemTag if len(params.Tags) > 0 { @@ -178,7 +181,10 @@ func Update(db *gorm.DB, params ItemParams) error { var err error var newFunctions []function.Function if len(params.Functions) > 0 { - newFunctions = *function.Get(db, params.Functions) + newFunctions, err = function.Get(db, params.Functions) + if err != nil { + return err + } } var newTags []itemtag.ItemTag if len(params.Tags) > 0 { diff --git a/src/lib/database/itemtag/go.mod b/src/modules/database/itemtag/go.mod similarity index 100% rename from src/lib/database/itemtag/go.mod rename to src/modules/database/itemtag/go.mod diff --git a/src/lib/database/itemtag/go.sum b/src/modules/database/itemtag/go.sum similarity index 100% rename from src/lib/database/itemtag/go.sum rename to src/modules/database/itemtag/go.sum diff --git a/src/lib/database/itemtag/itemtag.go b/src/modules/database/itemtag/itemtag.go similarity index 100% rename from src/lib/database/itemtag/itemtag.go rename to src/modules/database/itemtag/itemtag.go diff --git a/src/lib/database/person/go.mod b/src/modules/database/person/go.mod similarity index 100% rename from src/lib/database/person/go.mod rename to src/modules/database/person/go.mod diff --git a/src/lib/database/person/go.sum b/src/modules/database/person/go.sum similarity index 100% rename from src/lib/database/person/go.sum rename to src/modules/database/person/go.sum diff --git a/src/lib/database/person/person.go b/src/modules/database/person/person.go similarity index 100% rename from src/lib/database/person/person.go rename to src/modules/database/person/person.go diff --git a/src/lib/database/role/go.mod b/src/modules/database/role/go.mod similarity index 100% rename from src/lib/database/role/go.mod rename to src/modules/database/role/go.mod diff --git a/src/lib/database/role/go.sum b/src/modules/database/role/go.sum similarity index 100% rename from src/lib/database/role/go.sum rename to src/modules/database/role/go.sum diff --git a/src/lib/database/role/role.go b/src/modules/database/role/role.go similarity index 100% rename from src/lib/database/role/role.go rename to src/modules/database/role/role.go diff --git a/src/lib/database/schematic/go.mod b/src/modules/database/schematic/go.mod similarity index 100% rename from src/lib/database/schematic/go.mod rename to src/modules/database/schematic/go.mod diff --git a/src/lib/database/schematic/go.sum b/src/modules/database/schematic/go.sum similarity index 100% rename from src/lib/database/schematic/go.sum rename to src/modules/database/schematic/go.sum diff --git a/src/lib/database/schematic/schematic.go b/src/modules/database/schematic/schematic.go similarity index 97% rename from src/lib/database/schematic/schematic.go rename to src/modules/database/schematic/schematic.go index d1e5c6c..c0a4b59 100644 --- a/src/lib/database/schematic/schematic.go +++ b/src/modules/database/schematic/schematic.go @@ -126,7 +126,10 @@ func Create(db *gorm.DB, params SchematicParams) error { } var newRequirements []function.Function if len(params.Requirements) > 0 { - newRequirements = *function.Get(db, params.Requirements) + newRequirements, err = function.Get(db, params.Requirements) + if err != nil { + return err + } } resultArray := *inventoryslot.Get(db, []uint{params.Result}) newResult := resultArray[0] @@ -172,7 +175,10 @@ func Update(db *gorm.DB, params SchematicParams) error { } var newRequirements []function.Function if len(params.Requirements) > 0 { - newRequirements = *function.Get(db, params.Requirements) + newRequirements, err = function.Get(db, params.Requirements) + if err != nil { + return err + } } resultArray := *inventoryslot.Get(db, []uint{params.Result}) newResult := resultArray[0] diff --git a/src/modules/database/tier/go.mod b/src/modules/database/tier/go.mod new file mode 100644 index 0000000..8ba0d38 --- /dev/null +++ b/src/modules/database/tier/go.mod @@ -0,0 +1,22 @@ +module example.com/database/tier + +go 1.24.2 + +replace example.com/database/functionset => ../functionset + +replace example.com/database/function => ../function + +replace example.com/database/functiontag => ../functiontag + +require ( + example.com/database/function v0.0.0 // indirect + example.com/database/functionset v0.0.0 + example.com/database/functiontag v0.0.0 // indirect + gorm.io/gorm v1.25.12 // direct +) + +require ( + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + golang.org/x/text v0.15.0 // indirect +) diff --git a/src/modules/database/tier/go.sum b/src/modules/database/tier/go.sum new file mode 100644 index 0000000..6afc972 --- /dev/null +++ b/src/modules/database/tier/go.sum @@ -0,0 +1,8 @@ +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/src/lib/database/tier/tier.go b/src/modules/database/tier/tier.go similarity index 93% rename from src/lib/database/tier/tier.go rename to src/modules/database/tier/tier.go index e52085a..c5b1674 100644 --- a/src/lib/database/tier/tier.go +++ b/src/modules/database/tier/tier.go @@ -77,8 +77,12 @@ func (tier Tier) delete(db *gorm.DB) error { func Create(db *gorm.DB, params TierParams) error { var newFunctionSets []functionset.FunctionSet + var err error if len(params.FunctionSets) > 0 { - newFunctionSets = *functionset.Get(db, params.FunctionSets) + newFunctionSets, err = functionset.Get(db, params.FunctionSets) + if err != nil { + return err + } } return Tier{ FunctionSets: newFunctionSets, @@ -100,8 +104,12 @@ func Get(db *gorm.DB, inputTiers []uint) *[]Tier { func Update(db *gorm.DB, params TierParams) error { var newFunctionSets []functionset.FunctionSet + var err error if len(params.FunctionSets) > 0 { - newFunctionSets = *functionset.Get(db, params.FunctionSets) + newFunctionSets, err = functionset.Get(db, params.FunctionSets) + if err != nil { + return err + } } return Tier{ Model: gorm.Model{ID: params.IDArray[0]}, diff --git a/src/lib/database/user/go.mod b/src/modules/database/user/go.mod similarity index 100% rename from src/lib/database/user/go.mod rename to src/modules/database/user/go.mod diff --git a/src/lib/database/tier/go.sum b/src/modules/database/user/go.sum similarity index 100% rename from src/lib/database/tier/go.sum rename to src/modules/database/user/go.sum diff --git a/src/lib/database/user/user.go b/src/modules/database/user/user.go similarity index 100% rename from src/lib/database/user/user.go rename to src/modules/database/user/user.go diff --git a/test/api_test.go b/test/api_test.go index 0077d57..bfa7e43 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -1,96 +1,18 @@ package main import ( - "os" "testing" - character "example.com/database/character" - customization "example.com/database/customization" - function "example.com/database/function" - functionset "example.com/database/functionset" - functiontag "example.com/database/functiontag" - group "example.com/database/group" - inventoryslot "example.com/database/inventoryslot" - item "example.com/database/item" - itemtag "example.com/database/itemtag" - person "example.com/database/person" - role "example.com/database/role" - schematic "example.com/database/schematic" - tier "example.com/database/tier" - user "example.com/database/user" + functionsettest "example.com/unit/functionsettest" functiontagtest "example.com/unit/functiontagtest" functiontest "example.com/unit/functiontest" grouptest "example.com/unit/grouptest" persontest "example.com/unit/persontest" + tiertest "example.com/unit/tiertest" - "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" ) -type testCharacter struct { - Result []character.Character `json:"result"` -} - -type testCustomization struct { - Result []customization.Customization `json:"result"` -} - -type testFunction struct { - Result []function.Function `json:"result"` -} - -type testFunctionSet struct { - Result []functionset.FunctionSet `json:"result"` -} - -type testFunctionTag struct { - Result []functiontag.FunctionTag `json:"result"` -} - -type testInventorySlot struct { - Result []inventoryslot.InventorySlot `json:"result"` -} - -type testItem struct { - Result []item.Item `json:"result"` -} - -type testItemTag struct { - Result []itemtag.ItemTag `json:"result"` -} - -type testPerson struct { - Result []person.Person `json:"result"` -} - -type testRole struct { - Result []role.Role `json:"result"` -} - -type testSchematic struct { - Result []schematic.Schematic `json:"result"` -} - -type testTier struct { - Result []tier.Tier `json:"result"` -} - -type testUser struct { - Result []user.User `json:"result"` -} - -type apiTestSuite struct { - suite.Suite - globalAuthHeader string - router *gin.Engine - group group.Group - groupJSON []byte -} - -func (s *apiTestSuite) TearDownTestSuite() { - os.Remove("db/main.db") -} - func TestSuite01Group(t *testing.T) { var groupSuite grouptest.GroupTestSuite groupSuite.SetupTestSuite() @@ -118,3 +40,17 @@ func TestSuite04Function(t *testing.T) { suite.Run(t, &functionSuite) functionSuite.TearDownTestSuite() } + +func TestSuite05FunctionSet(t *testing.T) { + var functionSetSuite functionsettest.FunctionSetTestSuite + functionSetSuite.SetupTestSuite() + suite.Run(t, &functionSetSuite) + functionSetSuite.TearDownTestSuite() +} + +func TestSuite06Tier(t *testing.T) { + var tierSuite tiertest.TierTestSuite + tierSuite.SetupTestSuite() + suite.Run(t, &tierSuite) + tierSuite.TearDownTestSuite() +} diff --git a/test/fixtures/characters.json b/test/fixtures/characters.json new file mode 100644 index 0000000..9d81b06 --- /dev/null +++ b/test/fixtures/characters.json @@ -0,0 +1,88 @@ +{ + "$schema": "./schemas/character.schema.json", + "characters": [ + { + "function_sets": [], + "id": 1, + "inventory": [], + "name": "test1", + "owners": [], + "roles": [] + }, + { + "function_sets": [ + { + "id": 1, + "functions": [ + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ] + } + ] + } + ], + "id": 2, + "inventory": [], + "name": "test2", + "owners": [], + "roles": [] + }, + { + "function_sets": [], + "id": 3, + "inventory": [], + "name": "test3", + "owners": [], + "roles": [] + } + ], + "character_update": { + "id": 1, + "function_sets": [], + "inventory": [], + "name": "another_test", + "owners": [], + "roles": [] + } +} diff --git a/test/fixtures/customizations.json b/test/fixtures/customizations.json new file mode 100644 index 0000000..8b6699d --- /dev/null +++ b/test/fixtures/customizations.json @@ -0,0 +1,142 @@ +{ + "$schema": "./schemas/customization.schema.json", + "customizations": [ + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 1, + "name": "test1", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Something else", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Out of dumb jokes", + "rules_description": "Sorry", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [] + }, + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "customization_update": { + "flavor_text": "", + "functions": [ + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 1, + "name": "", + "physrep_requirements": "", + "rules_description": "", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [ + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } +} diff --git a/test/fixtures/functions.json b/test/fixtures/functions.json new file mode 100644 index 0000000..547e62d --- /dev/null +++ b/test/fixtures/functions.json @@ -0,0 +1,79 @@ +{ + "$schema": "./schemas/function.schema.json", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "function_update": { + "id": 1, + "name": "another_test", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "requirements": [ + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ] + } +} diff --git a/test/fixtures/functionset.json b/test/fixtures/functionset.json new file mode 100644 index 0000000..e05f793 --- /dev/null +++ b/test/fixtures/functionset.json @@ -0,0 +1,66 @@ +{ + "$schema": "./schemas/functionset.schema.json", + "function_sets": [ + { + "id": 1, + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "function_set_update": { + "id": 1, + "functions": [ + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ] + } + ] + } +} diff --git a/test/fixtures/functiontags.json b/test/fixtures/functiontags.json new file mode 100644 index 0000000..eca1c04 --- /dev/null +++ b/test/fixtures/functiontags.json @@ -0,0 +1,21 @@ +{ + "$schema": "./schemas/functiontag.schema.json", + "function_tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "function_tag_update": { + "id": 1, + "name": "another_test" + } +} diff --git a/test/fixtures/groups.json b/test/fixtures/groups.json new file mode 100644 index 0000000..66cc561 --- /dev/null +++ b/test/fixtures/groups.json @@ -0,0 +1,21 @@ +{ + "$schema": "./schemas/group.schema.json", + "groups": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "group_update": { + "id": 1, + "name": "another_test" + } +} diff --git a/test/fixtures/inventoryslots.json b/test/fixtures/inventoryslots.json new file mode 100644 index 0000000..50d3b0f --- /dev/null +++ b/test/fixtures/inventoryslots.json @@ -0,0 +1,280 @@ +{ + "$schema": "./schemas/inventoryslot.schema.json", + "inventory_slots": [ + { + "id": 1, + "item": { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 1 + }, + { + "id": 2, + "item": { + "customizations": [ + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + } + ], + "flavor_text": "Silver currency", + "functions": [], + "id": 2, + "name": "Silver", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 2 + }, + { + "id": 3, + "item": { + "customizations": [], + "flavor_text": "Gold currency", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 3, + "name": "Gold", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 3 + } + ], + "inventory_slot_update": { + "id": 1, + "item": { + "customizations": [ + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 1, + "name": "test1", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Something else", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Out of dumb jokes", + "rules_description": "Sorry", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [] + }, + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "flavor_text": "Free Luigi", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 1, + "name": "UBI", + "physrep_requirements": "Socialism", + "rules_description": "There is no ethical consumption under captialism", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + }, + "quantity": 50 + } +} diff --git a/test/fixtures/items.json b/test/fixtures/items.json new file mode 100644 index 0000000..9609b61 --- /dev/null +++ b/test/fixtures/items.json @@ -0,0 +1,280 @@ +{ + "$schema": "./schemas/item.schema.json", + "items": [ + { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + { + "customizations": [ + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + } + ], + "flavor_text": "Silver currency", + "functions": [], + "id": 2, + "name": "Silver", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + { + "customizations": [], + "flavor_text": "Gold currency", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 3, + "name": "Gold", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + { + "customizations": [], + "flavor_text": "Platinum currency", + "functions": [], + "id": 4, + "name": "Platinm", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [ + { + "id": 3, + "name": "test3" + } + ] + } + ], + "item_update": { + "customizations": [ + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 1, + "name": "test1", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + }, + { + "flavor_text": "Something else", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Out of dumb jokes", + "rules_description": "Sorry", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [] + }, + { + "flavor_text": "This is some flavor text.", + "functions": [], + "id": 3, + "name": "test3", + "physrep_requirements": "Git gud", + "rules_description": "Judge they're stacking", + "tags": [], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "flavor_text": "Free Luigi", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 1, + "name": "UBI", + "physrep_requirements": "Socialism", + "rules_description": "There is no ethical consumption under captialism", + "tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } +} diff --git a/test/fixtures/itemtags.json b/test/fixtures/itemtags.json new file mode 100644 index 0000000..4fe5b5c --- /dev/null +++ b/test/fixtures/itemtags.json @@ -0,0 +1,21 @@ +{ + "$schema": "./schemas/itemtag.schema.json", + "item_tags": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ], + "item_tag_update": { + "id": 1, + "name": "another_test" + } +} diff --git a/test/fixtures/persons.json b/test/fixtures/persons.json new file mode 100644 index 0000000..fbb5b1c --- /dev/null +++ b/test/fixtures/persons.json @@ -0,0 +1,52 @@ +{ + "$schema": "./schemas/person.schema.json", + "persons": [ + { + "id": 2, + "name": "test2", + "groups": [] + }, + { + "id": 3, + "name": "test3", + "groups": [ + { + "id": 1, + "name": "test1" + } + ] + }, + { + "id": 4, + "name": "test4", + "groups": [ + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "person_update": { + "id": 2, + "name": "another_test", + "groups": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } +} diff --git a/test/fixtures/roles.json b/test/fixtures/roles.json new file mode 100644 index 0000000..1ec9d55 --- /dev/null +++ b/test/fixtures/roles.json @@ -0,0 +1,104 @@ +{ + "$schema": "./schemas/role.schema.json", + "roles": [ + { + "id": 1, + "name": "test1", + "tiers": [], + "visibility": [] + }, + { + "id": 2, + "name": "test2", + "tiers": [ + { + "id": 1, + "function_sets": [] + } + ], + "visibility": [] + }, + { + "id": 3, + "name": "test3", + "tiers": [], + "visibility": [ + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "role_update": { + "id": 1, + "name": "another_test", + "tiers": [ + { + "id": 1, + "function_sets": [] + }, + { + "id": 2, + "function_sets": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + }, + { + "id": 2, + "name": "function2", + "requirements": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + } + ], + "tags": [] + }, + { + "id": 3, + "name": "function3", + "requirements": [], + "tags": [ + { + "id": 1, + "name": "tag1" + }, + { + "id": 2, + "name": "tag2" + }, + { + "id": 3, + "name": "tag3" + } + ] + } + ] + } + ], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } +} diff --git a/test/fixtures/schemas/character.schema.json b/test/fixtures/schemas/character.schema.json new file mode 100644 index 0000000..5e5d993 --- /dev/null +++ b/test/fixtures/schemas/character.schema.json @@ -0,0 +1,66 @@ +{ + "title": "Character", + "description": "Describes a list of characters", + "type": "object", + "properties": { + "characters": { + "description": "A list of characters", + "type": "array", + "items": { + "description": "A character object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this character", + "type": "integer" + }, + "name": { + "description": "A name associated with this character", + "type": "string" + }, + "owners": { + "description": "A list of persons that own this character", + "type": "array", + "items": { + "$ref": "./person.schema.json#/properties/persons/items" + } + }, + "roles": { + "description": "A list of roles associated with this character", + "type": "array", + "items": { + "$ref": "./role.schema.json#/properties/roles/items" + } + }, + "function_sets": { + "description": "A list of function sets associated with this character", + "type": "array", + "items": { + "$ref": "./functionset.schema.json#/properties/function_sets/items" + } + }, + "inventory": { + "description": "The inventory associated with this character (a list of inventory slot objects)", + "type": "array", + "items": { + "$ref": "./inventoryslot.schema.json#/properties/inventory_slots/items" + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "name", + "owners", + "roles", + "function_sets", + "inventory" + ] + } + }, + "character_update": { + "$ref": "#/properties/characters/items" + } + }, + "required": ["characters", "character_update"] +} diff --git a/test/fixtures/schemas/customization.schema.json b/test/fixtures/schemas/customization.schema.json new file mode 100644 index 0000000..d3dfd86 --- /dev/null +++ b/test/fixtures/schemas/customization.schema.json @@ -0,0 +1,73 @@ +{ + "title": "Customization", + "description": "Describes a list of customizations", + "type": "object", + "properties": { + "customizations": { + "description": "A list of customizations", + "type": "array", + "items": { + "description": "A customization object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this customization", + "type": "integer" + }, + "name": { + "description": "The name associated with this customization", + "type": "string" + }, + "functions": { + "description": "A list of functions associated with this customization", + "type": "array", + "items": { + "$ref": "function.schema.json#/properties/functions/items" + } + }, + "flavor_text": { + "description": "Flavor text associated with this customization", + "type": "string" + }, + "rules_description": { + "description": "Rules description associated with this customization", + "type": "string" + }, + "physrep_requirements": { + "description": "The physrep requirements associated with this customization", + "type": "string" + }, + "tags": { + "description": "A list of function tags associated with this customization", + "type": "array", + "items": { + "$ref": "functiontag.schema.json#/properties/function_tags/items" + } + }, + "visibility": { + "description": "A list of groups associated with this customization", + "type": "array", + "items": { + "$ref": "group.schema.json#/properties/groups/items" + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "name", + "functions", + "flavor_text", + "rules_description", + "physrep_requirements", + "tags", + "visibility" + ] + } + }, + "customization_update": { + "$ref": "#/properties/customizations/items" + } + }, + "required": ["customizations", "customization_update"] +} diff --git a/test/fixtures/schemas/function.schema.json b/test/fixtures/schemas/function.schema.json new file mode 100644 index 0000000..b955f6a --- /dev/null +++ b/test/fixtures/schemas/function.schema.json @@ -0,0 +1,45 @@ +{ + "title": "Function", + "description": "Describes a function", + "type": "object", + "properties": { + "functions": { + "description": "A list of functions", + "type": "array", + "items": { + "description": "A function object", + "type": "object", + "properties": { + "id": { + "description": "An integer representing the function tag id", + "type": "integer" + }, + "name": { + "description": "The name for a specific function tag", + "type": "string" + }, + "tags": { + "description": "A list of tags associated with this function", + "type": "array", + "items": { + "$ref": "functiontag.schema.json#/properties/function_tags/items" + } + }, + "requirements": { + "description": "A list of functions required for this function", + "type": "array", + "items": { + "$ref": "#/properties/functions/items" + } + } + }, + "required": ["id", "name", "tags", "requirements"], + "additionalProperties": false + } + }, + "function_update": { + "$ref": "#/properties/functions/items" + } + }, + "required": ["functions", "function_update"] +} diff --git a/test/fixtures/schemas/functionset.schema.json b/test/fixtures/schemas/functionset.schema.json new file mode 100644 index 0000000..696d6fe --- /dev/null +++ b/test/fixtures/schemas/functionset.schema.json @@ -0,0 +1,34 @@ +{ + "title": "Function Set", + "description": "Describes a set of functions", + "type": "object", + "properties": { + "function_sets": { + "description": "A list of function sets", + "type": "array", + "items": { + "description": "A function set object", + "type": "object", + "properties": { + "id": { + "description": "An integer representing the function tag id", + "type": "integer" + }, + "functions": { + "description": "A list of functions associated with this set", + "type": "array", + "items": { + "$ref": "function.schema.json#/properties/functions/items" + } + } + }, + "required": ["id", "functions"], + "additionalProperties": false + } + }, + "function_set_update": { + "$ref": "functionset.schema.json#/properties/function_sets/items" + } + }, + "required": ["function_sets", "function_set_update"] +} diff --git a/test/fixtures/schemas/functiontag.schema.json b/test/fixtures/schemas/functiontag.schema.json new file mode 100644 index 0000000..cd07559 --- /dev/null +++ b/test/fixtures/schemas/functiontag.schema.json @@ -0,0 +1,31 @@ +{ + "title": "Function Tag", + "description": "Describes a tag that functions can be assigned for categorization", + "type": "object", + "properties": { + "function_tags": { + "description": "A list of function tags", + "type": "array", + "items": { + "description": "A function tag object", + "type": "object", + "properties": { + "id": { + "description": "An integer representing the function tag id", + "type": "integer" + }, + "name": { + "description": "The name for a specific function tag", + "type": "string" + } + }, + "required": ["id", "name"], + "additionalProperties": false + } + }, + "function_tag_update": { + "$ref": "#/properties/function_tags/items" + } + }, + "required": ["function_tags", "function_tag_update"] +} diff --git a/test/fixtures/schemas/group.schema.json b/test/fixtures/schemas/group.schema.json new file mode 100644 index 0000000..e57f692 --- /dev/null +++ b/test/fixtures/schemas/group.schema.json @@ -0,0 +1,31 @@ +{ + "title": "Group", + "description": "Describes a group that users can be assigned to for access control", + "type": "object", + "properties": { + "groups": { + "description": "A list of groups", + "type": "array", + "items": { + "description": "A group object", + "type": "object", + "properties": { + "id": { + "description": "An integer representing the group id", + "type": "integer" + }, + "name": { + "description": "The name for a specific group", + "type": "string" + } + }, + "required": ["id", "name"], + "additionalProperties": false + } + }, + "group_update": { + "$ref": "group.schema.json#/properties/groups/items" + } + }, + "required": ["groups", "group_update"] +} diff --git a/test/fixtures/schemas/inventoryslot.schema.json b/test/fixtures/schemas/inventoryslot.schema.json new file mode 100644 index 0000000..1f5f371 --- /dev/null +++ b/test/fixtures/schemas/inventoryslot.schema.json @@ -0,0 +1,34 @@ +{ + "title": "Inventory Slot", + "description": "Describes a list of inventory slots", + "type": "object", + "properties": { + "inventory_slots": { + "description": "A list of inventory slots", + "type": "array", + "items": { + "description": "A inventory slot object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this customization", + "type": "integer" + }, + "item": { + "$ref": "./item.schema.json#/properties/items/items" + }, + "quantity": { + "description": "How much of this item", + "type": "integer" + } + }, + "additionalProperties": false, + "required": ["id", "item", "quantity"] + } + }, + "inventory_slot_update": { + "$ref": "#/properties/inventory_slots/items" + } + }, + "required": ["inventory_slots", "inventory_slot_update"] +} diff --git a/test/fixtures/schemas/item.schema.json b/test/fixtures/schemas/item.schema.json new file mode 100644 index 0000000..50bad08 --- /dev/null +++ b/test/fixtures/schemas/item.schema.json @@ -0,0 +1,81 @@ +{ + "title": "Item", + "description": "Describes a list of items", + "type": "object", + "properties": { + "items": { + "description": "A list of items", + "type": "array", + "items": { + "description": "A item object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this item", + "type": "integer" + }, + "name": { + "description": "The name associated with this item", + "type": "string" + }, + "functions": { + "description": "A list of functions associated with this item", + "type": "array", + "items": { + "$ref": "function.schema.json#/properties/functions/items" + } + }, + "flavor_text": { + "description": "Flavor text associated with this item", + "type": "string" + }, + "rules_description": { + "description": "A rules description associated with this item", + "type": "string" + }, + "physrep_requirements": { + "description": "The physrep requirements associated with this item", + "type": "string" + }, + "tags": { + "description": "A list of function tags associated with this item", + "type": "array", + "items": { + "$ref": "functiontag.schema.json#/properties/function_tags/items" + } + }, + "customizations": { + "description": "A list of customizations associated with this item", + "type": "array", + "items": { + "$ref": "customization.schema.json#/properties/customizations/items" + } + }, + "visibility": { + "description": "A list of groups attributed to this item", + "type": "array", + "items": { + "$ref": "group.schema.json#/properties/groups/items" + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "name", + "functions", + "flavor_text", + "rules_description", + "physrep_requirements", + "tags", + "customizations", + "visibility" + ] + } + }, + "item_update": { + "$ref": "#/properties/items/items" + } + }, + "required": ["items", "item_update"] +} diff --git a/test/fixtures/schemas/itemtag.schema.json b/test/fixtures/schemas/itemtag.schema.json new file mode 100644 index 0000000..0d34d0d --- /dev/null +++ b/test/fixtures/schemas/itemtag.schema.json @@ -0,0 +1,31 @@ +{ + "title": "Item Tag", + "description": "Describes a list of item tags", + "type": "object", + "properties": { + "item_tags": { + "description": "A list of item tags", + "type": "array", + "items": { + "description": "A item tag object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this item tag", + "type": "integer" + }, + "name": { + "description": "A name associated with this item tag", + "type": "string" + } + }, + "additionalProperties": false, + "required": ["id", "name"] + } + }, + "item_tag_update": { + "$ref": "#/properties/item_tags/items" + } + }, + "required": ["item_tags", "item_tag_update"] +} diff --git a/test/fixtures/schemas/person.schema.json b/test/fixtures/schemas/person.schema.json new file mode 100644 index 0000000..2ab5d29 --- /dev/null +++ b/test/fixtures/schemas/person.schema.json @@ -0,0 +1,38 @@ +{ + "title": "Person", + "description": "Describes a set of persons", + "type": "object", + "properties": { + "persons": { + "description": "A list of persons", + "type": "array", + "items": { + "description": "A person object", + "type": "object", + "properties": { + "id": { + "description": "An integer representing the function tag id", + "type": "integer" + }, + "name": { + "description": "The name associated with this person", + "type": "string" + }, + "groups": { + "description": "A list of groups attributed to this person", + "type": "array", + "items": { + "$ref": "group.schema.json#/properties/groups/items" + } + } + }, + "required": ["id", "name", "groups"], + "additionalProperties": false + } + }, + "person_update": { + "$ref": "#/properties/persons/items" + } + }, + "required": ["persons", "person_update"] +} diff --git a/test/fixtures/schemas/role.schema.json b/test/fixtures/schemas/role.schema.json new file mode 100644 index 0000000..a22b8fa --- /dev/null +++ b/test/fixtures/schemas/role.schema.json @@ -0,0 +1,45 @@ +{ + "title": "Role", + "description": "Describes a list of roles", + "type": "object", + "properties": { + "roles": { + "description": "A list of roles", + "type": "array", + "items": { + "description": "A role object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this item tag", + "type": "integer" + }, + "name": { + "description": "A name associated with this item tag", + "type": "string" + }, + "tiers": { + "description": "A list of tiers associated with this role", + "type": "array", + "items": { + "$ref": "./tier.schema.json#/properties/tiers/items" + } + }, + "visibility": { + "description": "A list of groups associated with this role", + "type": "array", + "items": { + "$ref": "./group.schema.json#/properties/groups/items" + } + } + }, + "additionalProperties": false, + "required": ["id", "name", "tiers", "visibility"] + } + }, + "role_update": { + "$ref": "#/properties/roles/items" + } + }, + "required": ["roles", "role_update"] +} diff --git a/test/fixtures/schemas/schematic.schema.json b/test/fixtures/schemas/schematic.schema.json new file mode 100644 index 0000000..fa03280 --- /dev/null +++ b/test/fixtures/schemas/schematic.schema.json @@ -0,0 +1,70 @@ +{ + "title": "Schematic", + "description": "Describes a list of schematics", + "type": "object", + "properties": { + "schematics": { + "description": "A list of schematics", + "type": "array", + "items": { + "description": "A schematic object", + "type": "object", + "properties": { + "id": { + "description": "An integer id associated with this schematic", + "type": "integer" + }, + "material": { + "description": "A list of materials associated with this schematic", + "type": "array", + "items": { + "$ref": "./inventoryslot.schema.json#/properties/inventory_slots/items" + } + }, + "tools": { + "description": "A list of tools associated with this schematic", + "type": "array", + "items": { + "$ref": "./inventoryslot.schema.json#/properties/inventory_slots/items" + } + }, + "requirements": { + "description": "A list of requirements for this schematic", + "type": "array", + "items": { + "$ref": "./function.schema.json#/properties/functions/items" + } + }, + "time_units": { + "description": "An amount of time units attributed to this schematic", + "type": "integer" + }, + "result": { + "$ref": "./inventoryslot.schema.json#/properties/inventory_slots/items" + }, + "visibility": { + "description": "A list of groups attributed to this schematic", + "type": "array", + "items": { + "$ref": "./group.schema.json#/properties/groups/items" + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "material", + "tools", + "requirements", + "time_units", + "result", + "visibility" + ] + } + }, + "schematic_update": { + "$ref": "#/properties/schematics/items" + } + }, + "required": ["schematics", "schematic_update"] +} diff --git a/test/fixtures/schemas/tier.schema.json b/test/fixtures/schemas/tier.schema.json new file mode 100644 index 0000000..6b3ecb4 --- /dev/null +++ b/test/fixtures/schemas/tier.schema.json @@ -0,0 +1,69 @@ +{ + "title": "Tier", + "description": "Describes a list of function sets", + "type": "object", + "properties": { + "tiers": { + "description": "A list of tiers", + "type": "array", + "items": { + "description": "A tier object", + "type": "object", + "properties": { + "id": { + "description": "Integer denoting the specific tier", + "type": "integer" + }, + "function_sets": { + "description": "A list of function sets held by this tier", + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "description": "Integer denoting the specific function", + "type": "integer" + }, + "name": { + "description": "The name of this function", + "type": "string" + }, + "tags": { + "description": "Function tags associated with this function", + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "description": "Integer denoting the specific function tag", + "type": "integer" + }, + "name": { + "description": "The name of this function tag", + "type": "string" + } + } + } + }, + "requirements": { + "description": "Functions required by this function", + "type": "array", + "items": { + "$ref": "tier.schema.json#/properties/tiers/items/properties/function_sets/items" + } + } + }, + "required": ["id", "name", "tags", "requirements"] + } + } + }, + "additionalProperties": false, + "required": ["id", "function_sets"] + } + }, + "tier_update": { + "$ref": "tier.schema.json#/properties/tiers/items" + } + }, + "required": ["tiers", "tier_update"] +} diff --git a/test/fixtures/schemas/user.schema.json b/test/fixtures/schemas/user.schema.json new file mode 100644 index 0000000..a696be1 --- /dev/null +++ b/test/fixtures/schemas/user.schema.json @@ -0,0 +1,70 @@ +{ + "title": "User", + "description": "Describes a user object", + "type": "object", + "properties": { + "id": { + "description": "Integer denoting the specific tier", + "type": "integer" + }, + "person": { + "$ref": "./person.schema.json#/properties/persons/items" + }, + "display_name": { + "description": "The display name associated with this user", + "type": "string" + }, + "user_name": { + "description": "The internal user name associated with this user", + "type": "string" + }, + "avatar": { + "description": "An avatar associated with this user", + "type": "string" + }, + "avatar_decoration": { + "description": "An avatar decoration associated with this user", + "type": "string" + }, + "login_token": { + "description": "The login token associated with this user", + "type": "string" + }, + "logged_in": { + "description": "Whether a user is currently logged in or not", + "type": "boolean" + }, + "api_keys": { + "description": "A list of api keys this user has generated", + "type": "array", + "items": { + "description": "An api key object", + "type": "object", + "properties": { + "name": { + "description": "A name associated with this api key", + "type": "string" + }, + "secret": { + "description": "The secret for this api key", + "type": "string" + } + }, + "additionalProperties": false, + "required": ["name", "secret"] + } + } + }, + "additionalProperties": false, + "required": [ + "id", + "person", + "display_name", + "user_name", + "avatar", + "avatar_decoration", + "login_token", + "logged_in", + "api_keys" + ] +} diff --git a/test/fixtures/schematics.json b/test/fixtures/schematics.json new file mode 100644 index 0000000..0fc180f --- /dev/null +++ b/test/fixtures/schematics.json @@ -0,0 +1,459 @@ +{ + "$schema": "./schemas/schematic.schema.json", + "schematics": [ + { + "id": 1, + "material": [], + "requirements": [], + "result": { + "id": 1, + "item": { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 1 + }, + "time_units": 10, + "tools": [], + "visibility": [] + }, + { + "id": 2, + "material": [ + { + "id": 1, + "item": { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 1 + } + ], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "result": { + "id": 2, + "item": { + "customizations": [ + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + } + ], + "flavor_text": "Silver currency", + "functions": [], + "id": 2, + "name": "Silver", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 2 + }, + "time_units": 20, + "tools": [], + "visibility": [] + }, + { + "id": 3, + "material": [], + "requirements": [], + "result": { + "id": 3, + "item": { + "customizations": [], + "flavor_text": "Gold currency", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 3, + "name": "Gold", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 3 + }, + "time_units": 30, + "tools": [ + { + "id": 1, + "item": { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 1 + } + ], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } + ], + "schematic_update": { + "id": 1, + "material": [ + { + "id": 1, + "item": { + "customizations": [], + "flavor_text": "Bronze currency", + "functions": [], + "id": 1, + "name": "Bronze", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 1 + }, + { + "id": 2, + "item": { + "customizations": [ + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + } + ], + "flavor_text": "Silver currency", + "functions": [], + "id": 2, + "name": "Silver", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 2 + }, + { + "id": 3, + "item": { + "customizations": [], + "flavor_text": "Gold currency", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 3, + "name": "Gold", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 3 + } + ], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "result": { + "id": 3, + "item": { + "customizations": [], + "flavor_text": "Gold currency", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + } + ], + "id": 3, + "name": "Gold", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 3 + }, + "time_units": 0, + "tools": [ + { + "id": 2, + "item": { + "customizations": [ + { + "flavor_text": "Skibbidy rizz ohio", + "functions": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + }, + { + "id": 2, + "name": "test2", + "tags": [ + { + "id": 1, + "name": "test1" + } + ], + "requirements": [] + }, + { + "id": 3, + "name": "test3", + "tags": [], + "requirements": [ + { + "id": 1, + "name": "test1", + "tags": [], + "requirements": [] + } + ] + } + ], + "id": 2, + "name": "test2", + "physrep_requirements": "Do you lift", + "rules_description": "Ur mom gay", + "tags": [], + "visibility": [] + } + ], + "flavor_text": "Silver currency", + "functions": [], + "id": 2, + "name": "Silver", + "physrep_requirements": "None", + "rules_description": "Money can be exchanged for goods and services", + "tags": [], + "visibility": [] + }, + "quantity": 2 + } + ], + "visibility": [ + { + "id": 1, + "name": "test1" + }, + { + "id": 2, + "name": "test2" + }, + { + "id": 3, + "name": "test3" + } + ] + } +} diff --git a/test/fixtures/tiers.json b/test/fixtures/tiers.json new file mode 100644 index 0000000..2f53bea --- /dev/null +++ b/test/fixtures/tiers.json @@ -0,0 +1,76 @@ +{ + "$schema": "./schemas/tier.schema.json", + "tiers": [ + { + "id": 1, + "function_sets": [] + }, + { + "id": 2, + "function_sets": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + }, + { + "id": 2, + "name": "function2", + "requirements": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + } + ], + "tags": [] + }, + { + "id": 3, + "name": "function3", + "requirements": [], + "tags": [ + { + "id": 1, + "name": "tag1" + }, + { + "id": 2, + "name": "tag2" + }, + { + "id": 3, + "name": "tag3" + } + ] + } + ] + } + ], + "tier_update": { + "id": 1, + "function_sets": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + }, + { + "id": 2, + "name": "function2", + "requirements": [ + { + "id": 1, + "name": "function1", + "requirements": [], + "tags": [] + } + ], + "tags": [] + } + ] + } +} diff --git a/test/go.mod b/test/go.mod index a7e857f..3a09cca 100644 --- a/test/go.mod +++ b/test/go.mod @@ -2,74 +2,65 @@ module api_test go 1.24.2 +replace example.com/unit/tiertest => ./unit/tiertest + replace example.com/unit/persontest => ./unit/persontest replace example.com/unit/grouptest => ./unit/grouptest replace example.com/unit/functiontest => ./unit/functiontest +replace example.com/unit/functionsettest => ./unit/functionsettest + replace example.com/unit/functiontagtest => ./unit/functiontagtest replace example.com/test/testrequest => ./lib/testrequest replace example.com/test/testsetup => ./lib/testsetup -replace example.com/api => ../src/lib/api +replace example.com/api => ../src/modules/api -replace example.com/database => ../src/lib/database +replace example.com/database => ../src/modules/database -replace example.com/database/user => ../src/lib/database/user +replace example.com/database/user => ../src/modules/database/user -replace example.com/database/character => ../src/lib/database/character +replace example.com/database/character => ../src/modules/database/character -replace example.com/database/functionset => ../src/lib/database/functionset +replace example.com/database/functionset => ../src/modules/database/functionset -replace example.com/database/inventoryslot => ../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../src/modules/database/inventoryslot -replace example.com/database/customization => ../src/lib/database/customization +replace example.com/database/customization => ../src/modules/database/customization -replace example.com/database/item => ../src/lib/database/item +replace example.com/database/item => ../src/modules/database/item -replace example.com/database/itemtag => ../src/lib/database/itemtag +replace example.com/database/itemtag => ../src/modules/database/itemtag -replace example.com/database/person => ../src/lib/database/person +replace example.com/database/person => ../src/modules/database/person -replace example.com/database/role => ../src/lib/database/role +replace example.com/database/role => ../src/modules/database/role -replace example.com/database/schematic => ../src/lib/database/schematic +replace example.com/database/schematic => ../src/modules/database/schematic -replace example.com/database/tier => ../src/lib/database/tier +replace example.com/database/tier => ../src/modules/database/tier -replace example.com/database/group => ../src/lib/database/group +replace example.com/database/group => ../src/modules/database/group -replace example.com/database/function => ../src/lib/database/function +replace example.com/database/function => ../src/modules/database/function -replace example.com/database/functiontag => ../src/lib/database/functiontag +replace example.com/database/functiontag => ../src/modules/database/functiontag -replace example.com/config/server => ../src/lib/config/server +replace example.com/config/server => ../src/modules/config/server -replace example.com/auth/discord => ../src/lib/auth/discord +replace example.com/auth/discord => ../src/modules/auth/discord require ( - example.com/database/character v0.0.0 - example.com/database/customization v0.0.0 - example.com/database/function v0.0.0 - example.com/database/functionset v0.0.0 - example.com/database/functiontag v0.0.0 - example.com/database/group v0.0.0 - example.com/database/inventoryslot v0.0.0 - example.com/database/item v0.0.0 - example.com/database/itemtag v0.0.0 - example.com/database/person v0.0.0 - example.com/database/role v0.0.0 - example.com/database/schematic v0.0.0 - example.com/database/tier v0.0.0 - example.com/database/user v0.0.0 + example.com/unit/functionsettest v0.0.0 example.com/unit/functiontagtest v0.0.0 example.com/unit/functiontest v0.0.0 example.com/unit/grouptest v0.0.0 example.com/unit/persontest v0.0.0 - github.com/gin-gonic/gin v1.10.0 + example.com/unit/tiertest v0.0.0 github.com/stretchr/testify v1.10.0 ) @@ -78,6 +69,20 @@ require ( example.com/auth/discord v0.0.0 // indirect example.com/config/server v0.0.0 // indirect example.com/database v0.0.0-00010101000000-000000000000 // indirect + example.com/database/character v0.0.0 // indirect + example.com/database/customization v0.0.0 // indirect + example.com/database/function v0.0.0 // indirect + example.com/database/functionset v0.0.0 // indirect + example.com/database/functiontag v0.0.0 // indirect + example.com/database/group v0.0.0 // indirect + example.com/database/inventoryslot v0.0.0 // indirect + example.com/database/item v0.0.0 // indirect + example.com/database/itemtag v0.0.0 // indirect + example.com/database/person v0.0.0 // indirect + example.com/database/role v0.0.0 // indirect + example.com/database/schematic v0.0.0 // indirect + example.com/database/tier v0.0.0 // indirect + example.com/database/user v0.0.0 // indirect example.com/test/testrequest v0.0.0 // indirect example.com/test/testsetup v0.0.0 // indirect github.com/bytedance/sonic v1.13.2 // indirect @@ -87,6 +92,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/gin-contrib/cors v1.7.5 // indirect github.com/gin-contrib/sse v1.0.0 // indirect + github.com/gin-gonic/gin v1.10.1 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.26.0 // indirect @@ -116,5 +122,5 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.7 // indirect - gorm.io/gorm v1.25.12 // indirect + gorm.io/gorm v1.26.1 // indirect ) diff --git a/test/go.sum b/test/go.sum index 930a2df..7118f42 100644 --- a/test/go.sum +++ b/test/go.sum @@ -15,8 +15,8 @@ github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYM github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= -github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= -github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= +github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -106,6 +106,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I= gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= -gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= -gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw= +gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= diff --git a/test/lib/testsetup/go.mod b/test/lib/testsetup/go.mod index f3d9a05..7a65113 100644 --- a/test/lib/testsetup/go.mod +++ b/test/lib/testsetup/go.mod @@ -2,41 +2,41 @@ module example.com/test/testsetup go 1.24.2 -replace example.com/api => ../../../src/lib/api +replace example.com/api => ../../../src/modules/api -replace example.com/database => ../../../src/lib/database +replace example.com/database => ../../../src/modules/database -replace example.com/database/user => ../../../src/lib/database/user +replace example.com/database/user => ../../../src/modules/database/user -replace example.com/database/character => ../../../src/lib/database/character +replace example.com/database/character => ../../../src/modules/database/character -replace example.com/database/functionset => ../../../src/lib/database/functionset +replace example.com/database/functionset => ../../../src/modules/database/functionset -replace example.com/database/inventoryslot => ../../../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot -replace example.com/database/customization => ../../../src/lib/database/customization +replace example.com/database/customization => ../../../src/modules/database/customization -replace example.com/database/item => ../../../src/lib/database/item +replace example.com/database/item => ../../../src/modules/database/item -replace example.com/database/itemtag => ../../../src/lib/database/itemtag +replace example.com/database/itemtag => ../../../src/modules/database/itemtag -replace example.com/database/person => ../../../src/lib/database/person +replace example.com/database/person => ../../../src/modules/database/person -replace example.com/database/role => ../../../src/lib/database/role +replace example.com/database/role => ../../../src/modules/database/role -replace example.com/database/schematic => ../../../src/lib/database/schematic +replace example.com/database/schematic => ../../../src/modules/database/schematic -replace example.com/database/tier => ../../../src/lib/database/tier +replace example.com/database/tier => ../../../src/modules/database/tier -replace example.com/database/group => ../../../src/lib/database/group +replace example.com/database/group => ../../../src/modules/database/group -replace example.com/database/function => ../../../src/lib/database/function +replace example.com/database/function => ../../../src/modules/database/function -replace example.com/database/functiontag => ../../../src/lib/database/functiontag +replace example.com/database/functiontag => ../../../src/modules/database/functiontag -replace example.com/config/server => ../../../src/lib/config/server +replace example.com/config/server => ../../../src/modules/config/server -replace example.com/auth/discord => ../../../src/lib/auth/discord +replace example.com/auth/discord => ../../../src/modules/auth/discord require ( example.com/api v0.0.0-00010101000000-000000000000 diff --git a/test/unit/functionsettest/functionsettest.go b/test/unit/functionsettest/functionsettest.go new file mode 100644 index 0000000..d3cfa78 --- /dev/null +++ b/test/unit/functionsettest/functionsettest.go @@ -0,0 +1,161 @@ +package functionsettest + +import ( + "encoding/json" + "fmt" + "os" + + function "example.com/database/function" + functionset "example.com/database/functionset" + testrequest "example.com/test/testrequest" + testsetup "example.com/test/testsetup" + functiontest "example.com/unit/functiontest" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/suite" +) + +type TestFunctionSet struct { + Result []functionset.FunctionSet `json:"result"` +} + +type FunctionSetTestSuite struct { + suite.Suite + globalAuthHeader string + router *gin.Engine + functionSet functionset.FunctionSet + functionSetJSON []byte + functionSetUpdate functionset.FunctionSet + functionSetUpdateJSON []byte +} + +func (s *FunctionSetTestSuite) SetupTestSuite() { + s.globalAuthHeader, s.router = testsetup.SetupTestSuite() + // Create Test Data + fixtures, _ := os.ReadFile("fixtures/functionset.json") + var functionSetFixtures struct { + FunctionSets []functionset.FunctionSet `json:"function_sets"` + FunctionSetUpdate functionset.FunctionSet `json:"function_set_update"` + } + json.Unmarshal(fixtures, &functionSetFixtures) + s.functionSet = functionSetFixtures.FunctionSets[0] + var functionSetFunctionIDs []uint + for _, function := range s.functionSet.Functions { + functionSetFunctionIDs = append(functionSetFunctionIDs, function.ID) + } + s.functionSetJSON, _ = json.Marshal(functionset.FunctionSetParams{ + Functions: functionSetFunctionIDs, + }) + s.functionSetUpdate = functionSetFixtures.FunctionSetUpdate + var functionSetUpdateFunctionIDs []uint + for _, function := range s.functionSetUpdate.Functions { + functionSetUpdateFunctionIDs = append(functionSetUpdateFunctionIDs, function.ID) + } + s.functionSetUpdateJSON, _ = json.Marshal(functionset.FunctionSetParams{ + Functions: functionSetUpdateFunctionIDs, + }) +} + +func (s *FunctionSetTestSuite) TearDownTestSuite() { + os.Remove("db/main.db") +} + +func (s *FunctionSetTestSuite) Test01CreateFunctionSet() { + // Setup variables + var output TestFunctionSet + target := fmt.Sprintf("/function-set?id=%d", s.functionSet.ID) + + // Create needed field objects + var functionOutput functiontest.TestFunction + for _, function := range s.functionSet.Functions { + functionBody, _ := json.Marshal(function) + functionStatus := testrequest.MakePostRequest(&functionBody, "/function", s.globalAuthHeader, s.router) + s.Equal(functionStatus, "200 OK", "function created successfully") + functionTarget := fmt.Sprintf("/function?id=%d", function.ID) + functionBody = testrequest.MakeGetRequest(functionTarget, s.router) + json.Unmarshal(functionBody, &functionOutput) + s.Equal(function.Name, functionOutput.Result[0].Name, "input function name matches output function name") + } + + // Attempt to create function set + status := testrequest.MakePostRequest(&s.functionSetJSON, "/function-set", s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "function created successfully") + + // Attempt to get function set + body := testrequest.MakeGetRequest(target, s.router) + json.Unmarshal(body, &output) + // Check that the function set listed matches the created function set + s.Equal(s.functionSet.Functions[0].Name, output.Result[0].Functions[0].Name, "first input function name matches first output function name") +} + +func (s *FunctionSetTestSuite) Test02GetFunctionSet() { + // Setup variables + var output TestFunctionSet + + // Attempt to get function sets + body := testrequest.MakeGetRequest("/function-set", s.router) + json.Unmarshal(body, &output) + // Check that the function sets listed match the created function sets + s.Equal(s.functionSet.Functions[0].Name, output.Result[0].Functions[0].Name, "first input function name matches first output function name") +} + +func (s *FunctionSetTestSuite) Test03UpdateFunctionSet() { + // Setup variables + var output TestFunctionSet + target := fmt.Sprintf("/function-set?id=%d", s.functionSet.ID) + + // Create needed field objects + var functionOutput functiontest.TestFunction + for _, updateFunction := range s.functionSetUpdate.Functions { + var functionTagIDs []uint + for _, tag := range updateFunction.Tags { + tagBody, _ := json.Marshal(tag) + testrequest.MakePostRequest(&tagBody, "/function-tag", s.globalAuthHeader, s.router) + functionTagIDs = append(functionTagIDs, tag.ID) + } + var functionRequirementIDs []uint + for _, requirement := range updateFunction.Requirements { + functionRequirementIDs = append(functionRequirementIDs, requirement.ID) + } + functionBody, _ := json.Marshal(function.FunctionParams{ + Name: updateFunction.Name, + Tags: functionTagIDs, + Requirements: functionRequirementIDs, + }) + functionStatus := testrequest.MakePostRequest(&functionBody, "/function", s.globalAuthHeader, s.router) + s.Equal(functionStatus, "200 OK", "function created successfully") + functionTarget := fmt.Sprintf("/function?id=%d", updateFunction.ID) + functionBody = testrequest.MakeGetRequest(functionTarget, s.router) + json.Unmarshal(functionBody, &functionOutput) + s.Equal(updateFunction.Name, functionOutput.Result[0].Name, "input function name matches output function name") + } + + // Attempt to update function set + status := testrequest.MakePutRequest(&s.functionSetUpdateJSON, target, s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "function set created successfully") + + // Attempt to get function set + body := testrequest.MakeGetRequest(target, s.router) + json.Unmarshal(body, &output) + // Check that the function set listed matches the updated function + s.Equal(s.functionSetUpdate.Functions[0].Name, output.Result[0].Functions[0].Name, "first updated function name matches first output function name") + s.Equal(s.functionSetUpdate.Functions[1].Name, output.Result[0].Functions[1].Name, "second updated function name matches second output function name") +} + +func (s *FunctionSetTestSuite) Test04DeleteFunctionSet() { + // Setup variables + var output TestFunctionSet + target := fmt.Sprintf("/function-set?id=%d", s.functionSet.ID) + + // Attempt to delete function set + status := testrequest.MakeDeleteRequest(target, s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "function deleted successfully") + + // Attempt to get function set + body := testrequest.MakeGetRequest("/function-set", s.router) + json.Unmarshal(body, &output) + // Check that the function set list is empty + s.Equal(0, len(output.Result), "function set list is empty") +} diff --git a/test/unit/functionsettest/go.mod b/test/unit/functionsettest/go.mod new file mode 100644 index 0000000..f147018 --- /dev/null +++ b/test/unit/functionsettest/go.mod @@ -0,0 +1,115 @@ +module example.com/unit/functionsettest + +go 1.24.2 + +replace example.com/api => ../../../src/modules/api + +replace example.com/database => ../../../src/modules/database + +replace example.com/database/user => ../../../src/modules/database/user + +replace example.com/unit/grouptest => ../../unit/grouptest + +replace example.com/unit/functiontest => ../../unit/functiontest + +replace example.com/unit/functiontagtest => ../../unit/functiontagtest + +replace example.com/test/testrequest => ../../lib/testrequest + +replace example.com/test/testsetup => ../../lib/testsetup + +replace example.com/database/character => ../../../src/modules/database/character + +replace example.com/database/functionset => ../../../src/modules/database/functionset + +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot + +replace example.com/database/customization => ../../../src/modules/database/customization + +replace example.com/database/item => ../../../src/modules/database/item + +replace example.com/database/itemtag => ../../../src/modules/database/itemtag + +replace example.com/database/person => ../../../src/modules/database/person + +replace example.com/database/role => ../../../src/modules/database/role + +replace example.com/database/schematic => ../../../src/modules/database/schematic + +replace example.com/database/tier => ../../../src/modules/database/tier + +replace example.com/database/group => ../../../src/modules/database/group + +replace example.com/database/function => ../../../src/modules/database/function + +replace example.com/database/functiontag => ../../../src/modules/database/functiontag + +replace example.com/config/server => ../../../src/modules/config/server + +replace example.com/auth/discord => ../../../src/modules/auth/discord + +require ( + example.com/database/function v0.0.0 + example.com/database/functionset v0.0.0 + example.com/test/testrequest v0.0.0 + example.com/test/testsetup v0.0.0 + example.com/unit/functiontest v0.0.0 + github.com/gin-gonic/gin v1.10.0 + github.com/stretchr/testify v1.10.0 +) + +require ( + example.com/api v0.0.0-00010101000000-000000000000 // indirect + example.com/auth/discord v0.0.0 // indirect + example.com/config/server v0.0.0 // indirect + example.com/database v0.0.0-00010101000000-000000000000 // indirect + example.com/database/character v0.0.0 // indirect + example.com/database/customization v0.0.0 // indirect + example.com/database/functiontag v0.0.0 // indirect + example.com/database/group v0.0.0 // indirect + example.com/database/inventoryslot v0.0.0 // indirect + example.com/database/item v0.0.0 // indirect + example.com/database/itemtag v0.0.0 // indirect + example.com/database/person v0.0.0 // indirect + example.com/database/role v0.0.0 // indirect + example.com/database/schematic v0.0.0 // indirect + example.com/database/tier v0.0.0 // indirect + example.com/database/user v0.0.0 // indirect + github.com/bytedance/sonic v1.13.2 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gin-contrib/cors v1.7.5 // indirect + github.com/gin-contrib/sse v1.0.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.26.0 // indirect + github.com/goccy/go-json v0.10.5 // indirect + github.com/golang-jwt/jwt/v5 v5.2.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.10 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-sqlite3 v1.14.22 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + github.com/xyproto/randomstring v1.2.0 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/sqlite v1.5.7 // indirect + gorm.io/gorm v1.25.12 // indirect +) diff --git a/src/lib/database/user/go.sum b/test/unit/functionsettest/go.sum similarity index 50% rename from src/lib/database/user/go.sum rename to test/unit/functionsettest/go.sum index 5188744..930a2df 100644 --- a/src/lib/database/user/go.sum +++ b/test/unit/functionsettest/go.sum @@ -1,18 +1,20 @@ -github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= -github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= -github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= -github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYMk= +github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0= +github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= +github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= @@ -21,12 +23,14 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= +github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= @@ -35,22 +39,32 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 h1:x3LgcvujjG+mx8PUMfPmwn3tcu2aA95uCB6ilGGObWk= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3/go.mod h1:P/mZMYLZ87lqRSECEWsOqywGrO1hlZkk9RTwEw35IP4= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -61,35 +75,37 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= -golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/xyproto/randomstring v1.2.0 h1:y7PXAEBM3XlwJjPG2JQg4voxBYZ4+hPgRdGKCfU8wik= +github.com/xyproto/randomstring v1.2.0/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= +golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= +golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I= +gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/test/unit/functiontagtest/functiontagtest.go b/test/unit/functiontagtest/functiontagtest.go index cc3218e..e47ecf9 100644 --- a/test/unit/functiontagtest/functiontagtest.go +++ b/test/unit/functiontagtest/functiontagtest.go @@ -10,7 +10,6 @@ import ( testsetup "example.com/test/testsetup" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" - "gorm.io/gorm" ) type TestFunctionTag struct { @@ -29,9 +28,15 @@ type FunctionTagTestSuite struct { func (s *FunctionTagTestSuite) SetupTestSuite() { s.globalAuthHeader, s.router = testsetup.SetupTestSuite() // Create Test Data - s.functiontag = functiontag.FunctionTag{Model: gorm.Model{ID: 1}, Name: "test"} + fixtures, _ := os.ReadFile("fixtures/functiontags.json") + var functionTagFixtures struct { + FunctionTags []functiontag.FunctionTag `json:"function_tags"` + FunctionTagUpdate functiontag.FunctionTag `json:"function_tag_update"` + } + json.Unmarshal(fixtures, &functionTagFixtures) + s.functiontag = functionTagFixtures.FunctionTags[0] s.functiontagJSON, _ = json.Marshal(s.functiontag) - s.functiontagUpdate = functiontag.FunctionTag{Model: gorm.Model{ID: 1}, Name: "another_test"} + s.functiontagUpdate = functionTagFixtures.FunctionTagUpdate } func (s *FunctionTagTestSuite) TearDownTestSuite() { diff --git a/test/unit/functiontagtest/go.mod b/test/unit/functiontagtest/go.mod index b7a2637..50244bc 100644 --- a/test/unit/functiontagtest/go.mod +++ b/test/unit/functiontagtest/go.mod @@ -2,45 +2,45 @@ module example.com/unit/functiontagtest go 1.24.2 -replace example.com/api => ../../../src/lib/api +replace example.com/api => ../../../src/modules/api -replace example.com/database => ../../../src/lib/database +replace example.com/database => ../../../src/modules/database -replace example.com/database/user => ../../../src/lib/database/user +replace example.com/database/user => ../../../src/modules/database/user replace example.com/test/testrequest => ../../lib/testrequest replace example.com/test/testsetup => ../../lib/testsetup -replace example.com/database/character => ../../../src/lib/database/character +replace example.com/database/character => ../../../src/modules/database/character -replace example.com/database/functionset => ../../../src/lib/database/functionset +replace example.com/database/functionset => ../../../src/modules/database/functionset -replace example.com/database/inventoryslot => ../../../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot -replace example.com/database/customization => ../../../src/lib/database/customization +replace example.com/database/customization => ../../../src/modules/database/customization -replace example.com/database/item => ../../../src/lib/database/item +replace example.com/database/item => ../../../src/modules/database/item -replace example.com/database/itemtag => ../../../src/lib/database/itemtag +replace example.com/database/itemtag => ../../../src/modules/database/itemtag -replace example.com/database/person => ../../../src/lib/database/person +replace example.com/database/person => ../../../src/modules/database/person -replace example.com/database/role => ../../../src/lib/database/role +replace example.com/database/role => ../../../src/modules/database/role -replace example.com/database/schematic => ../../../src/lib/database/schematic +replace example.com/database/schematic => ../../../src/modules/database/schematic -replace example.com/database/tier => ../../../src/lib/database/tier +replace example.com/database/tier => ../../../src/modules/database/tier -replace example.com/database/group => ../../../src/lib/database/group +replace example.com/database/group => ../../../src/modules/database/group -replace example.com/database/function => ../../../src/lib/database/function +replace example.com/database/function => ../../../src/modules/database/function -replace example.com/database/functiontag => ../../../src/lib/database/functiontag +replace example.com/database/functiontag => ../../../src/modules/database/functiontag -replace example.com/config/server => ../../../src/lib/config/server +replace example.com/config/server => ../../../src/modules/config/server -replace example.com/auth/discord => ../../../src/lib/auth/discord +replace example.com/auth/discord => ../../../src/modules/auth/discord require ( example.com/database/functiontag v0.0.0 @@ -48,7 +48,6 @@ require ( example.com/test/testsetup v0.0.0 github.com/gin-gonic/gin v1.10.0 github.com/stretchr/testify v1.10.0 - gorm.io/gorm v1.25.12 ) require ( @@ -105,4 +104,5 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.7 // indirect + gorm.io/gorm v1.25.12 // indirect ) diff --git a/test/unit/functiontest/functiontest.go b/test/unit/functiontest/functiontest.go index 79dfa01..35ec658 100644 --- a/test/unit/functiontest/functiontest.go +++ b/test/unit/functiontest/functiontest.go @@ -6,13 +6,10 @@ import ( "os" function "example.com/database/function" - "example.com/database/functiontag" testrequest "example.com/test/testrequest" testsetup "example.com/test/testsetup" - functiontagtest "example.com/unit/functiontagtest" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" - "gorm.io/gorm" ) type TestFunction struct { @@ -32,38 +29,44 @@ type FunctionTestSuite struct { func (s *FunctionTestSuite) SetupTestSuite() { s.globalAuthHeader, s.router = testsetup.SetupTestSuite() // Create Test Data - testFunctionTag := functiontag.FunctionTag{ - Model: gorm.Model{ID: 1}, - Name: "test", + fixtures, _ := os.ReadFile("fixtures/functions.json") + var functionFixtures struct { + Functions []function.Function `json:"functions"` + FunctionUpdate function.Function `json:"function_update"` } - testFunction := function.Function{ - Model: gorm.Model{ID: 2}, - Name: "test", - Tags: []functiontag.FunctionTag{}, - Requirements: []function.Function{}, + json.Unmarshal(fixtures, &functionFixtures) + s.function = functionFixtures.Functions[0] + var functionTagIDs []uint + for _, tag := range s.function.Tags { + functionTagIDs = append(functionTagIDs, tag.ID) } - s.function = function.Function{ - Model: gorm.Model{ID: 1}, - Name: "another_test", - Tags: []functiontag.FunctionTag{}, - Requirements: []function.Function{}, + var functionRequirementIDs []uint + for _, requirement := range s.function.Requirements { + functionRequirementIDs = append(functionRequirementIDs, requirement.ID) } - s.functionJSON, _ = json.Marshal(s.function) - s.functionUpdate = function.Function{ - Model: gorm.Model{ID: 1}, - Name: "yet_another_test", - Tags: []functiontag.FunctionTag{ - testFunctionTag, - }, - Requirements: []function.Function{ - testFunction, - }, + s.functionJSON, _ = json.Marshal(function.FunctionParams{ + Name: s.function.Name, + Tags: functionTagIDs, + Requirements: functionRequirementIDs, + }) + s.functionUpdate = functionFixtures.FunctionUpdate + var functionUpdateTagIDs []uint + for _, tag := range s.functionUpdate.Tags { + functionUpdateTagIDs = append(functionUpdateTagIDs, tag.ID) + } + var functionUpdateRequirementIDs []uint + for _, requirement := range s.functionUpdate.Requirements { + functionUpdateRequirementIDs = append(functionUpdateRequirementIDs, requirement.ID) } s.functionUpdateJSON, _ = json.Marshal(function.FunctionParams{ Name: s.functionUpdate.Name, - Tags: []uint{1}, - Requirements: []uint{2}, + Tags: functionUpdateTagIDs, + Requirements: functionUpdateRequirementIDs, }) + for _, tag := range s.functionUpdate.Tags { + tagBody, _ := json.Marshal(tag) + testrequest.MakePostRequest(&tagBody, "/function-tag", s.globalAuthHeader, s.router) + } } func (s *FunctionTestSuite) TearDownTestSuite() { @@ -76,6 +79,7 @@ func (s *FunctionTestSuite) Test01CreateFunction() { target := fmt.Sprintf("/function?id=%d", s.function.ID) // Attempt to create function + fmt.Println(string(s.functionJSON)) status := testrequest.MakePostRequest(&s.functionJSON, "/function", s.globalAuthHeader, s.router) // Check that the request was successful s.Equal(status, "200 OK", "function created successfully") @@ -107,36 +111,22 @@ func (s *FunctionTestSuite) Test03UpdateFunction() { // Create needed field objects // Setup variables - var functionTagOutput functiontagtest.TestFunctionTag - functionTagBody, _ := json.Marshal(s.functionUpdate.Tags[0]) - // Attempt to create function tag - functionTagStatus := testrequest.MakePostRequest(&functionTagBody, "/function-tag", s.globalAuthHeader, s.router) - // Check that the request was successful - s.Equal(functionTagStatus, "200 OK", "function tag created successfully") - // Setup variables - functionTagTarget := fmt.Sprintf("/function-tag?id=%d", s.functionUpdate.Tags[0].ID) - // Attempt to get function tag - functionTagBody = testrequest.MakeGetRequest(functionTagTarget, s.router) - // Unamrshal the result - json.Unmarshal(functionTagBody, &functionTagOutput) - // Check that the function tag listed matches the created function tag - s.Equal(s.functionUpdate.Tags[0].Name, functionTagOutput.Result[0].Name, "input function tag name matches created function tag name") - // Setup variables - var functionOutput TestFunction - functionBody, _ := json.Marshal(s.functionUpdate.Requirements[0]) - // Attempt to create function - functionStatus := testrequest.MakePostRequest(&functionBody, "/function", s.globalAuthHeader, s.router) - // Check that the request was successful - s.Equal(functionStatus, "200 OK", "function created successfully") - // Setup variables - functionTarget := fmt.Sprintf("/function?id=%d", s.functionUpdate.Requirements[0].ID) - // Attempt to get function - functionBody = testrequest.MakeGetRequest(functionTarget, s.router) - // Unmarshal the result - json.Unmarshal(functionBody, &functionOutput) - // Check that the function listed matches the created function - s.Equal(s.functionUpdate.Requirements[0].Name, functionOutput.Result[0].Name, "input function name matches created function name") - + for _, requirement := range s.functionUpdate.Requirements { + var requirementTagIDs []uint + for _, tag := range s.function.Tags { + requirementTagIDs = append(requirementTagIDs, tag.ID) + } + var requirementRequirementIDs []uint + for _, requirement := range s.function.Requirements { + requirementRequirementIDs = append(requirementRequirementIDs, requirement.ID) + } + requirementBody, _ := json.Marshal(function.FunctionParams{ + Name: requirement.Name, + Tags: requirementTagIDs, + Requirements: requirementRequirementIDs, + }) + testrequest.MakePostRequest(&requirementBody, "/function", s.globalAuthHeader, s.router) + } // Attempt to update function status := testrequest.MakePutRequest(&s.functionUpdateJSON, target, s.globalAuthHeader, s.router) // Check that the request was successful @@ -163,9 +153,9 @@ func (s *FunctionTestSuite) Test04DeleteFunction() { s.Equal(status, "200 OK", "function deleted successfully") // Attempt to get function - body := testrequest.MakeGetRequest(target, s.router) + body := testrequest.MakeGetRequest("/function", s.router) // Unmarshal the result json.Unmarshal(body, &output) - // Check that the function list has one entry - s.Equal(1, len(output.Result), "function list has one entry left") + // Check that the function list only has two entries + s.Equal(2, len(output.Result), "function list has two entries left") } diff --git a/test/unit/functiontest/go.mod b/test/unit/functiontest/go.mod index 1e23a94..eb64b4b 100644 --- a/test/unit/functiontest/go.mod +++ b/test/unit/functiontest/go.mod @@ -2,58 +2,56 @@ module example.com/unit/functiontest go 1.24.2 -replace example.com/api => ../../../src/lib/api +replace example.com/api => ../../../src/modules/api -replace example.com/database => ../../../src/lib/database +replace example.com/database => ../../../src/modules/database -replace example.com/database/user => ../../../src/lib/database/user +replace example.com/database/user => ../../../src/modules/database/user replace example.com/unit/functiontagtest => ../../unit/functiontagtest +replace example.com/unit/grouptest => ../../unit/grouptest + replace example.com/test/testrequest => ../../lib/testrequest replace example.com/test/testsetup => ../../lib/testsetup -replace example.com/database/character => ../../../src/lib/database/character +replace example.com/database/character => ../../../src/modules/database/character -replace example.com/database/functionset => ../../../src/lib/database/functionset +replace example.com/database/functionset => ../../../src/modules/database/functionset -replace example.com/database/inventoryslot => ../../../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot -replace example.com/database/customization => ../../../src/lib/database/customization +replace example.com/database/customization => ../../../src/modules/database/customization -replace example.com/database/item => ../../../src/lib/database/item +replace example.com/database/item => ../../../src/modules/database/item -replace example.com/database/itemtag => ../../../src/lib/database/itemtag +replace example.com/database/itemtag => ../../../src/modules/database/itemtag -replace example.com/database/person => ../../../src/lib/database/person +replace example.com/database/person => ../../../src/modules/database/person -replace example.com/database/role => ../../../src/lib/database/role +replace example.com/database/role => ../../../src/modules/database/role -replace example.com/database/schematic => ../../../src/lib/database/schematic +replace example.com/database/schematic => ../../../src/modules/database/schematic -replace example.com/database/tier => ../../../src/lib/database/tier +replace example.com/database/tier => ../../../src/modules/database/tier -replace example.com/database/group => ../../../src/lib/database/group +replace example.com/database/group => ../../../src/modules/database/group -replace example.com/database/function => ../../../src/lib/database/function +replace example.com/database/function => ../../../src/modules/database/function -replace example.com/database/functiontag => ../../../src/lib/database/functiontag +replace example.com/database/functiontag => ../../../src/modules/database/functiontag -replace example.com/config/server => ../../../src/lib/config/server +replace example.com/config/server => ../../../src/modules/config/server -replace example.com/auth/discord => ../../../src/lib/auth/discord +replace example.com/auth/discord => ../../../src/modules/auth/discord require ( - example.com/unit/functiontagtest v0.0.0 - example.com/database/group v0.0.0 - example.com/database/person v0.0.0 + example.com/database/function v0.0.0 example.com/test/testrequest v0.0.0 example.com/test/testsetup v0.0.0 - example.com/unit/grouptest v0.0.0 github.com/gin-gonic/gin v1.10.0 github.com/stretchr/testify v1.10.0 - gorm.io/gorm v1.25.12 ) require ( @@ -63,12 +61,13 @@ require ( example.com/database v0.0.0-00010101000000-000000000000 // indirect example.com/database/character v0.0.0 // indirect example.com/database/customization v0.0.0 // indirect - example.com/database/function v0.0.0 // indirect example.com/database/functionset v0.0.0 // indirect example.com/database/functiontag v0.0.0 // indirect + example.com/database/group v0.0.0 // indirect example.com/database/inventoryslot v0.0.0 // indirect example.com/database/item v0.0.0 // indirect example.com/database/itemtag v0.0.0 // indirect + example.com/database/person v0.0.0 // indirect example.com/database/role v0.0.0 // indirect example.com/database/schematic v0.0.0 // indirect example.com/database/tier v0.0.0 // indirect @@ -109,4 +108,5 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.7 // indirect + gorm.io/gorm v1.25.12 // indirect ) diff --git a/test/unit/grouptest/go.mod b/test/unit/grouptest/go.mod index 896e84a..db58a69 100644 --- a/test/unit/grouptest/go.mod +++ b/test/unit/grouptest/go.mod @@ -2,45 +2,45 @@ module example.com/unit/grouptest go 1.24.2 -replace example.com/api => ../../../src/lib/api +replace example.com/api => ../../../src/modules/api -replace example.com/database => ../../../src/lib/database +replace example.com/database => ../../../src/modules/database -replace example.com/database/user => ../../../src/lib/database/user +replace example.com/database/user => ../../../src/modules/database/user replace example.com/test/testrequest => ../../lib/testrequest replace example.com/test/testsetup => ../../lib/testsetup -replace example.com/database/character => ../../../src/lib/database/character +replace example.com/database/character => ../../../src/modules/database/character -replace example.com/database/functionset => ../../../src/lib/database/functionset +replace example.com/database/functionset => ../../../src/modules/database/functionset -replace example.com/database/inventoryslot => ../../../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot -replace example.com/database/customization => ../../../src/lib/database/customization +replace example.com/database/customization => ../../../src/modules/database/customization -replace example.com/database/item => ../../../src/lib/database/item +replace example.com/database/item => ../../../src/modules/database/item -replace example.com/database/itemtag => ../../../src/lib/database/itemtag +replace example.com/database/itemtag => ../../../src/modules/database/itemtag -replace example.com/database/person => ../../../src/lib/database/person +replace example.com/database/person => ../../../src/modules/database/person -replace example.com/database/role => ../../../src/lib/database/role +replace example.com/database/role => ../../../src/modules/database/role -replace example.com/database/schematic => ../../../src/lib/database/schematic +replace example.com/database/schematic => ../../../src/modules/database/schematic -replace example.com/database/tier => ../../../src/lib/database/tier +replace example.com/database/tier => ../../../src/modules/database/tier -replace example.com/database/group => ../../../src/lib/database/group +replace example.com/database/group => ../../../src/modules/database/group -replace example.com/database/function => ../../../src/lib/database/function +replace example.com/database/function => ../../../src/modules/database/function -replace example.com/database/functiontag => ../../../src/lib/database/functiontag +replace example.com/database/functiontag => ../../../src/modules/database/functiontag -replace example.com/config/server => ../../../src/lib/config/server +replace example.com/config/server => ../../../src/modules/config/server -replace example.com/auth/discord => ../../../src/lib/auth/discord +replace example.com/auth/discord => ../../../src/modules/auth/discord require ( example.com/database/group v0.0.0 @@ -48,7 +48,6 @@ require ( example.com/test/testsetup v0.0.0 github.com/gin-gonic/gin v1.10.0 github.com/stretchr/testify v1.10.0 - gorm.io/gorm v1.25.12 ) require ( @@ -105,4 +104,5 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.7 // indirect + gorm.io/gorm v1.25.12 // indirect ) diff --git a/test/unit/grouptest/grouptest.go b/test/unit/grouptest/grouptest.go index ce3273d..430bbf3 100644 --- a/test/unit/grouptest/grouptest.go +++ b/test/unit/grouptest/grouptest.go @@ -10,7 +10,6 @@ import ( testsetup "example.com/test/testsetup" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" - "gorm.io/gorm" ) type TestGroup struct { @@ -29,9 +28,15 @@ type GroupTestSuite struct { func (s *GroupTestSuite) SetupTestSuite() { s.globalAuthHeader, s.router = testsetup.SetupTestSuite() // Create Test Data - s.group = group.Group{Model: gorm.Model{ID: 1}, Name: "test"} + fixtures, _ := os.ReadFile("fixtures/groups.json") + var groupFixtures struct { + Groups []group.Group `json:"groups"` + GroupUpdate group.Group `json:"group_update"` + } + json.Unmarshal(fixtures, &groupFixtures) + s.group = groupFixtures.Groups[0] s.groupJSON, _ = json.Marshal(s.group) - s.groupUpdate = group.Group{Model: gorm.Model{ID: 1}, Name: "another_test"} + s.groupUpdate = groupFixtures.GroupUpdate } func (s *GroupTestSuite) TearDownTestSuite() { diff --git a/test/unit/persontest/go.mod b/test/unit/persontest/go.mod index c9c51aa..e02ce66 100644 --- a/test/unit/persontest/go.mod +++ b/test/unit/persontest/go.mod @@ -2,11 +2,11 @@ module example.com/unit/persontest go 1.24.2 -replace example.com/api => ../../../src/lib/api +replace example.com/api => ../../../src/modules/api -replace example.com/database => ../../../src/lib/database +replace example.com/database => ../../../src/modules/database -replace example.com/database/user => ../../../src/lib/database/user +replace example.com/database/user => ../../../src/modules/database/user replace example.com/unit/grouptest => ../../unit/grouptest @@ -14,45 +14,43 @@ replace example.com/test/testrequest => ../../lib/testrequest replace example.com/test/testsetup => ../../lib/testsetup -replace example.com/database/character => ../../../src/lib/database/character +replace example.com/database/character => ../../../src/modules/database/character -replace example.com/database/functionset => ../../../src/lib/database/functionset +replace example.com/database/functionset => ../../../src/modules/database/functionset -replace example.com/database/inventoryslot => ../../../src/lib/database/inventoryslot +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot -replace example.com/database/customization => ../../../src/lib/database/customization +replace example.com/database/customization => ../../../src/modules/database/customization -replace example.com/database/item => ../../../src/lib/database/item +replace example.com/database/item => ../../../src/modules/database/item -replace example.com/database/itemtag => ../../../src/lib/database/itemtag +replace example.com/database/itemtag => ../../../src/modules/database/itemtag -replace example.com/database/person => ../../../src/lib/database/person +replace example.com/database/person => ../../../src/modules/database/person -replace example.com/database/role => ../../../src/lib/database/role +replace example.com/database/role => ../../../src/modules/database/role -replace example.com/database/schematic => ../../../src/lib/database/schematic +replace example.com/database/schematic => ../../../src/modules/database/schematic -replace example.com/database/tier => ../../../src/lib/database/tier +replace example.com/database/tier => ../../../src/modules/database/tier -replace example.com/database/group => ../../../src/lib/database/group +replace example.com/database/group => ../../../src/modules/database/group -replace example.com/database/function => ../../../src/lib/database/function +replace example.com/database/function => ../../../src/modules/database/function -replace example.com/database/functiontag => ../../../src/lib/database/functiontag +replace example.com/database/functiontag => ../../../src/modules/database/functiontag -replace example.com/config/server => ../../../src/lib/config/server +replace example.com/config/server => ../../../src/modules/config/server -replace example.com/auth/discord => ../../../src/lib/auth/discord +replace example.com/auth/discord => ../../../src/modules/auth/discord require ( - example.com/unit/grouptest v0.0.0 - example.com/database/group v0.0.0 example.com/database/person v0.0.0 example.com/test/testrequest v0.0.0 example.com/test/testsetup v0.0.0 + example.com/unit/grouptest v0.0.0 github.com/gin-gonic/gin v1.10.0 github.com/stretchr/testify v1.10.0 - gorm.io/gorm v1.25.12 ) require ( @@ -65,6 +63,7 @@ require ( example.com/database/function v0.0.0 // indirect example.com/database/functionset v0.0.0 // indirect example.com/database/functiontag v0.0.0 // indirect + example.com/database/group v0.0.0 // indirect example.com/database/inventoryslot v0.0.0 // indirect example.com/database/item v0.0.0 // indirect example.com/database/itemtag v0.0.0 // indirect @@ -108,4 +107,5 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/sqlite v1.5.7 // indirect + gorm.io/gorm v1.25.12 // indirect ) diff --git a/test/unit/persontest/persontest.go b/test/unit/persontest/persontest.go index 11577f6..fc593e1 100644 --- a/test/unit/persontest/persontest.go +++ b/test/unit/persontest/persontest.go @@ -5,14 +5,12 @@ import ( "fmt" "os" - group "example.com/database/group" person "example.com/database/person" testrequest "example.com/test/testrequest" testsetup "example.com/test/testsetup" grouptest "example.com/unit/grouptest" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" - "gorm.io/gorm" ) type TestPerson struct { @@ -32,27 +30,29 @@ type PersonTestSuite struct { func (s *PersonTestSuite) SetupTestSuite() { s.globalAuthHeader, s.router = testsetup.SetupTestSuite() // Create Test Data - testGroup := group.Group{ - Model: gorm.Model{ID: 1}, - Name: "one", + fixtures, _ := os.ReadFile("fixtures/persons.json") + var personFixtures struct { + Persons []person.Person `json:"persons"` + PersonUpdate person.Person `json:"person_update"` } - testGroups := []group.Group{} - var updatedGroups []group.Group - updatedGroups = append(updatedGroups, testGroup) - s.person = person.Person{ - Model: gorm.Model{ID: 2}, - Name: "another_test", - Groups: testGroups, + json.Unmarshal(fixtures, &personFixtures) + s.person = personFixtures.Persons[0] + var personGroupsIDs []uint + for _, group := range s.person.Groups { + personGroupsIDs = append(personGroupsIDs, group.ID) } - s.personJSON, _ = json.Marshal(s.person) - s.personUpdate = person.Person{ - Model: gorm.Model{ID: 2}, - Name: "yet_another_test", - Groups: updatedGroups, + s.personJSON, _ = json.Marshal(person.PersonParams{ + Name: s.person.Name, + Groups: personGroupsIDs, + }) + s.personUpdate = personFixtures.PersonUpdate + var personUpdateGroupsIDs []uint + for _, group := range s.personUpdate.Groups { + personUpdateGroupsIDs = append(personUpdateGroupsIDs, group.ID) } s.personUpdateJSON, _ = json.Marshal(person.PersonParams{ Name: s.personUpdate.Name, - Groups: []uint{1}, + Groups: personUpdateGroupsIDs, }) } @@ -74,6 +74,7 @@ func (s *PersonTestSuite) Test01CreatePerson() { body := testrequest.MakeGetRequest(target, s.router) // Unmarshal the result json.Unmarshal(body, &output) + fmt.Println(string(body)) // Check that the person listed matches the created person s.Equal(s.person.Name, output.Result[0].Name, "input name matches output name") } @@ -97,12 +98,15 @@ func (s *PersonTestSuite) Test03UpdatePerson() { // Create needed field objects var groupOutput grouptest.TestGroup - groupBody, _ := json.Marshal(s.personUpdate.Groups[0]) - groupStatus := testrequest.MakePostRequest(&groupBody, "/group", s.globalAuthHeader, s.router) - s.Equal(groupStatus, "200 OK", "group created successfully") - groupTarget := fmt.Sprintf("/group?id=%d", s.personUpdate.Groups[0].ID) - groupBody = testrequest.MakeGetRequest(groupTarget, s.router) - json.Unmarshal(groupBody, &groupOutput) + for _, group := range s.personUpdate.Groups { + groupBody, _ := json.Marshal(group) + groupStatus := testrequest.MakePostRequest(&groupBody, "/group", s.globalAuthHeader, s.router) + s.Equal(groupStatus, "200 OK", "group created successfully") + groupTarget := fmt.Sprintf("/group?id=%d", group.ID) + groupBody = testrequest.MakeGetRequest(groupTarget, s.router) + json.Unmarshal(groupBody, &groupOutput) + s.Equal(group.Name, groupOutput.Result[0].Name, "input group name matches output group name") + } // Attempt to update person status := testrequest.MakePutRequest(&s.personUpdateJSON, target, s.globalAuthHeader, s.router) diff --git a/test/unit/tiertest/go.mod b/test/unit/tiertest/go.mod new file mode 100644 index 0000000..ebcd3a6 --- /dev/null +++ b/test/unit/tiertest/go.mod @@ -0,0 +1,110 @@ +module example.com/unit/tiertest + +go 1.24.2 + +replace example.com/api => ../../../src/modules/api + +replace example.com/database => ../../../src/modules/database + +replace example.com/database/user => ../../../src/modules/database/user + +replace example.com/unit/functiontagtest => ../../unit/functiontagtest + +replace example.com/test/testrequest => ../../lib/testrequest + +replace example.com/test/testsetup => ../../lib/testsetup + +replace example.com/database/character => ../../../src/modules/database/character + +replace example.com/database/inventoryslot => ../../../src/modules/database/inventoryslot + +replace example.com/database/customization => ../../../src/modules/database/customization + +replace example.com/database/item => ../../../src/modules/database/item + +replace example.com/database/itemtag => ../../../src/modules/database/itemtag + +replace example.com/database/person => ../../../src/modules/database/person + +replace example.com/database/role => ../../../src/modules/database/role + +replace example.com/database/schematic => ../../../src/modules/database/schematic + +replace example.com/database/tier => ../../../src/modules/database/tier + +replace example.com/database/group => ../../../src/modules/database/group + +replace example.com/database/function => ../../../src/modules/database/function + +replace example.com/database/functiontag => ../../../src/modules/database/functiontag + +replace example.com/database/functionset => ../../../src/modules/database/functionset + +replace example.com/config/server => ../../../src/modules/config/server + +replace example.com/auth/discord => ../../../src/modules/auth/discord + +require ( + example.com/database/function v0.0.0 + example.com/database/functionset v0.0.0 + example.com/database/functiontag v0.0.0 + example.com/database/tier v0.0.0 + example.com/test/testrequest v0.0.0-00010101000000-000000000000 + example.com/test/testsetup v0.0.0-00010101000000-000000000000 + github.com/gin-gonic/gin v1.10.1 + github.com/stretchr/testify v1.10.0 + gorm.io/gorm v1.26.1 +) + +require ( + example.com/api v0.0.0-00010101000000-000000000000 // indirect + example.com/auth/discord v0.0.0 // indirect + example.com/config/server v0.0.0 // indirect + example.com/database v0.0.0-00010101000000-000000000000 // indirect + example.com/database/character v0.0.0 // indirect + example.com/database/customization v0.0.0 // indirect + example.com/database/group v0.0.0 // indirect + example.com/database/inventoryslot v0.0.0 // indirect + example.com/database/item v0.0.0 // indirect + example.com/database/itemtag v0.0.0 // indirect + example.com/database/person v0.0.0 // indirect + example.com/database/role v0.0.0 // indirect + example.com/database/schematic v0.0.0 // indirect + example.com/database/user v0.0.0 // indirect + github.com/bytedance/sonic v1.13.2 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gin-contrib/cors v1.7.5 // indirect + github.com/gin-contrib/sse v1.0.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.26.0 // indirect + github.com/goccy/go-json v0.10.5 // indirect + github.com/golang-jwt/jwt/v5 v5.2.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.10 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-sqlite3 v1.14.22 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + github.com/xyproto/randomstring v1.2.0 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/sqlite v1.5.7 // indirect +) diff --git a/test/unit/tiertest/go.sum b/test/unit/tiertest/go.sum new file mode 100644 index 0000000..7118f42 --- /dev/null +++ b/test/unit/tiertest/go.sum @@ -0,0 +1,111 @@ +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYMk= +github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0= +github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= +github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= +github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= +github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 h1:x3LgcvujjG+mx8PUMfPmwn3tcu2aA95uCB6ilGGObWk= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3/go.mod h1:P/mZMYLZ87lqRSECEWsOqywGrO1hlZkk9RTwEw35IP4= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/xyproto/randomstring v1.2.0 h1:y7PXAEBM3XlwJjPG2JQg4voxBYZ4+hPgRdGKCfU8wik= +github.com/xyproto/randomstring v1.2.0/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= +golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= +golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I= +gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= +gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw= +gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= diff --git a/test/unit/tiertest/tiertest.go b/test/unit/tiertest/tiertest.go new file mode 100644 index 0000000..a74bda7 --- /dev/null +++ b/test/unit/tiertest/tiertest.go @@ -0,0 +1,247 @@ +package tiertest + +import ( + "encoding/json" + "fmt" + "os" + + function "example.com/database/function" + functionset "example.com/database/functionset" + "example.com/database/functiontag" + tier "example.com/database/tier" + testrequest "example.com/test/testrequest" + testsetup "example.com/test/testsetup" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/suite" + "gorm.io/gorm" +) + +type TestTier struct { + Result []tier.Tier `json:"result"` +} + +type TierTestSuite struct { + suite.Suite + globalAuthHeader string + router *gin.Engine + tier tier.Tier + tierJSON []byte + tierUpdate tier.Tier + tierUpdateJSON []byte +} + +func (s *TierTestSuite) SetupTestSuite() { + s.globalAuthHeader, s.router = testsetup.SetupTestSuite() + // Create Test Data + testFunctionTag1 := functiontag.FunctionTag{ + Model: gorm.Model{ID: 1}, + Name: "tag1", + } + testFunctionTag2 := functiontag.FunctionTag{ + Model: gorm.Model{ID: 2}, + Name: "tag2", + } + testFunctionTag3 := functiontag.FunctionTag{ + Model: gorm.Model{ID: 3}, + Name: "tag3", + } + testFunction1 := function.Function{ + Model: gorm.Model{ID: 1}, + Name: "function1", + Tags: []functiontag.FunctionTag{ + testFunctionTag1, + testFunctionTag2, + }, + Requirements: []function.Function{}, + } + testFunction1JSON, _ := json.Marshal(function.FunctionParams{ + Name: testFunction1.Name, + Tags: []uint{ + testFunctionTag1.ID, + testFunctionTag2.ID, + }, + Requirements: []uint{}, + }) + testFunction2 := function.Function{ + Model: gorm.Model{ID: 2}, + Name: "function2", + Tags: []functiontag.FunctionTag{}, + Requirements: []function.Function{ + testFunction1, + }, + } + testFunction2JSON, _ := json.Marshal(function.FunctionParams{ + Name: testFunction2.Name, + Tags: []uint{}, + Requirements: []uint{ + testFunction1.ID, + }, + }) + testFunction3 := function.Function{ + Model: gorm.Model{ID: 3}, + Name: "function3", + Tags: []functiontag.FunctionTag{ + testFunctionTag2, + testFunctionTag3, + }, + Requirements: []function.Function{ + testFunction1, + testFunction2, + }, + } + testFunction3JSON, _ := json.Marshal(function.FunctionParams{ + Name: testFunction3.Name, + Tags: []uint{ + testFunctionTag2.ID, + testFunctionTag3.ID, + }, + Requirements: []uint{ + testFunction1.ID, + testFunction2.ID, + }, + }) + testFunctionSet1 := functionset.FunctionSet{ + Model: gorm.Model{ID: 1}, + Functions: []function.Function{ + testFunction1, + testFunction2, + }, + } + testFunctionSet1JSON, _ := json.Marshal(functionset.FunctionSetParams{ + Functions: []uint{ + testFunction1.ID, + testFunction2.ID, + }, + }) + testFunctionSet2 := functionset.FunctionSet{ + Model: gorm.Model{ID: 2}, + Functions: []function.Function{ + testFunction2, + testFunction3, + }, + } + testFunctionSet2JSON, _ := json.Marshal(functionset.FunctionSetParams{ + Functions: []uint{ + testFunction2.ID, + testFunction3.ID, + }, + }) + // Set Test Variables + s.tier = tier.Tier{ + Model: gorm.Model{ID: 1}, + FunctionSets: []functionset.FunctionSet{ + testFunctionSet1, + }, + } + s.tierJSON, _ = json.Marshal(tier.TierParams{ + FunctionSets: []uint{ + testFunctionSet1.ID, + }, + }) + s.tierUpdate = tier.Tier{ + Model: gorm.Model{ID: 1}, + FunctionSets: []functionset.FunctionSet{ + testFunctionSet2, + }, + } + s.tierUpdateJSON, _ = json.Marshal(tier.TierParams{ + FunctionSets: []uint{ + testFunctionSet2.ID, + }, + }) + // Setup variables + var target string + var body []byte + target = "/function-tag" + // Setup variables + body, _ = json.Marshal(testFunctionTag1) + // Attempt to create function tag 1 + testrequest.MakePostRequest(&body, target, s.globalAuthHeader, s.router) + // Setup variables + body, _ = json.Marshal(testFunctionTag2) + // Attempt to create function tag 2 + testrequest.MakePostRequest(&body, target, s.globalAuthHeader, s.router) + // Setup variables + body, _ = json.Marshal(testFunctionTag3) + // Attempt to create function tag 3 + testrequest.MakePostRequest(&body, target, s.globalAuthHeader, s.router) + target = "/function" + // Attempt to create function 1 + testrequest.MakePostRequest(&testFunction1JSON, target, s.globalAuthHeader, s.router) + // Attempt to create function 2 + testrequest.MakePostRequest(&testFunction2JSON, target, s.globalAuthHeader, s.router) + // Attempt to create function 3 + testrequest.MakePostRequest(&testFunction3JSON, target, s.globalAuthHeader, s.router) + target = "/function-set" + // Attempt to create function set 1 + testrequest.MakePostRequest(&testFunctionSet1JSON, target, s.globalAuthHeader, s.router) + // Attempt to create function set 2 + testrequest.MakePostRequest(&testFunctionSet2JSON, target, s.globalAuthHeader, s.router) +} + +func (s *TierTestSuite) TearDownTestSuite() { + os.Remove("db/main.db") +} + +func (s *TierTestSuite) Test01CreateTier() { + // Setup variables + var output TestTier + target := fmt.Sprintf("/tier?id=%d", s.tier.ID) + + // Attempt to create tier + status := testrequest.MakePostRequest(&s.tierJSON, "/tier", s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "function created successfully") + + // Attempt to get tier + body := testrequest.MakeGetRequest(target, s.router) + json.Unmarshal(body, &output) + fmt.Println(string(body)) + // Check that the tier listed matches the created tier + s.Equal(s.tier.FunctionSets[0].ID, output.Result[0].FunctionSets[0].ID, "input tier exists and function set id matches output function set id") +} + +func (s *TierTestSuite) Test02GetTier() { + // Setup variables + var output TestTier + + // Attempt to get tiers + body := testrequest.MakeGetRequest("/tier", s.router) + json.Unmarshal(body, &output) + // Check that the tiers listed match the created tiers + s.Equal(s.tier.FunctionSets[0].ID, output.Result[0].FunctionSets[0].ID, "input tier exists and function set id matches output function set id") +} + +func (s *TierTestSuite) Test03UpdateTier() { + // Setup variables + var output TestTier + target := fmt.Sprintf("/tier?id=%d", s.tier.ID) + + // Attempt to update tier + status := testrequest.MakePutRequest(&s.tierUpdateJSON, target, s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "tier created successfully") + + // Attempt to get tier + body := testrequest.MakeGetRequest(target, s.router) + json.Unmarshal(body, &output) + // Check that the tier listed matches the updated function + s.Equal(s.tierUpdate.FunctionSets[0].ID, output.Result[0].FunctionSets[0].ID, "updated tier function set id matches output function set id") +} + +func (s *TierTestSuite) Test04DeleteTier() { + // Setup variables + var output TestTier + target := fmt.Sprintf("/tier?id=%d", s.tier.ID) + + // Attempt to delete tier + status := testrequest.MakeDeleteRequest(target, s.globalAuthHeader, s.router) + // Check that the request was successful + s.Equal(status, "200 OK", "function deleted successfully") + + // Attempt to get tier + body := testrequest.MakeGetRequest("/tier", s.router) + json.Unmarshal(body, &output) + // Check that the tier list is empty + s.Equal(0, len(output.Result), "tier list is empty") +}