diff --git a/packages/backend/src/controllers/api/v1/automatisch/license.js b/packages/backend/src/controllers/api/v1/automatisch/license.js new file mode 100644 index 00000000..65f6f4b6 --- /dev/null +++ b/packages/backend/src/controllers/api/v1/automatisch/license.js @@ -0,0 +1,15 @@ +import { getLicense } from '../../../../helpers/license.ee.js'; +import { renderObject } from '../../../../helpers/renderer.js'; + +export default async (request, response) => { + const license = await getLicense(); + + const computedLicense = { + id: license ? license.id : null, + name: license ? license.name : null, + expireAt: license ? license.expireAt : null, + verified: license ? true : false, + }; + + renderObject(response, computedLicense); +}; diff --git a/packages/backend/src/controllers/api/v1/automatisch/license.test.js b/packages/backend/src/controllers/api/v1/automatisch/license.test.js new file mode 100644 index 00000000..211ef630 --- /dev/null +++ b/packages/backend/src/controllers/api/v1/automatisch/license.test.js @@ -0,0 +1,23 @@ +import { vi, expect, describe, it } from 'vitest'; +import request from 'supertest'; +import app from '../../../../app.js'; +import licenseMock from '../../../../../test/mocks/rest/api/v1/automatisch/license.js'; +import * as license from '../../../../helpers/license.ee.js'; + +describe('GET /api/v1/automatisch/license', () => { + it('should return Automatisch license info', async () => { + vi.spyOn(license, 'getLicense').mockResolvedValue({ + id: '123', + name: 'license-name', + expireAt: '2025-12-31T23:59:59Z', + }); + + const response = await request(app) + .get('/api/v1/automatisch/license') + .expect(200); + + const expectedPayload = licenseMock(); + + expect(response.body).toEqual(expectedPayload); + }); +}); diff --git a/packages/backend/src/routes/api/v1/automatisch.js b/packages/backend/src/routes/api/v1/automatisch.js index 91d2e2a7..2ee257fa 100644 --- a/packages/backend/src/routes/api/v1/automatisch.js +++ b/packages/backend/src/routes/api/v1/automatisch.js @@ -2,11 +2,13 @@ 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'; +import licenseAction from '../../../controllers/api/v1/automatisch/license.js'; const router = Router(); router.get('/version', versionAction); router.get('/notifications', notificationsAction); router.get('/info', infoAction); +router.get('/license', licenseAction); export default router; diff --git a/packages/backend/test/mocks/rest/api/v1/automatisch/license.js b/packages/backend/test/mocks/rest/api/v1/automatisch/license.js new file mode 100644 index 00000000..1a02ebb6 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/automatisch/license.js @@ -0,0 +1,19 @@ +const licenseMock = () => { + return { + data: { + expireAt: '2025-12-31T23:59:59Z', + id: '123', + name: 'license-name', + verified: true, + }, + meta: { + count: 1, + currentPage: null, + isArray: false, + totalPages: null, + type: 'Object', + }, + }; +}; + +export default licenseMock;