feat: Implement get app config API endpoint
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { renderObject } from '../../../../helpers/renderer.js';
|
||||
import AppConfig from '../../../../models/app-config.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const appConfig = await AppConfig.query()
|
||||
.findOne({
|
||||
key: request.params.appKey,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
renderObject(response, appConfig);
|
||||
};
|
@@ -0,0 +1,44 @@
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import app from '../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../test/factories/user.js';
|
||||
import getAppConfigMock from '../../../../../test/mocks/rest/api/v1/app-configs/get-app-config.js';
|
||||
import { createAppConfig } from '../../../../../test/factories/app-config.js';
|
||||
import * as license from '../../../../helpers/license.ee.js';
|
||||
|
||||
describe('GET /api/v1/app-configs/:appKey', () => {
|
||||
let currentUser, appConfig, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||
|
||||
currentUser = await createUser();
|
||||
|
||||
appConfig = await createAppConfig({
|
||||
key: 'deepl',
|
||||
allowCustomConnection: true,
|
||||
shared: true,
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
token = createAuthTokenByUserId(currentUser.id);
|
||||
});
|
||||
|
||||
it('should return specified app config info', async () => {
|
||||
const response = await request(app)
|
||||
.get(`/api/v1/app-configs/${appConfig.key}`)
|
||||
.set('Authorization', token)
|
||||
.expect(200);
|
||||
|
||||
const expectedPayload = getAppConfigMock(appConfig);
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app key', async () => {
|
||||
await request(app)
|
||||
.get('/api/v1/app-configs/not-existing-app-key')
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
16
packages/backend/src/routes/api/v1/app-configs.ee.js
Normal file
16
packages/backend/src/routes/api/v1/app-configs.ee.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Router } from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
||||
import getAppConfigAction from '../../../controllers/api/v1/app-configs/get-app-config.ee.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
'/:appKey',
|
||||
authenticateUser,
|
||||
checkIsEnterprise,
|
||||
asyncHandler(getAppConfigAction)
|
||||
);
|
||||
|
||||
export default router;
|
@@ -7,6 +7,7 @@ import automatischRouter from './api/v1/automatisch.js';
|
||||
import usersRouter from './api/v1/users.js';
|
||||
import paymentRouter from './api/v1/payment.ee.js';
|
||||
import appAuthClientsRouter from './api/v1/app-auth-clients.js';
|
||||
import appConfigsRouter from './api/v1/app-configs.ee.js';
|
||||
import flowsRouter from './api/v1/flows.js';
|
||||
import appsRouter from './api/v1/apps.js';
|
||||
import executionsRouter from './api/v1/executions.js';
|
||||
@@ -26,6 +27,7 @@ router.use('/api/v1/automatisch', automatischRouter);
|
||||
router.use('/api/v1/users', usersRouter);
|
||||
router.use('/api/v1/payment', paymentRouter);
|
||||
router.use('/api/v1/app-auth-clients', appAuthClientsRouter);
|
||||
router.use('/api/v1/app-configs', appConfigsRouter);
|
||||
router.use('/api/v1/flows', flowsRouter);
|
||||
router.use('/api/v1/apps', appsRouter);
|
||||
router.use('/api/v1/executions', executionsRouter);
|
||||
|
@@ -1,13 +1,9 @@
|
||||
import AppConfig from '../../src/models/app-config.js';
|
||||
|
||||
export const createAppConfig = async (params = {}) => {
|
||||
const appConfigData = {
|
||||
key: params?.key || 'gitlab',
|
||||
};
|
||||
params.key = params?.key || 'gitlab';
|
||||
|
||||
const appConfig = await AppConfig.query()
|
||||
.insert(appConfigData)
|
||||
.returning('*');
|
||||
const appConfig = await AppConfig.query().insert(params).returning('*');
|
||||
|
||||
return appConfig;
|
||||
};
|
||||
|
@@ -0,0 +1,24 @@
|
||||
const getAppConfigMock = (appConfig) => {
|
||||
return {
|
||||
data: {
|
||||
id: appConfig.id,
|
||||
key: appConfig.key,
|
||||
allowCustomConnection: appConfig.allowCustomConnection,
|
||||
shared: appConfig.shared,
|
||||
disabled: appConfig.disabled,
|
||||
canConnect: appConfig.canConnect,
|
||||
canCustomConnect: appConfig.canCustomConnect,
|
||||
createdAt: appConfig.createdAt.getTime(),
|
||||
updatedAt: appConfig.updatedAt.getTime(),
|
||||
},
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: false,
|
||||
totalPages: null,
|
||||
type: 'AppConfig',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getAppConfigMock;
|
Reference in New Issue
Block a user