Skip to content

Commit

Permalink
feat(server): missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniloMurer committed Nov 19, 2024
1 parent 6f5fb4d commit 92a0956
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
54 changes: 27 additions & 27 deletions server/internal/triffgonix/api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package api

import (
"github.com/google/uuid"
"net/http/httptest"
"server/internal/triffgonix/database"
"server/internal/triffgonix/models"
"testing"
"github.com/google/uuid"
"net/http/httptest"
"server/internal/triffgonix/database"
"server/internal/triffgonix/models"
"testing"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)

func TestCreatePlayer(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/api/user", nil)
router.ServeHTTP(w, req)
router := setupRouter()
w := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/api/user", nil)
router.ServeHTTP(w, req)

assert.Equal(t, 400, w.Code)
assert.Equal(t, 400, w.Code)
}

func setupRouter() *gin.Engine {
gin.SetMode(gin.TestMode)
r := gin.Default()
group := r.Group("/api")
{
group.POST("/user", CreatePlayer)
group.GET("/user", GetPlayers)
group.POST("/game", CreateGame)
group.GET("/game", GetGames)
}
return r
gin.SetMode(gin.TestMode)
r := gin.Default()
group := r.Group("/api")
{
group.POST("/user", CreatePlayer)
group.GET("/user", GetPlayers)
group.POST("/game", CreateGame)
group.GET("/game", GetGames)
}
return r
}

func TestDatabaseConnections(t *testing.T) {
database.AutoMigrate()
err, _ := database.CreatePlayer(&models.Player{PlayerName: uuid.Must(uuid.NewRandom()).String()})
assert.Nil(t, err)
games := database.FindAllGames()
assert.NotNil(t, games)
database.AutoMigrate()
err, _ := database.CreatePlayer(&models.Player{PlayerName: uuid.Must(uuid.NewRandom()).String()})
assert.Nil(t, err)
games := database.FindAllGames()
assert.NotNil(t, games)
}
30 changes: 15 additions & 15 deletions server/internal/triffgonix/database/database_test.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package database

import (
"github.com/google/uuid"
"server/internal/triffgonix/models"
"testing"
"github.com/google/uuid"
"server/internal/triffgonix/models"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)

func TestAutoMigrate(t *testing.T) {
assert.NotPanics(t, AutoMigrate)
assert.NotPanics(t, AutoMigrate)
}

func TestCreatePlayer(t *testing.T) {
player := &models.Player{PlayerName: uuid.Must(uuid.NewRandom()).String()}
err, _ := CreatePlayer(player)
assert.Nil(t, err)
player := &models.Player{PlayerName: uuid.Must(uuid.NewRandom()).String()}
err, _ := CreatePlayer(player)
assert.Nil(t, err)
}

func TestFindAllUsers(t *testing.T) {
users := FindAllUsers()
assert.NotNil(t, users)
users := FindAllUsers()
assert.NotNil(t, users)
}

func TestCreateGame(t *testing.T) {
game := &models.Game{Name: "Test Game"}
err, _ := CreateGame(game)
assert.Nil(t, err)
game := &models.Game{Name: "Test Game"}
err, _ := CreateGame(game)
assert.Nil(t, err)
}

func TestFindAllGames(t *testing.T) {
games := FindAllGames()
assert.NotNil(t, games)
games := FindAllGames()
assert.NotNil(t, games)
}

0 comments on commit 92a0956

Please sign in to comment.