MCPcopy Create free account
hub / github.com/elimity-com/scim / TestServerResourcePostHandlerValid

Function TestServerResourcePostHandlerValid

handlers_test.go:432–496  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

430}
431
432func TestServerResourcePostHandlerValid(t *testing.T) {
433 tests := []struct {
434 name string
435 target string
436 body io.Reader
437 expectedUserName string
438 expectedExternalID interface{}
439 }{
440 {
441 name: "Users post request without version",
442 target: "/Users",
443 body: strings.NewReader(`{"id": "other", "userName": "test1", "externalId": "external_test1"}`),
444 expectedUserName: "test1",
445 expectedExternalID: "external_test1",
446 }, {
447 name: "Users post request with version",
448 target: "/v2/Users",
449 body: strings.NewReader(`{"id": "other", "userName": "test2", "externalId": "external_test2"}`),
450 expectedUserName: "test2",
451 expectedExternalID: "external_test2",
452 }, {
453 name: "Users post request without externalId",
454 target: "/v2/Users",
455 body: strings.NewReader(`{"id": "other", "userName": "test3"}`),
456 expectedUserName: "test3",
457 expectedExternalID: nil,
458 }, {
459 name: "Users post request with immutable attribute",
460 target: "/v2/Users",
461 body: strings.NewReader(`{"id": "other", "userName": "test3", "immutableThing": "test"}`),
462 expectedUserName: "test3",
463 expectedExternalID: nil,
464 },
465 }
466
467 for _, test := range tests {
468 t.Run(test.name, func(t *testing.T) {
469 req := httptest.NewRequest(http.MethodPost, test.target, test.body)
470 rr := httptest.NewRecorder()
471 newTestServer().ServeHTTP(rr, req)
472
473 assertEqualStatusCode(t, http.StatusCreated, rr.Code)
474
475 assertEqual(t, "application/scim+json", rr.Header().Get("Content-Type"))
476
477 var resource map[string]interface{}
478 assertUnmarshalNoError(t, json.Unmarshal(rr.Body.Bytes(), &resource))
479
480 assertEqual(t, test.expectedUserName, resource["userName"])
481
482 assertEqual(t, test.expectedExternalID, resource["externalId"])
483
484 meta, ok := resource["meta"].(map[string]interface{})
485 assertTypeOk(t, ok, "object")
486
487 assertEqual(t, "User", meta["resourceType"])
488 assertNotNil(t, meta["created"], "created")
489 assertNotNil(t, meta["lastModified"], "last modified")

Callers

nothing calls this directly

Calls 8

assertEqualStatusCodeFunction · 0.85
assertEqualFunction · 0.85
assertUnmarshalNoErrorFunction · 0.85
assertTypeOkFunction · 0.85
assertNotNilFunction · 0.85
ServeHTTPMethod · 0.80
newTestServerFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…