Fix: unittests
This commit is contained in:
		| @@ -3,6 +3,8 @@ package repos | ||||
| import ( | ||||
| 	"context" | ||||
| 	"gralias/models" | ||||
|  | ||||
| 	"github.com/jmoiron/sqlx" | ||||
| ) | ||||
|  | ||||
| type RoomsRepo interface { | ||||
| @@ -16,7 +18,7 @@ type RoomsRepo interface { | ||||
|  | ||||
| func (p *RepoProvider) RoomList(ctx context.Context) ([]*models.Room, error) { | ||||
| 	rooms := []*models.Room{} | ||||
| 	err := p.DB.SelectContext(ctx, &rooms, `SELECT * FROM rooms`) | ||||
| 	err := sqlx.SelectContext(ctx, p.DB, &rooms, `SELECT * FROM rooms`) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -25,37 +27,58 @@ func (p *RepoProvider) RoomList(ctx context.Context) ([]*models.Room, error) { | ||||
|  | ||||
| func (p *RepoProvider) RoomGetByID(ctx context.Context, id string) (*models.Room, error) { | ||||
| 	room := &models.Room{} | ||||
| 	err := p.DB.GetContext(ctx, room, `SELECT * FROM rooms WHERE id = ?`, id) | ||||
| 	err := sqlx.GetContext(ctx, p.DB, room, `SELECT * FROM rooms WHERE id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	settings := &models.GameSettings{} | ||||
| 	err = sqlx.GetContext(ctx, p.DB, settings, `SELECT * FROM settings WHERE room_id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	room.Settings = *settings | ||||
| 	return room, nil | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) RoomCreate(ctx context.Context, r *models.Room) error { | ||||
| 	_, err := p.DB.ExecContext(ctx, `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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.ID, r.CreatedAt, r.CreatorName, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.IsOver, r.TeamWon, r.RoomLink) | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.ID, r.CreatedAt, r.CreatorName, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.IsOver, r.TeamWon, r.RoomLink) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = db.ExecContext(ctx, `INSERT INTO settings (room_id, language, room_pass, turn_time) VALUES (?, ?, ?, ?)`, r.ID, r.Settings.Language, r.Settings.RoomPass, r.Settings.RoundTime) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) RoomDeleteByID(ctx context.Context, id string) error { | ||||
| 	_, err := p.DB.ExecContext(ctx, `DELETE FROM rooms WHERE id = ?`, id) | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `DELETE FROM rooms WHERE id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = db.ExecContext(ctx, `DELETE FROM settings WHERE room_id = ?`, id) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) RoomUpdate(ctx context.Context, r *models.Room) error { | ||||
| 	_, err := p.DB.ExecContext(ctx, `UPDATE rooms SET team_turn = ?, this_turn_limit = ?, opened_this_turn = ?, blue_counter = ?, red_counter = ?, red_turn = ?, mime_done = ?,  = ?, is_running = ?, is_over = ?, team_won = ?, room_link = ? WHERE id = ?`, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.IsOver, r.TeamWon, r.RoomLink, r.ID) | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `UPDATE rooms SET team_turn = ?, this_turn_limit = ?, opened_this_turn = ?, blue_counter = ?, red_counter = ?, red_turn = ?, mime_done = ?, is_running = ?, is_over = ?, team_won = ?, room_link = ? WHERE id = ?`, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.IsOver, r.TeamWon, r.RoomLink, r.ID) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = db.ExecContext(ctx, `UPDATE settings SET language = ?, room_pass = ?, turn_time = ? WHERE room_id = ?`, r.Settings.Language, r.Settings.RoomPass, r.Settings.RoundTime, r.ID) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models.Room, error) { | ||||
| 	room := &models.Room{} | ||||
| 	err := p.DB.GetContext(ctx, room, `SELECT * FROM rooms WHERE id = ?`, id) | ||||
| 	err := sqlx.GetContext(ctx, p.DB, room, `SELECT * FROM rooms WHERE id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	// Get players | ||||
| 	players := []*models.Player{} | ||||
| 	err = p.DB.SelectContext(ctx, &players, `SELECT * FROM players WHERE room_id = ?`, id) | ||||
| 	err = sqlx.SelectContext(ctx, p.DB, &players, `SELECT * FROM players WHERE room_id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -87,21 +110,21 @@ func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models. | ||||
| 	} | ||||
| 	// Get word cards | ||||
| 	wordCards := []models.WordCard{} | ||||
| 	err = p.DB.SelectContext(ctx, &wordCards, `SELECT * FROM word_cards WHERE room_id = ?`, id) | ||||
| 	err = sqlx.SelectContext(ctx, p.DB, &wordCards, `SELECT * FROM word_cards WHERE room_id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	room.Cards = wordCards | ||||
| 	// Get actions | ||||
| 	actions := []models.Action{} | ||||
| 	err = p.DB.SelectContext(ctx, &actions, `SELECT * FROM actions WHERE room_id = ? ORDER BY created_at ASC`, id) | ||||
| 	err = sqlx.SelectContext(ctx, p.DB, &actions, `SELECT * FROM actions WHERE room_id = ? ORDER BY created_at ASC`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	room.ActionHistory = actions | ||||
| 	// Get settings | ||||
| 	settings := &models.GameSettings{} | ||||
| 	err = p.DB.GetContext(ctx, settings, `SELECT * FROM settings WHERE room_id = ?`, id) | ||||
| 	err = sqlx.GetContext(ctx, p.DB, settings, `SELECT * FROM settings WHERE room_id = ?`, id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder