Fix: unittests
This commit is contained in:
		| @@ -4,6 +4,8 @@ import ( | ||||
| 	"context" | ||||
| 	"gralias/models" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jmoiron/sqlx" | ||||
| ) | ||||
|  | ||||
| type ActionsRepo interface { | ||||
| @@ -15,7 +17,7 @@ type ActionsRepo interface { | ||||
|  | ||||
| func (p *RepoProvider) ListActions(ctx context.Context, roomID string) ([]models.Action, error) { | ||||
| 	actions := []models.Action{} | ||||
| 	err := p.DB.SelectContext(ctx, &actions, `SELECT actor, actor_color, action_type, word, word_color, number_associated, created_at FROM actions WHERE room_id = ? ORDER BY created_at ASC`, roomID) | ||||
| 	err := sqlx.SelectContext(ctx, p.DB, &actions, `SELECT actor, actor_color, action_type, word, word_color, number_associated, created_at FROM actions WHERE room_id = ? ORDER BY created_at ASC`, roomID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -26,13 +28,14 @@ func (p *RepoProvider) ListActions(ctx context.Context, roomID string) ([]models | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) CreateAction(ctx context.Context, roomID string, a *models.Action) error { | ||||
| 	_, err := p.DB.ExecContext(ctx, `INSERT INTO actions (room_id, actor, actor_color, action_type, word, word_color, number_associated, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, roomID, a.Actor, a.ActorColor, a.Action, a.Word, a.WordColor, a.Number, a.CreatedAt.UnixNano()) | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `INSERT INTO actions (room_id, actor, actor_color, action_type, word, word_color, number_associated, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, roomID, a.Actor, a.ActorColor, a.Action, a.Word, a.WordColor, a.Number, a.CreatedAt.UnixNano()) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) GetLastClue(ctx context.Context, roomID string) (*models.Action, error) { | ||||
| 	action := &models.Action{} | ||||
| 	err := p.DB.GetContext(ctx, action, `SELECT actor, actor_color, action_type, word, word_color, number_associated, created_at FROM actions WHERE room_id = ? AND action_type = 'gave_clue' ORDER BY created_at DESC LIMIT 1`, roomID) | ||||
| 	err := sqlx.GetContext(ctx, p.DB, action, `SELECT actor, actor_color, action_type, word, word_color, number_associated, created_at FROM actions WHERE room_id = ? AND action_type = 'gave_clue' ORDER BY created_at DESC LIMIT 1`, roomID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -41,6 +44,7 @@ func (p *RepoProvider) GetLastClue(ctx context.Context, roomID string) (*models. | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) DeleteActionsByRoomID(ctx context.Context, roomID string) error { | ||||
| 	_, err := p.DB.ExecContext(ctx, `DELETE FROM actions WHERE room_id = ?`, roomID) | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `DELETE FROM actions WHERE room_id = ?`, roomID) | ||||
| 	return err | ||||
| } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder