mirror of
https://git.shipoclu.com/moon/plspace.git
synced 2026-08-13 02:42:30 +00:00
public profile editing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ApiClient } from './client'
|
||||
import { postStatus, updateProfileFields, votePoll } from './endpoints'
|
||||
import { postStatus, updateProfileFields, updatePublicProfile, votePoll } from './endpoints'
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
@@ -39,6 +39,56 @@ describe('updateProfileFields', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updatePublicProfile', () => {
|
||||
it('sends public text, images, fields and Pleroma identity data as multipart form data', async () => {
|
||||
const avatar = new File(['avatar'], 'avatar.png', { type: 'image/png' })
|
||||
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
|
||||
const form = init?.body as FormData
|
||||
expect(init?.method).toBe('PATCH')
|
||||
expect(form.get('display_name')).toBe('Alice Example')
|
||||
expect(form.get('note')).toBe('My public bio')
|
||||
expect(form.get('avatar')).toBe(avatar)
|
||||
expect(form.get('header')).toBe('')
|
||||
expect(form.get('actor_type')).toBe('Group')
|
||||
expect(form.get('birthday')).toBe('2000-01-02')
|
||||
expect(form.get('show_birthday')).toBe('true')
|
||||
expect(form.get('fields_attributes[0][name]')).toBe('Website')
|
||||
expect(form.get('fields_attributes[0][value]')).toBe('https://example.test')
|
||||
return new Response(JSON.stringify({ id: 'account-1', fields: [] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await updatePublicProfile(new ApiClient('example.test', 'token'), {
|
||||
displayName: 'Alice Example',
|
||||
note: 'My public bio',
|
||||
avatar,
|
||||
header: '',
|
||||
actorType: 'Group',
|
||||
birthday: '2000-01-02',
|
||||
showBirthday: true,
|
||||
fields: [{ name: 'Website', value: 'https://example.test' }],
|
||||
})
|
||||
})
|
||||
|
||||
it('sends an empty sentinel row when all public fields are cleared', async () => {
|
||||
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
|
||||
const form = init?.body as FormData
|
||||
expect(form.get('fields_attributes[0][name]')).toBe('')
|
||||
expect(form.get('fields_attributes[0][value]')).toBe('')
|
||||
return new Response(JSON.stringify({ id: 'account-1', fields: [] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await updatePublicProfile(new ApiClient('example.test', 'token'), { fields: [] })
|
||||
})
|
||||
})
|
||||
|
||||
describe('poll endpoints', () => {
|
||||
it('submits selected poll option indexes as JSON', async () => {
|
||||
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
|
||||
|
||||
Reference in New Issue
Block a user