feat: pushover client
This commit is contained in:
28
tests/pushover.test.ts
Normal file
28
tests/pushover.test.ts
Normal 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/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user