feat: Introduce renderer helper
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import appConfig from '../../../../config/app';
|
||||
import appConfig from '../../../../config/app.js';
|
||||
import { renderObject } from '../../../../helpers/renderer.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
response.json({ version: appConfig.version });
|
||||
renderObject(response, { version: appConfig.version });
|
||||
};
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import app from '../../../../app.js';
|
||||
import appConfig from '../../../../config/app.js';
|
||||
|
||||
describe('GET /api/v1/automatisch/version', () => {
|
||||
it('should return Automatisch version', async () => {
|
||||
@@ -9,6 +8,19 @@ describe('GET /api/v1/automatisch/version', () => {
|
||||
.get('/api/v1/automatisch/version')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toEqual({ version: appConfig.version });
|
||||
const expectedPayload = {
|
||||
data: {
|
||||
version: '0.10.0',
|
||||
},
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'Object',
|
||||
},
|
||||
};
|
||||
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
});
|
||||
|
18
packages/backend/src/helpers/renderer.js
Normal file
18
packages/backend/src/helpers/renderer.js
Normal 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 };
|
Reference in New Issue
Block a user