This commit is contained in:
Moon.eth
2026-07-29 19:37:17 +09:00
parent 4eb785b6ad
commit 8f0d47b850
10 changed files with 614 additions and 22 deletions
+58 -1
View File
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ApiClient } from './client'
import { updateProfileFields } from './endpoints'
import { postStatus, updateProfileFields, votePoll } from './endpoints'
afterEach(() => {
vi.unstubAllGlobals()
@@ -38,3 +38,60 @@ describe('updateProfileFields', () => {
)
})
})
describe('poll endpoints', () => {
it('submits selected poll option indexes as JSON', async () => {
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
expect(init?.method).toBe('POST')
expect(JSON.parse(String(init?.body))).toEqual({ choices: [0, 2] })
return new Response(
JSON.stringify({
id: 'poll-1',
expired: false,
multiple: true,
votes_count: 2,
options: [],
emojis: [],
voted: true,
own_votes: [0, 2],
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
})
vi.stubGlobal('fetch', fetchMock)
await votePoll(new ApiClient('example.test', 'token'), 'poll/one', [0, 2])
expect(fetchMock).toHaveBeenCalledWith(
'https://example.test/api/v1/polls/poll%2Fone/votes',
expect.any(Object),
)
})
it('includes a standard Mastodon/Pleroma poll in a new status', async () => {
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
expect(JSON.parse(String(init?.body))).toMatchObject({
status: 'Pick a snack',
poll: {
options: ['Cake', 'Fruit'],
expires_in: 3600,
multiple: false,
},
})
return new Response(JSON.stringify({ id: 'status-1' }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
})
})
vi.stubGlobal('fetch', fetchMock)
await postStatus(new ApiClient('example.test', 'token'), {
status: 'Pick a snack',
poll: {
options: ['Cake', 'Fruit'],
expires_in: 3600,
multiple: false,
},
})
})
})