diff --git a/backend/internal/database/migrate.go b/backend/internal/database/migrate.go index cb158521..fabc4d3b 100644 --- a/backend/internal/database/migrate.go +++ b/backend/internal/database/migrate.go @@ -116,6 +116,10 @@ func MigrateSteps(dbURL string, migrationsPath string, steps int) error { // RollbackMigrations rolls back all migrations (drops all tables). func RollbackMigrations(dbURL string, migrationsPath string) error { + if migrationsPath == "" { + return errors.New("migrations path is required") + } + m, err := migrate.New( fmt.Sprintf("file://%s", migrationsPath), dbURL, diff --git a/backend/internal/repository/captain_inbox_repo_test.go b/backend/internal/repository/captain_inbox_repo_test.go index e19b5312..406c89ab 100644 --- a/backend/internal/repository/captain_inbox_repo_test.go +++ b/backend/internal/repository/captain_inbox_repo_test.go @@ -34,6 +34,17 @@ func TestCaptainInboxRepo_Create(t *testing.T) { assert.Equal(t, uint(100), ci.AccountID) } +func TestCaptainInboxRepo_Create_OnlyOneActiveAssistantPerInbox(t *testing.T) { + db := setupTestDB(t, &model.CaptainInbox{}) + repo := NewCaptainInboxRepo(db) + ctx := context.Background() + + require.NoError(t, repo.Create(ctx, newTestCaptainInbox(1, 10, 100))) + require.Error(t, repo.Create(ctx, newTestCaptainInbox(2, 10, 100))) + require.NoError(t, repo.Delete(ctx, 1, 10)) + require.NoError(t, repo.Create(ctx, newTestCaptainInbox(2, 10, 100))) +} + // ========== Delete ========== func TestCaptainInboxRepo_Delete(t *testing.T) {