MCPcopy Index your code
hub / github.com/coder/coder / TestService_IsEnabled

Function TestService_IsEnabled

coderd/x/chatd/chatdebug/service_test.go:37–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func 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
75func TestService_IsEnabled_AlwaysEnable(t *testing.T) {
76 t.Parallel()

Callers

nothing calls this directly

Calls 8

IsEnabledMethod · 0.95
ContextFunction · 0.92
NewDBWithSQLDBFunction · 0.92
NewServiceFunction · 0.92
LoggerFunction · 0.92
seedChatFunction · 0.85

Tested by

no test coverage detected