@@ -27,80 +27,104 @@ describe('updateMeProfile', (): void => {
2727 } ) ;
2828
2929 it ( 'should update profile successfully using default fetch' , async ( ) : Promise < void > => {
30- const mockUser : User = {
31- email : 'alice@example.com' ,
30+ const mockUserResponse = {
3231 id : 'u1' ,
33- name : 'Alice' ,
32+ attributes : {
33+ email : 'alice@example.com' ,
34+ name : 'Alice' ,
35+ } ,
36+ } ;
37+
38+ const mockUser : User = {
39+ ...mockUserResponse ,
40+ ...mockUserResponse . attributes ,
3441 } ;
3542
3643 global . fetch = vi . fn ( ) . mockResolvedValue ( {
37- json : ( ) => Promise . resolve ( mockUser ) ,
44+ json : ( ) => Promise . resolve ( mockUserResponse ) ,
3845 ok : true ,
3946 } ) ;
4047
41- const url = 'https://localhost:8090/scim2/Me ' ;
42- const payload : Record < string , unknown > = { 'urn:scim:wso2:schema' : { mobileNumbers : [ '0777933830' ] } } ;
48+ const url = 'https://localhost:8090/users/me ' ;
49+ const payload : Record < string , unknown > = { given_name : 'Alice' } ;
4350
4451 const result : User = await updateMeProfile ( { payload, url} ) ;
4552
4653 expect ( fetch ) . toHaveBeenCalledTimes ( 1 ) ;
4754 const [ calledUrl , init ] : [ string , RequestInit ] = ( fetch as unknown as Mock ) . mock . calls [ 0 ] ;
4855
4956 expect ( calledUrl ) . toBe ( url ) ;
50- expect ( init . method ) . toBe ( 'PATCH ' ) ;
51- expect ( ( init . headers as Record < string , string > ) [ 'Content-Type' ] ) . toBe ( 'application/scim+ json' ) ;
57+ expect ( init . method ) . toBe ( 'PUT ' ) ;
58+ expect ( ( init . headers as Record < string , string > ) [ 'Content-Type' ] ) . toBe ( 'application/json' ) ;
5259 expect ( ( init . headers as Record < string , string > ) [ 'Accept' ] ) . toBe ( 'application/json' ) ;
5360
5461 const parsed : Record < string , unknown > = JSON . parse ( init . body as string ) ;
55- expect ( parsed . schemas ) . toEqual ( [ 'urn:ietf:params:scim:api:messages:2.0:PatchOp' ] ) ;
56- expect ( parsed . Operations ) . toEqual ( [ { op : 'replace' , value : payload } ] ) ;
62+ expect ( parsed . attributes ) . toEqual ( payload ) ;
5763
5864 expect ( result ) . toEqual ( mockUser ) ;
5965 } ) ;
6066
6167 it ( 'should fall back to baseUrl when url is not provided' , async ( ) : Promise < void > => {
62- const mockUser : User = {
63- email : 'bob@example.com' ,
68+ const mockUserResponse = {
6469 id : 'u2' ,
65- name : 'Bob' ,
70+ attributes : {
71+ email : 'bob@example.com' ,
72+ name : 'Bob' ,
73+ } ,
74+ } ;
75+
76+ const mockUser : User = {
77+ ...mockUserResponse ,
78+ ...mockUserResponse . attributes ,
6679 } ;
6780
6881 global . fetch = vi . fn ( ) . mockResolvedValue ( {
69- json : ( ) => Promise . resolve ( mockUser ) ,
82+ json : ( ) => Promise . resolve ( mockUserResponse ) ,
7083 ok : true ,
7184 } ) ;
7285
7386 const baseUrl = 'https://localhost:8090' ;
74- const payload : Record < string , unknown > = { profile : { givenName : 'Bob' } } ;
87+ const payload : Record < string , unknown > = { givenName : 'Bob' } ;
7588
7689 const result : User = await updateMeProfile ( { baseUrl, payload} ) ;
7790
78- expect ( fetch ) . toHaveBeenCalledWith ( `${ baseUrl } /scim2/Me ` , expect . any ( Object ) ) ;
91+ expect ( fetch ) . toHaveBeenCalledWith ( `${ baseUrl } /users/me ` , expect . any ( Object ) ) ;
7992 expect ( result ) . toEqual ( mockUser ) ;
8093 } ) ;
8194
8295 it ( 'should use custom fetcher when provided' , async ( ) : Promise < void > => {
83- const mockUser : User = { email : 'carol@example.com' , id : 'u3' , name : 'Carol' } ;
96+ const mockUserResponse = {
97+ id : 'u3' ,
98+ attributes : {
99+ email : 'carol@example.com' ,
100+ name : 'Carol' ,
101+ } ,
102+ } ;
103+
104+ const mockUser : User = {
105+ ...mockUserResponse ,
106+ ...mockUserResponse . attributes ,
107+ } ;
84108
85109 const customFetcher : Mock = vi . fn ( ) . mockResolvedValue ( {
86- json : ( ) => Promise . resolve ( mockUser ) ,
110+ json : ( ) => Promise . resolve ( mockUserResponse ) ,
87111 ok : true ,
88112 } ) ;
89113
90114 const baseUrl = 'https://localhost:8090' ;
91- const payload : Record < string , unknown > = { profile : { familyName : 'Doe' } } ;
115+ const payload : Record < string , unknown > = { familyName : 'Doe' } ;
92116
93117 const result : User = await updateMeProfile ( { baseUrl, fetcher : customFetcher , payload} ) ;
94118
95119 expect ( result ) . toEqual ( mockUser ) ;
96120 expect ( customFetcher ) . toHaveBeenCalledWith (
97- `${ baseUrl } /scim2/Me ` ,
121+ `${ baseUrl } /users/me ` ,
98122 expect . objectContaining ( {
99123 headers : expect . objectContaining ( {
100124 Accept : 'application/json' ,
101- 'Content-Type' : 'application/scim+ json' ,
125+ 'Content-Type' : 'application/json' ,
102126 } ) ,
103- method : 'PATCH ' ,
127+ method : 'PUT ' ,
104128 } ) ,
105129 ) ;
106130 } ) ;
@@ -112,7 +136,7 @@ describe('updateMeProfile', (): void => {
112136 ok : true ,
113137 } ) ;
114138
115- const url = 'https://localhost:8090/scim2/Me ' ;
139+ const url = 'https://localhost:8090/users/me ' ;
116140 const baseUrl = 'https://localhost:8090' ;
117141 await updateMeProfile ( { baseUrl, payload : { x : 1 } , url} ) ;
118142
@@ -156,16 +180,16 @@ describe('updateMeProfile', (): void => {
156180 it ( 'should handle network or unknown errors with the generic message' , async ( ) : Promise < void > => {
157181 // Rejection with Error
158182 global . fetch = vi . fn ( ) . mockRejectedValue ( new Error ( 'Network error' ) ) ;
159- await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/scim2/Me ' } ) ) . rejects . toThrow (
183+ await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/users/me ' } ) ) . rejects . toThrow (
160184 ThunderIDAPIError ,
161185 ) ;
162- await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/scim2/Me ' } ) ) . rejects . toThrow (
186+ await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/users/me ' } ) ) . rejects . toThrow (
163187 'An error occurred while updating the user profile. Please try again.' ,
164188 ) ;
165189
166190 // Rejection with non-Error
167191 global . fetch = vi . fn ( ) . mockRejectedValue ( 'weird failure' ) ;
168- await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/scim2/Me ' } ) ) . rejects . toThrow (
192+ await expect ( updateMeProfile ( { payload : { a : 1 } , url : 'https://localhost:8090/users/me ' } ) ) . rejects . toThrow (
169193 'An error occurred while updating the user profile. Please try again.' ,
170194 ) ;
171195 } ) ;
@@ -192,28 +216,26 @@ describe('updateMeProfile', (): void => {
192216 expect ( ( init as Record < string , unknown > ) . headers ) . toMatchObject ( {
193217 Accept : 'application/json' ,
194218 Authorization : 'Bearer token' ,
195- 'Content-Type' : 'application/scim+ json' ,
219+ 'Content-Type' : 'application/json' ,
196220 'X-Custom-Header' : 'custom-value' ,
197221 } ) ;
198222 } ) ;
199223
200- it ( 'should build the SCIM PatchOp body correctly' , async ( ) : Promise < void > => {
224+ it ( 'should build the PUT attributes body correctly' , async ( ) : Promise < void > => {
201225 global . fetch = vi . fn ( ) . mockResolvedValue ( {
202226 json : ( ) => Promise . resolve ( { } as User ) ,
203227 ok : true ,
204228 } ) ;
205229
206230 const baseUrl = 'https://localhost:8090' ;
207- const payload : Record < string , unknown > = { 'urn:scim:wso2:schema' : { mobileNumbers : [ '123' ] } } ;
231+ const payload : Record < string , unknown > = { mobileNumbers : [ '123' ] } ;
208232
209233 await updateMeProfile ( { baseUrl, payload} ) ;
210234
211235 const [ , init ] : [ string , RequestInit ] = ( fetch as unknown as Mock ) . mock . calls [ 0 ] ;
212236 const body : Record < string , unknown > = JSON . parse ( ( init as Record < string , unknown > ) . body as string ) ;
213237
214- expect ( body . schemas ) . toEqual ( [ 'urn:ietf:params:scim:api:messages:2.0:PatchOp' ] ) ;
215- expect ( body . Operations ) . toHaveLength ( 1 ) ;
216- expect ( ( body . Operations as Record < string , unknown > [ ] ) [ 0 ] ) . toEqual ( { op : 'replace' , value : payload } ) ;
238+ expect ( body . attributes ) . toEqual ( payload ) ;
217239 } ) ;
218240
219241 it ( 'should allow method override when provided in requestConfig' , async ( ) : Promise < void > => {
0 commit comments