feat(links): /api/kutt proxy (version + create + recent)
This commit is contained in:
40
tests/api/kutt.test.js
Normal file
40
tests/api/kutt.test.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
||||
import request from 'supertest';
|
||||
|
||||
vi.mock('../../lib/links/kutt.js', () => ({
|
||||
compareVersions: (r, l) => ({ running: r, latest: l, updateAvailable: r !== l }),
|
||||
fetchLatestKuttRelease: async () => ({ latest: 'v9.9.9', url: 'https://x' }),
|
||||
createLink: async (b) => ({ link: 'https://link.hynesy.com/abc', address: 'abc', target: b.target }),
|
||||
recentLinks: async () => ({ data: [] })
|
||||
}));
|
||||
|
||||
let app;
|
||||
const owner = r => r.set('Authorization', 'Bearer test-token');
|
||||
beforeAll(async () => {
|
||||
process.env.OWNER_TOKEN = 'test-token';
|
||||
process.env.KUTT_API_URL = 'http://10.0.0.1:3000';
|
||||
process.env.KUTT_API_KEY = 'K';
|
||||
process.env.KUTT_VERSION = 'v3.2.5';
|
||||
({ createApp } = await import('../../server.js'));
|
||||
app = createApp();
|
||||
});
|
||||
let createApp;
|
||||
|
||||
describe('/api/kutt', () => {
|
||||
it('GET /version returns running/latest/updateAvailable (owner)', async () => {
|
||||
expect((await request(app).get('/api/kutt/version')).status).toBe(401);
|
||||
const res = await owner(request(app).get('/api/kutt/version'));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toMatchObject({ running: 'v3.2.5', latest: 'v9.9.9', updateAvailable: true });
|
||||
});
|
||||
|
||||
it('POST / creates a link via Kutt (owner)', async () => {
|
||||
const res = await owner(request(app).post('/api/kutt')).send({ target: 'https://example.com' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.link).toBe('https://link.hynesy.com/abc');
|
||||
});
|
||||
|
||||
it('POST / rejects a non-URL target', async () => {
|
||||
expect((await owner(request(app).post('/api/kutt')).send({ target: 'not a url' })).status).toBe(400);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user