File tree Expand file tree Collapse file tree
web/sdk/client/views/profile Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { profileUpdateBody } from './profile-update-body' ;
2+
3+ describe ( 'profileUpdateBody' , ( ) => {
4+ const storedUser = {
5+ id : 'user-1' ,
6+ name : 'jane_doe' ,
7+ title : 'Jane Doe' ,
8+ email : 'jane@raystack.org' ,
9+ avatar : 'data:image/png;base64,old' ,
10+ metadata : { onboarded : true , team : 'core' }
11+ } ;
12+
13+ it ( 'leaves out metadata when only the avatar changes' , ( ) => {
14+ const formValues = { ...storedUser , avatar : 'data:image/png;base64,new' } ;
15+
16+ const body = profileUpdateBody ( formValues , storedUser . name ) ;
17+
18+ expect ( body ) . toEqual ( {
19+ title : 'Jane Doe' ,
20+ email : 'jane@raystack.org' ,
21+ avatar : 'data:image/png;base64,new' ,
22+ name : 'jane_doe'
23+ } ) ;
24+ expect ( body ) . not . toHaveProperty ( 'metadata' ) ;
25+ } ) ;
26+
27+ it ( 'leaves out metadata when the title changes' , ( ) => {
28+ const formValues = { ...storedUser , title : 'Jane Smith' } ;
29+
30+ const body = profileUpdateBody ( formValues , storedUser . name ) ;
31+
32+ expect ( body . title ) . toBe ( 'Jane Smith' ) ;
33+ expect ( body ) . not . toHaveProperty ( 'metadata' ) ;
34+ } ) ;
35+ } ) ;
Original file line number Diff line number Diff line change 1+ export interface ProfileFormValues {
2+ title : string ;
3+ email : string ;
4+ avatar ?: string ;
5+ }
6+
7+ export function profileUpdateBody (
8+ values : ProfileFormValues ,
9+ currentName : string | undefined
10+ ) {
11+ return {
12+ title : values . title ,
13+ email : values . email ,
14+ avatar : values . avatar ,
15+ name : currentName
16+ } ;
17+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import { DeleteUserDialog } from '../../components/delete-user-dialog';
2727import styles from './profile-view.module.css' ;
2828
2929import { handleConnectError } from '~/utils/error' ;
30+ import { profileUpdateBody } from './profile-update-body' ;
3031
3132const profileSchema = yup
3233 . object ( {
@@ -101,14 +102,7 @@ export function ProfileView({
101102 async function onSubmit ( data : FormData ) {
102103 try {
103104 if ( ! user ?. id ) return ;
104- await updateCurrentUser ( {
105- body : {
106- title : data . title ,
107- email : data . email ,
108- avatar : data . avatar ,
109- name : user . name
110- }
111- } ) ;
105+ await updateCurrentUser ( { body : profileUpdateBody ( data , user . name ) } ) ;
112106 toastManager . add ( { title : 'Updated user' , type : 'success' } ) ;
113107 } catch ( err ) {
114108 handleConnectError ( err , {
You can’t perform that action at this time.
0 commit comments