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

Function TestUserSkillMissingAndUpdateMismatch

coderd/userskills_test.go:311–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

309}
310
311func TestUserSkillMissingAndUpdateMismatch(t *testing.T) {
312 t.Parallel()
313
314 adminClient := coderdtest.New(t, nil)
315 firstUser := coderdtest.CreateFirstUser(t, adminClient)
316 ownerClient, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
317 owner := codersdk.NewExperimentalClient(ownerClient)
318 ctx := testutil.Context(t, testutil.WaitMedium)
319
320 _, err := owner.UserSkillByName(ctx, codersdk.Me, "missing-skill")
321 requireSDKErrorStatus(t, err, http.StatusNotFound)
322
323 _, err = owner.UpdateUserSkill(ctx, codersdk.Me, "missing-skill", codersdk.UpdateUserSkillRequest{
324 Content: userSkillMarkdown("missing-skill", "Missing", "Body."),
325 })
326 requireSDKErrorStatus(t, err, http.StatusNotFound)
327
328 err = owner.DeleteUserSkill(ctx, codersdk.Me, "missing-skill")
329 requireSDKErrorStatus(t, err, http.StatusNotFound)
330
331 _, err = owner.CreateUserSkill(ctx, codersdk.Me, codersdk.CreateUserSkillRequest{
332 Content: userSkillMarkdown("old-name", "Old", "Body."),
333 })
334 require.NoError(t, err)
335 _, err = owner.UpdateUserSkill(ctx, codersdk.Me, "old-name", codersdk.UpdateUserSkillRequest{
336 Content: userSkillMarkdown("new-name", "New", "Body."),
337 })
338 sdkErr := requireSDKErrorStatus(t, err, http.StatusBadRequest)
339 assert.Equal(t, "Skill name in path does not match frontmatter name.", sdkErr.Message)
340 assert.Equal(t, `path has "old-name", frontmatter has "new-name"`, sdkErr.Detail)
341}
342
343func TestUserSkillAuthorization(t *testing.T) {
344 t.Parallel()

Callers

nothing calls this directly

Calls 12

UserSkillByNameMethod · 0.95
UpdateUserSkillMethod · 0.95
DeleteUserSkillMethod · 0.95
CreateUserSkillMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
ContextFunction · 0.92
requireSDKErrorStatusFunction · 0.85
userSkillMarkdownFunction · 0.70
EqualMethod · 0.45

Tested by

no test coverage detected