Skip to content

Commit

Permalink
feat: Implement automatisch info API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
farukaydin committed Feb 25, 2024
1 parent 1c7435a commit 079fb5d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/backend/src/controllers/api/v1/automatisch/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import appConfig from '../../../../config/app.js';
import { hasValidLicense } from '../../../../helpers/license.ee.js';
import { renderObject } from '../../../../helpers/renderer.js';

export default async (request, response) => {
const info = {
isCloud: appConfig.isCloud,
isMation: appConfig.isMation,
isEnterprise: await hasValidLicense(),
};

renderObject(response, info);
};
22 changes: 22 additions & 0 deletions packages/backend/src/controllers/api/v1/automatisch/info.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { vi, expect, describe, it } from 'vitest';
import request from 'supertest';
import appConfig from '../../../../config/app.js';
import app from '../../../../app.js';
import infoMock from '../../../../../test/mocks/rest/api/v1/automatisch/info.js';
import * as license from '../../../../helpers/license.ee.js';

describe('GET /api/v1/automatisch/info', () => {
it('should return Automatisch info', async () => {
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);

const response = await request(app)
.get('/api/v1/automatisch/info')
.expect(200);

const expectedPayload = infoMock();

expect(response.body).toEqual(expectedPayload);
});
});
2 changes: 2 additions & 0 deletions packages/backend/src/routes/api/v1/automatisch.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Router } from 'express';
import versionAction from '../../../controllers/api/v1/automatisch/version.js';
import notificationsAction from '../../../controllers/api/v1/automatisch/notifications.js';
import infoAction from '../../../controllers/api/v1/automatisch/info.js';

const router = Router();

router.get('/version', versionAction);
router.get('/notifications', notificationsAction);
router.get('/info', infoAction);

export default router;
18 changes: 18 additions & 0 deletions packages/backend/test/mocks/rest/api/v1/automatisch/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const infoMock = () => {
return {
data: {
isCloud: false,
isMation: false,
isEnterprise: true,
},
meta: {
count: 1,
currentPage: null,
isArray: false,
totalPages: null,
type: 'Object',
},
};
};

export default infoMock;

0 comments on commit 079fb5d

Please sign in to comment.