Update Users.edit to use FormData when submitting avatar updates (#3644)

This commit is contained in:
Justin Dalrymple 2024-10-19 20:21:10 -04:00 committed by GitHub
parent e4aa240ff8
commit d8bdf42788
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -156,7 +156,7 @@ export type AllUsersOptions = {
export type CreateUserOptions = {
admin?: boolean;
auditor?: boolean;
avatar?: { content: Blob; filepath?: string };
avatar?: { content: Blob; filename?: string };
bio?: string;
canCreateGroup?: boolean;
colorSchemeId?: number;
@ -487,9 +487,16 @@ export class Users<C extends boolean = false> extends BaseResource<C> {
edit<E extends boolean = false>(
userId: number,
options?: EditUserOptions & Sudo & ShowExpanded<E>,
{ avatar, ...options }: EditUserOptions & Sudo & ShowExpanded<E> = {},
) {
return RequestHelper.put<ExpandedUserSchema>()(this, endpoint`users/${userId}`, options);
const opts: Record<string, unknown> = {
...options,
isForm: true,
};
if (avatar) opts.avatar = [avatar.content, avatar.filename];
return RequestHelper.put<ExpandedUserSchema>()(this, endpoint`users/${userId}`, opts);
}
editStatus<E extends boolean = false>(

View File

@ -181,7 +181,10 @@ describe('Users.edit', () => {
it('should request PUT users/:id', async () => {
await service.edit(1, { name: 'Okoye' });
expect(RequestHelper.put()).toHaveBeenCalledWith(service, 'users/1', { name: 'Okoye' });
expect(RequestHelper.put()).toHaveBeenCalledWith(service, 'users/1', {
isForm: true,
name: 'Okoye',
});
});
});