Feat: card_mark repo
This commit is contained in:
		| @@ -7,8 +7,8 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jmoiron/sqlx" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	_ "github.com/mattn/go-sqlite3" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func setupTestDB(t *testing.T) (*sqlx.DB, func()) { | ||||
| @@ -181,9 +181,9 @@ func TestRoomsRepo_GetRoomByID(t *testing.T) { | ||||
| 	} | ||||
|  | ||||
| 	// Insert a room directly into the database for testing GetRoomByID | ||||
| 	_, err = db.Exec(`INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, is_over, team_won, room_link) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, room.ID, room.CreatedAt, room.CreatorName, room.TeamTurn, room.ThisTurnLimit, room.OpenedThisTurn, room.BlueCounter, room.RedCounter, room.RedTurn, room.MimeDone, room.IsRunning, room.IsOver, room.TeamWon, room.RoomLink) | ||||
| 	_, err := db.Exec(`INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, is_over, team_won, room_link) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, room.ID, room.CreatedAt, room.CreatorName, room.TeamTurn, room.ThisTurnLimit, room.OpenedThisTurn, room.BlueCounter, room.RedCounter, room.RedTurn, room.MimeDone, room.IsRunning, room.IsOver, room.TeamWon, room.RoomLink) | ||||
| 	assert.NoError(t, err) | ||||
| 		_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime) | ||||
| 	_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	retrievedRoom, err := repo.RoomGetByID(context.Background(), room.ID) | ||||
| @@ -288,7 +288,7 @@ func TestRoomsRepo_DeleteRoomByID(t *testing.T) { | ||||
|  | ||||
| 	_, err := db.Exec(`INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, is_over, team_won, room_link) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, room.ID, room.CreatedAt, room.CreatorName, room.TeamTurn, room.ThisTurnLimit, room.OpenedThisTurn, room.BlueCounter, room.RedCounter, room.RedTurn, room.MimeDone, room.IsRunning, room.IsOver, room.TeamWon, room.RoomLink) | ||||
| 	assert.NoError(t, err) | ||||
| 		_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime, room.Settings.TurnSecondsLeft) | ||||
| 	_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	// Insert a word card for the room | ||||
| @@ -347,21 +347,19 @@ func TestRoomsRepo_UpdateRoom(t *testing.T) { | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	_, err := db.Exec(`INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, is_over, team_won, room_link) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, room.ID, room.CreatedAt, room.CreatorName, room.TeamTurn, room.ThisTurnLimit, room.OpenedThisTurn, room.BlueCounter, room.RedCounter, room.RedTurn, room.MimeDone, room.IsRunning, room.IsOver, room.TeamWon, room.RoomLink) | ||||
| 	var err error | ||||
| 	_, err = db.Exec(`INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, is_over, team_won, room_link) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, room.ID, room.CreatedAt, room.CreatorName, room.TeamTurn, room.ThisTurnLimit, room.OpenedThisTurn, room.BlueCounter, room.RedCounter, room.RedTurn, room.MimeDone, room.IsRunning, room.IsOver, room.TeamWon, room.RoomLink) | ||||
| 	assert.NoError(t, err) | ||||
| 		_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime, room.Settings.TurnSecondsLeft) | ||||
| 	_, err = db.Exec(`INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?)`, room.ID, room.Settings.Language, room.Settings.RoomPass, room.Settings.RoundTime) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	room.TeamTurn = "red" | ||||
| 	room.BlueCounter = 10 | ||||
| 	room.Settings.RoundTime = 120 | ||||
| 	 | ||||
|  | ||||
| 	err = repo.RoomUpdate(context.Background(), room) | ||||
| 	assert.NoError(t, err) | ||||
|  | ||||
| 	 | ||||
|  | ||||
| 	var updatedRoom models.Room | ||||
| 	err = db.Get(&updatedRoom, "SELECT * FROM rooms WHERE id = ?", room.ID) | ||||
| 	assert.NoError(t, err) | ||||
| @@ -371,6 +369,6 @@ func TestRoomsRepo_UpdateRoom(t *testing.T) { | ||||
| 	var updatedSettings models.GameSettings | ||||
| 	err = db.Get(&updatedSettings, "SELECT * FROM settings WHERE room_id = ?", room.ID) | ||||
| 	assert.NoError(t, err) | ||||
| 	assert.Equal(t, uint32(120), updatedSettings.RoundTime) | ||||
| 	assert.Equal(t, uint32(30), updatedSettings.TurnSecondsLeft) | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder