feat: pushover client

This commit is contained in:
2026-05-25 14:12:37 +00:00
parent ff807065fd
commit 8ec9d1fde7
2 changed files with 61 additions and 0 deletions

28
tests/pushover.test.ts Normal file
View File

@@ -0,0 +1,28 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { sendPush } from '@/lib/pushover'
beforeEach(() => {
process.env.PUSHOVER_TOKEN = 'tok'
process.env.PUSHOVER_USER = 'user'
global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200, json: async () => ({ status: 1 }) }) as unknown as typeof fetch
})
describe('sendPush', () => {
it('posts to pushover with token/user/payload', async () => {
await sendPush({ title: 'T', message: 'M', url: 'https://x' })
const fetchMock = global.fetch as unknown as ReturnType<typeof vi.fn>
const [url, init] = fetchMock.mock.calls[0]
expect(url).toBe('https://api.pushover.net/1/messages.json')
const body = init.body as URLSearchParams
expect(body.get('token')).toBe('tok')
expect(body.get('user')).toBe('user')
expect(body.get('title')).toBe('T')
expect(body.get('message')).toBe('M')
expect(body.get('url')).toBe('https://x')
})
it('throws if env vars missing', async () => {
delete process.env.PUSHOVER_TOKEN
await expect(sendPush({ title: 'T', message: 'M' })).rejects.toThrow(/PUSHOVER/)
})
})