♻️(backend) rename convert-markdown endpoint

Renamed the `convert-markdown` endpoint to `convert` as a
general-purpose conversion endpoint for integration with DocSpec
conversion (DOCX import), without altering its existing functionality.

In a future contribution, this endpoint will not only support conversion
from Markdown -> BlockNote -> Yjs but also directly BlockNote -> Yjs.

Signed-off-by: Stephan Meijer <me@stephanmeijer.com>
This commit is contained in:
Stephan Meijer
2025-06-27 14:19:53 +02:00
parent 1d741871d7
commit c8ae2f6549
8 changed files with 21 additions and 21 deletions

View File

@@ -0,0 +1,66 @@
import request from 'supertest';
const port = 5556;
const origin = 'http://localhost:3000';
jest.mock('../src/env', () => {
return {
PORT: port,
COLLABORATION_SERVER_ORIGIN: origin,
Y_PROVIDER_API_KEY: 'yprovider-api-key',
};
});
import { initServer } from '../src/servers/appServer';
console.error = jest.fn();
const { app, server } = initServer();
describe('Server Tests', () => {
afterAll(() => {
server.close();
});
test('POST /api/convert with incorrect API key should return 403', async () => {
const response = await request(app as any)
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'wrong-api-key');
expect(response.status).toBe(403);
expect(response.body.error).toBe('Forbidden: Invalid API Key');
});
test('POST /api/convert with a Bearer token', async () => {
const response = await request(app as any)
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'Bearer test-secret-api-key');
// Warning: Changing the authorization header to Bearer token format will break backend compatibility with this microservice.
expect(response.status).toBe(403);
});
test('POST /api/convert with missing body param content', async () => {
const response = await request(app as any)
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'yprovider-api-key');
expect(response.status).toBe(400);
expect(response.body.error).toBe('Invalid request: missing content');
});
test('POST /api/convert with body param content being an empty string', async () => {
const response = await request(app as any)
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'yprovider-api-key')
.send({
content: '',
});
expect(response.status).toBe(400);
expect(response.body.error).toBe('Invalid request: missing content');
});
});