Merge pull request #1653 from automatisch/rest-automatisch-license
faet: Implement automatisch license API endpoint
This commit is contained in:
@@ -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);
|
||||
};
|
@@ -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);
|
||||
});
|
||||
});
|
@@ -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;
|
||||
|
@@ -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;
|
Reference in New Issue
Block a user