(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func TestService_IsEnabled(t *testing.T) { |
| 38 | t.Parallel() |
| 39 | |
| 40 | ctx := testutil.Context(t, testutil.WaitLong) |
| 41 | db, _, _ := dbtestutil.NewDBWithSQLDB(t) |
| 42 | _, owner, chat, model := seedChat(t, db) |
| 43 | require.NotEqual(t, uuid.Nil, model.ID) |
| 44 | |
| 45 | svc := chatdebug.NewService(db, testutil.Logger(t), nil) |
| 46 | |
| 47 | // Default is off until an admin allows user opt-in. |
| 48 | require.False(t, svc.IsEnabled(ctx, chat.ID, owner.ID)) |
| 49 | |
| 50 | err := db.UpsertChatDebugLoggingAllowUsers(ctx, true) |
| 51 | require.NoError(t, err) |
| 52 | // Allowing user opt-in is not enough on its own; the user must opt in. |
| 53 | require.False(t, svc.IsEnabled(ctx, chat.ID, owner.ID)) |
| 54 | require.False(t, svc.IsEnabled(ctx, chat.ID, uuid.Nil)) |
| 55 | |
| 56 | err = db.UpsertUserChatDebugLoggingEnabled(ctx, |
| 57 | database.UpsertUserChatDebugLoggingEnabledParams{ |
| 58 | UserID: owner.ID, |
| 59 | DebugLoggingEnabled: true, |
| 60 | }, |
| 61 | ) |
| 62 | require.NoError(t, err) |
| 63 | require.True(t, svc.IsEnabled(ctx, chat.ID, owner.ID)) |
| 64 | |
| 65 | err = db.UpsertUserChatDebugLoggingEnabled(ctx, |
| 66 | database.UpsertUserChatDebugLoggingEnabledParams{ |
| 67 | UserID: owner.ID, |
| 68 | DebugLoggingEnabled: false, |
| 69 | }, |
| 70 | ) |
| 71 | require.NoError(t, err) |
| 72 | require.False(t, svc.IsEnabled(ctx, chat.ID, owner.ID)) |
| 73 | } |
| 74 | |
| 75 | func TestService_IsEnabled_AlwaysEnable(t *testing.T) { |
| 76 | t.Parallel() |
nothing calls this directly
no test coverage detected