diff --git a/Backend/cmd/migrate/game_card_seeder.go b/Backend/cmd/migrate/game_card_seeder.go index 9677b20..768c094 100644 --- a/Backend/cmd/migrate/game_card_seeder.go +++ b/Backend/cmd/migrate/game_card_seeder.go @@ -10,5 +10,5 @@ import ( func main() { db := config.NewDatabase() - seeders.Run(db) + seeders.OnlyCardsRun(db) } diff --git a/Backend/cmd/migrate/game_seeder.go b/Backend/cmd/migrate/game_seeder.go new file mode 100644 index 0000000..9677b20 --- /dev/null +++ b/Backend/cmd/migrate/game_seeder.go @@ -0,0 +1,14 @@ +//go:build migrate + +package main + +import ( + "github.com/Game-as-a-Service/The-Message/config" + "github.com/Game-as-a-Service/The-Message/database/seeders" + _ "github.com/joho/godotenv/autoload" +) + +func main() { + db := config.NewDatabase() + seeders.Run(db) +} diff --git a/Backend/database/seeders/database_seeder.go b/Backend/database/seeders/database_seeder.go index 6ee14a4..1b970ae 100644 --- a/Backend/database/seeders/database_seeder.go +++ b/Backend/database/seeders/database_seeder.go @@ -6,4 +6,9 @@ import ( func Run(db *gorm.DB) { SeederCards(db) + SeederGameWithPlayers(db) +} + +func OnlyCardsRun(db *gorm.DB) { + SeederCards(db) } diff --git a/Backend/database/seeders/game_seeder.go b/Backend/database/seeders/game_seeder.go new file mode 100644 index 0000000..99b25b4 --- /dev/null +++ b/Backend/database/seeders/game_seeder.go @@ -0,0 +1,46 @@ +package seeders + +import ( + "math/rand" + + "github.com/Game-as-a-Service/The-Message/enums" + "github.com/Game-as-a-Service/The-Message/service/repository" + "github.com/go-faker/faker/v4" + "gorm.io/gorm" +) + +func SeederGameWithPlayers(db *gorm.DB) { + // Get all cards + var cards []*repository.Card + _ = db.Find(&cards) + + // Fake game data + game := &repository.Game{ + RoomID: faker.UUIDDigit(), + Status: enums.ActionCardStage, + Players: []repository.Player{}, + } + + // Fake player count random 1~3 + playerCount := rand.Intn(3) + 1 + + // Fake players data + for i := 0; i < playerCount; i++ { + player := repository.Player{ + UserID: faker.UUIDDigit(), + Name: faker.FirstName(), + PlayerCards: []repository.PlayerCard{}, + } + + // Each player gets 3 cards + for j := 0; j < 3; j++ { + player.PlayerCards = append(player.PlayerCards, repository.PlayerCard{ + CardID: cards[i*3+j].ID, + Type: "hand", + }) + } + game.Players = append(game.Players, player) + } + + _ = db.Create(&game) +} diff --git a/Backend/tests/e2e/suite_test.go b/Backend/tests/e2e/suite_test.go index a2f70d9..ecaab09 100644 --- a/Backend/tests/e2e/suite_test.go +++ b/Backend/tests/e2e/suite_test.go @@ -166,7 +166,7 @@ func (suite *IntegrationTestSuite) SetupTest() { //Fixme Run db refresh and seeders config.RunRefresh() db := config.NewDatabase() - seeders.Run(db) + seeders.OnlyCardsRun(db) } func (suite *IntegrationTestSuite) TearDownTest() {