@@ -244,6 +244,37 @@ func TestSCIMEnterpriseGroupAttributes_Marshal(t *testing.T) {
244244 testJSONMarshal (t , u , want )
245245}
246246
247+ func TestSCIMEnterpriseAttributeOptions_Marshal (t * testing.T ) {
248+ t .Parallel ()
249+ testJSONMarshal (t , & SCIMEnterpriseAttributeOptions {}, "{}" )
250+
251+ u := & SCIMEnterpriseAttributeOptions {
252+ Schemas : []string {"s" },
253+ Operations : []SCIMEnterpriseAttributeOperations {{
254+ Op : "o1" ,
255+ Path : Ptr ("p1" ),
256+ Value : Ptr ("v1" ),
257+ },
258+ {
259+ Op : "o2" ,
260+ }},
261+ }
262+
263+ want := `{
264+ "schemas": ["s"],
265+ "Operations": [{
266+ "op": "o1",
267+ "path": "p1",
268+ "value": "v1"
269+ },
270+ {
271+ "op": "o2"
272+ }]
273+ }`
274+
275+ testJSONMarshal (t , u , want )
276+ }
277+
247278func TestEnterpriseService_ListProvisionedSCIMGroups (t * testing.T ) {
248279 t .Parallel ()
249280 client , mux , _ := setup (t )
@@ -445,3 +476,185 @@ func TestEnterpriseService_ListProvisionedSCIMUsers(t *testing.T) {
445476 return resp , err
446477 })
447478}
479+
480+ func TestEnterpriseService_UpdateAttributeSCIMGroup (t * testing.T ) {
481+ t .Parallel ()
482+ client , mux , _ := setup (t )
483+
484+ mux .HandleFunc ("/scim/v2/enterprises/ee/Groups/abcd" , func (w http.ResponseWriter , r * http.Request ) {
485+ testMethod (t , r , "PATCH" )
486+ testHeader (t , r , "Accept" , mediaTypeSCIM )
487+ testBody (t , r , `{"schemas":["` + SCIMSchemasURINamespacesPatchOp + `"],"Operations":[{"op":"replace","path":"displayName","value":"Employees"}]}` + "\n " )
488+ w .WriteHeader (http .StatusOK )
489+ fmt .Fprint (w , `{
490+ "schemas": ["` + SCIMSchemasURINamespacesGroups + `"],
491+ "id": "abcd",
492+ "externalId": "8aa1",
493+ "displayName": "Employees",
494+ "members": [{
495+ "value": "879d",
496+ "$ref": "https://api.github.localhost/scim/v2/enterprises/ee/Users/879d",
497+ "display": "User 1"
498+ }],
499+ "meta": {
500+ "resourceType": "Group",
501+ "created": ` + referenceTimeStr + `,
502+ "lastModified": ` + referenceTimeStr + `,
503+ "location": "https://api.github.localhost/scim/v2/enterprises/ee/Groups/abcd"
504+ }
505+ }` )
506+ })
507+ want := & SCIMEnterpriseGroupAttributes {
508+ Schemas : []string {SCIMSchemasURINamespacesGroups },
509+ ID : Ptr ("abcd" ),
510+ ExternalID : Ptr ("8aa1" ),
511+ DisplayName : Ptr ("Employees" ),
512+ Members : []* SCIMEnterpriseDisplayReference {{
513+ Value : "879d" ,
514+ Ref : "https://api.github.localhost/scim/v2/enterprises/ee/Users/879d" ,
515+ Display : Ptr ("User 1" ),
516+ }},
517+ Meta : & SCIMEnterpriseMeta {
518+ ResourceType : "Group" ,
519+ Created : & Timestamp {referenceTime },
520+ LastModified : & Timestamp {referenceTime },
521+ Location : Ptr ("https://api.github.localhost/scim/v2/enterprises/ee/Groups/abcd" ),
522+ },
523+ }
524+
525+ ctx := t .Context ()
526+ input := SCIMEnterpriseAttributeOptions {
527+ Schemas : []string {SCIMSchemasURINamespacesPatchOp },
528+ Operations : []SCIMEnterpriseAttributeOperations {{
529+ Op : "replace" ,
530+ Path : Ptr ("displayName" ),
531+ Value : Ptr ("Employees" ),
532+ }},
533+ }
534+ got , _ , err := client .Enterprise .UpdateAttributeSCIMGroup (ctx , "ee" , "abcd" , input )
535+ if err != nil {
536+ t .Fatalf ("Enterprise.UpdateAttributeSCIMGroup returned unexpected error: %v" , err )
537+ }
538+ if diff := cmp .Diff (want , got ); diff != "" {
539+ t .Errorf ("Enterprise.UpdateAttributeSCIMGroup diff mismatch (-want +got):\n %v" , diff )
540+ }
541+
542+ const methodName = "UpdateAttributeSCIMGroup"
543+ testBadOptions (t , methodName , func () (err error ) {
544+ _ , _ , err = client .Enterprise .UpdateAttributeSCIMGroup (ctx , "\n " , "\n " , SCIMEnterpriseAttributeOptions {})
545+ return err
546+ })
547+
548+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
549+ got , resp , err := client .Enterprise .UpdateAttributeSCIMGroup (ctx , "ee" , "abcd" , input )
550+ if got != nil {
551+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
552+ }
553+ return resp , err
554+ })
555+ }
556+
557+ func TestEnterpriseService_UpdateAttributeSCIMUser (t * testing.T ) {
558+ t .Parallel ()
559+ client , mux , _ := setup (t )
560+
561+ mux .HandleFunc ("/scim/v2/enterprises/ee/Users/7fce" , func (w http.ResponseWriter , r * http.Request ) {
562+ testMethod (t , r , "PATCH" )
563+ testHeader (t , r , "Accept" , mediaTypeSCIM )
564+ testBody (
t ,
r ,
`{"schemas":["` + SCIMSchemasURINamespacesPatchOp + `"],"Operations":[{"op":"replace","path":"emails[type eq 'work'].value","value":"[email protected] "},{"op":"replace","path":"name.familyName","value":"updatedFamilyName"}]}` + "\n " )
565+ w .WriteHeader (http .StatusOK )
566+ fmt .Fprint (w , `{
567+ "schemas": ["` + SCIMSchemasURINamespacesUser + `"],
568+ "id": "7fce",
569+ "externalId": "e123",
570+ "active": true,
571+ "userName": "e123",
572+ "name": {
573+ "formatted": "John Doe X",
574+ "familyName": "updatedFamilyName",
575+ "givenName": "John",
576+ "middleName": "X"
577+ },
578+ "displayName": "John Doe",
579+ "emails": [{
580+ 581+ "type": "work",
582+ "primary": true
583+ }],
584+ "roles": [{
585+ "value": "User",
586+ "primary": false
587+ }],
588+ "meta": {
589+ "resourceType": "User",
590+ "created": ` + referenceTimeStr + `,
591+ "lastModified": ` + referenceTimeStr + `,
592+ "location": "https://api.github.localhost/scim/v2/enterprises/ee/Users/7fce"
593+ }
594+ }` )
595+ })
596+ want := & SCIMEnterpriseUserAttributes {
597+ Schemas : []string {SCIMSchemasURINamespacesUser },
598+ ID : Ptr ("7fce" ),
599+ ExternalID : "e123" ,
600+ Active : true ,
601+ UserName : "e123" ,
602+ DisplayName : "John Doe" ,
603+ Name : & SCIMEnterpriseUserName {
604+ Formatted : Ptr ("John Doe X" ),
605+ FamilyName : "updatedFamilyName" ,
606+ GivenName : "John" ,
607+ MiddleName : Ptr ("X" ),
608+ },
609+ Emails : []* SCIMEnterpriseUserEmail {{
610+ 611+ Type : "work" ,
612+ Primary : true ,
613+ }},
614+ Roles : []* SCIMEnterpriseUserRole {{
615+ Value : "User" ,
616+ Primary : Ptr (false ),
617+ }},
618+ Meta : & SCIMEnterpriseMeta {
619+ ResourceType : "User" ,
620+ Created : & Timestamp {referenceTime },
621+ LastModified : & Timestamp {referenceTime },
622+ Location : Ptr ("https://api.github.localhost/scim/v2/enterprises/ee/Users/7fce" ),
623+ },
624+ }
625+
626+ ctx := t .Context ()
627+ input := SCIMEnterpriseAttributeOptions {
628+ Schemas : []string {SCIMSchemasURINamespacesPatchOp },
629+ Operations : []SCIMEnterpriseAttributeOperations {{
630+ Op : "replace" ,
631+ Path : Ptr ("emails[type eq 'work'].value" ),
632+ 633+ }, {
634+ Op : "replace" ,
635+ Path : Ptr ("name.familyName" ),
636+ Value : Ptr ("updatedFamilyName" ),
637+ }},
638+ }
639+ got , _ , err := client .Enterprise .UpdateAttributeSCIMUser (ctx , "ee" , "7fce" , input )
640+ if err != nil {
641+ t .Fatalf ("Enterprise.UpdateAttributeSCIMUser returned unexpected error: %v" , err )
642+ }
643+ if diff := cmp .Diff (want , got ); diff != "" {
644+ t .Errorf ("Enterprise.UpdateAttributeSCIMUser diff mismatch (-want +got):\n %v" , diff )
645+ }
646+
647+ const methodName = "UpdateAttributeSCIMUser"
648+ testBadOptions (t , methodName , func () (err error ) {
649+ _ , _ , err = client .Enterprise .UpdateAttributeSCIMUser (ctx , "\n " , "\n " , SCIMEnterpriseAttributeOptions {})
650+ return err
651+ })
652+
653+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
654+ got , resp , err := client .Enterprise .UpdateAttributeSCIMUser (ctx , "ee" , "7fce" , input )
655+ if got != nil {
656+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
657+ }
658+ return resp , err
659+ })
660+ }
0 commit comments