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

Function TestChatTemplateAllowlist

coderd/exp_chats_test.go:13511–13636  ·  view source on GitHub ↗

nolint:tparallel // Subtests share a single coderdtest instance and run sequentially.

(t *testing.T)

Source from the content-addressed store, hash-verified

13509
13510//nolint:tparallel // Subtests share a single coderdtest instance and run sequentially.
13511func TestChatTemplateAllowlist(t *testing.T) {
13512 t.Parallel()
13513
13514 // Shared setup: one coderdtest instance with two real templates.
13515 // Subtests that need valid template IDs use these.
13516 client, store := newChatClientWithDatabase(t)
13517 admin := coderdtest.CreateFirstUser(t, client.Client)
13518 tmpl1 := dbgen.Template(t, store, database.Template{
13519 OrganizationID: admin.OrganizationID,
13520 CreatedBy: admin.UserID,
13521 })
13522 tmpl2 := dbgen.Template(t, store, database.Template{
13523 OrganizationID: admin.OrganizationID,
13524 CreatedBy: admin.UserID,
13525 })
13526 deprecatedTmpl := dbgen.Template(t, store, database.Template{
13527 OrganizationID: admin.OrganizationID,
13528 CreatedBy: admin.UserID,
13529 })
13530 //nolint:gocritic // Owner context needed to deprecate the template in test setup.
13531 ownerRoles, err := rbac.RoleIdentifiers{rbac.RoleOwner()}.Expand()
13532 require.NoError(t, err)
13533 err = store.UpdateTemplateAccessControlByID(dbauthz.As(context.Background(), rbac.Subject{
13534 ID: "owner",
13535 Roles: rbac.Roles(ownerRoles),
13536 Scope: rbac.ExpandableScope(rbac.ScopeAll),
13537 }), database.UpdateTemplateAccessControlByIDParams{
13538 ID: deprecatedTmpl.ID,
13539 Deprecated: "this template is deprecated",
13540 })
13541 require.NoError(t, err, "deprecate template")
13542
13543 //nolint:paralleltest // Sequential: subtests share a single coderdtest instance.
13544 t.Run("ReturnsEmptyWhenUnset", func(t *testing.T) {
13545 ctx := testutil.Context(t, testutil.WaitLong)
13546 resp, err := client.GetChatTemplateAllowlist(ctx)
13547 require.NoError(t, err)
13548 require.Empty(t, resp.TemplateIDs)
13549 })
13550
13551 //nolint:paralleltest // Sequential: subtests share a single coderdtest instance.
13552 t.Run("AdminCanSet", func(t *testing.T) {
13553 ctx := testutil.Context(t, testutil.WaitLong)
13554 ids := []string{tmpl1.ID.String(), tmpl2.ID.String()}
13555 err := client.UpdateChatTemplateAllowlist(ctx, codersdk.ChatTemplateAllowlist{TemplateIDs: ids})
13556 require.NoError(t, err)
13557 resp, err := client.GetChatTemplateAllowlist(ctx)
13558 require.NoError(t, err)
13559 require.ElementsMatch(t, ids, resp.TemplateIDs)
13560 })
13561
13562 //nolint:paralleltest // Sequential: subtests share a single coderdtest instance.
13563 t.Run("AdminCanClear", func(t *testing.T) {
13564 ctx := testutil.Context(t, testutil.WaitLong)
13565 err := client.UpdateChatTemplateAllowlist(ctx, codersdk.ChatTemplateAllowlist{TemplateIDs: []string{}})
13566 require.NoError(t, err)
13567 resp, err := client.GetChatTemplateAllowlist(ctx)
13568 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

CreateFirstUserFunction · 0.92
TemplateFunction · 0.92
RoleOwnerFunction · 0.92
AsFunction · 0.92
RolesTypeAlias · 0.92
ExpandableScopeInterface · 0.92
ContextFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected