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

Function TestUserAutofillParameters

coderd/users_test.go:2825–2946  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2823}
2824
2825func TestUserAutofillParameters(t *testing.T) {
2826 t.Parallel()
2827 t.Run("NotSelf", func(t *testing.T) {
2828 t.Parallel()
2829 client1, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{})
2830
2831 u1 := coderdtest.CreateFirstUser(t, client1)
2832
2833 client2, u2 := coderdtest.CreateAnotherUser(t, client1, u1.OrganizationID)
2834
2835 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2836 defer cancel()
2837
2838 db := api.Database
2839
2840 version := dbfake.TemplateVersion(t, db).Seed(database.TemplateVersion{
2841 CreatedBy: u1.UserID,
2842 OrganizationID: u1.OrganizationID,
2843 }).Params(database.TemplateVersionParameter{
2844 Name: "param",
2845 Required: true,
2846 }).Do()
2847
2848 _, err := client2.UserAutofillParameters(
2849 ctx,
2850 u1.UserID.String(),
2851 version.Template.ID,
2852 )
2853
2854 var apiErr *codersdk.Error
2855 require.ErrorAs(t, err, &apiErr)
2856 require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
2857
2858 // u1 should be able to read u2's parameters as u1 is site admin.
2859 _, err = client1.UserAutofillParameters(
2860 ctx,
2861 u2.ID.String(),
2862 version.Template.ID,
2863 )
2864 require.NoError(t, err)
2865 })
2866
2867 t.Run("FindsParameters", func(t *testing.T) {
2868 t.Parallel()
2869 client1, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{})
2870
2871 u1 := coderdtest.CreateFirstUser(t, client1)
2872
2873 client2, u2 := coderdtest.CreateAnotherUser(t, client1, u1.OrganizationID)
2874
2875 db := api.Database
2876
2877 version := dbfake.TemplateVersion(t, db).Seed(database.TemplateVersion{
2878 CreatedBy: u1.UserID,
2879 OrganizationID: u1.OrganizationID,
2880 }).Params(database.TemplateVersionParameter{
2881 Name: "param",
2882 Required: true,

Callers

nothing calls this directly

Calls 13

StatusCodeMethod · 0.95
NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
TemplateVersionFunction · 0.92
WorkspaceBuildFunction · 0.92
RunMethod · 0.65
DoMethod · 0.65
ParamsMethod · 0.45
SeedMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected