Merge pull request #1590 from automatisch/rest-api-automatisch-version

feat: Implement automatisch version API endpoint
This commit is contained in:
Ömer Faruk Aydın
2024-02-13 10:42:44 +01:00
committed by GitHub
5 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import appConfig from '../../../../config/app.js';
import { renderObject } from '../../../../helpers/renderer.js';
export default async (request, response) => {
renderObject(response, { version: appConfig.version });
};

View File

@@ -0,0 +1,26 @@
import { describe, it, expect } from 'vitest';
import request from 'supertest';
import app from '../../../../app.js';
describe('GET /api/v1/automatisch/version', () => {
it('should return Automatisch version', async () => {
const response = await request(app)
.get('/api/v1/automatisch/version')
.expect(200);
const expectedPayload = {
data: {
version: '0.10.0',
},
meta: {
count: 1,
currentPage: null,
isArray: false,
totalPages: null,
type: 'Object',
},
};
expect(response.body).toEqual(expectedPayload);
});
});

View File

@@ -0,0 +1,18 @@
const renderObject = (response, object) => {
const isArray = Array.isArray(object);
const computedPayload = {
data: object,
meta: {
type: object.constructor.name,
count: isArray ? object.length : 1,
isArray,
currentPage: null,
totalPages: null,
},
};
return response.json(computedPayload);
};
export { renderObject };

View File

@@ -0,0 +1,8 @@
import { Router } from 'express';
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
const router = Router();
router.get('/version', versionAction);
export default router;

View File

@@ -3,6 +3,7 @@ import graphQLInstance from '../helpers/graphql-instance.js';
import webhooksRouter from './webhooks.js'; import webhooksRouter from './webhooks.js';
import paddleRouter from './paddle.ee.js'; import paddleRouter from './paddle.ee.js';
import healthcheckRouter from './healthcheck.js'; import healthcheckRouter from './healthcheck.js';
import automatischRouter from './api/v1/automatisch.js';
const router = Router(); const router = Router();
@@ -10,5 +11,6 @@ router.use('/graphql', graphQLInstance);
router.use('/webhooks', webhooksRouter); router.use('/webhooks', webhooksRouter);
router.use('/paddle', paddleRouter); router.use('/paddle', paddleRouter);
router.use('/healthcheck', healthcheckRouter); router.use('/healthcheck', healthcheckRouter);
router.use('/api/v1/automatisch', automatischRouter);
export default router; export default router;