Merge pull request #1686 from automatisch/get-app-actions
feat: Implement get app actions API endpoint
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import App from '../../../../models/app.js';
|
||||
import { renderObject } from '../../../../helpers/renderer.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const actions = await App.findActionsByKey(request.params.appKey);
|
||||
|
||||
renderObject(response, actions, { serializer: 'Action' });
|
||||
};
|
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import App from '../../../../models/app';
|
||||
import app from '../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
|
||||
import { createUser } from '../../../../../test/factories/user';
|
||||
import getActionsMock from '../../../../../test/mocks/rest/api/v1/apps/get-actions.js';
|
||||
|
||||
describe('GET /api/v1/apps/:appKey/actions', () => {
|
||||
let currentUser, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
currentUser = await createUser();
|
||||
token = createAuthTokenByUserId(currentUser.id);
|
||||
});
|
||||
|
||||
it('should return the app actions', async () => {
|
||||
const exampleApp = await App.findOneByKey('github');
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/api/v1/apps/${exampleApp.key}/actions`)
|
||||
.set('Authorization', token)
|
||||
.expect(200);
|
||||
|
||||
const expectedPayload = getActionsMock(exampleApp.actions);
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for invalid app key', async () => {
|
||||
await request(app)
|
||||
.get('/api/v1/apps/invalid-app-key/actions')
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
@@ -64,6 +64,13 @@ class App {
|
||||
return trigger?.substeps || [];
|
||||
}
|
||||
|
||||
static async findActionsByKey(key, stripFuncs = false) {
|
||||
const rawAppData = await getApp(key, stripFuncs);
|
||||
const appData = appInfoConverter(rawAppData);
|
||||
|
||||
return appData?.actions || [];
|
||||
}
|
||||
|
||||
static async checkAppAndAction(appKey, actionKey) {
|
||||
const app = await this.findOneByKey(appKey);
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js';
|
||||
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
||||
import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js';
|
||||
import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js';
|
||||
import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -25,4 +26,10 @@ router.get(
|
||||
asyncHandler(getTriggerSubstepsAction)
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:appKey/actions',
|
||||
authenticateUser,
|
||||
asyncHandler(getActionsAction)
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
9
packages/backend/src/serializers/action.js
Normal file
9
packages/backend/src/serializers/action.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const actionSerializer = (action) => {
|
||||
return {
|
||||
name: action.name,
|
||||
key: action.key,
|
||||
description: action.description,
|
||||
};
|
||||
};
|
||||
|
||||
export default actionSerializer;
|
21
packages/backend/src/serializers/action.test.js
Normal file
21
packages/backend/src/serializers/action.test.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import App from '../models/app';
|
||||
import actionSerializer from './action';
|
||||
|
||||
describe('actionSerializer', () => {
|
||||
it('should return the action data', async () => {
|
||||
const actions = await App.findActionsByKey('github');
|
||||
const action = actions[0];
|
||||
|
||||
const expectedPayload = {
|
||||
description: action.description,
|
||||
key: action.key,
|
||||
name: action.name,
|
||||
pollInterval: action.pollInterval,
|
||||
showWebhookUrl: action.showWebhookUrl,
|
||||
type: action.type,
|
||||
};
|
||||
|
||||
expect(actionSerializer(action)).toEqual(expectedPayload);
|
||||
});
|
||||
});
|
@@ -8,6 +8,7 @@ import stepSerializer from './step.js';
|
||||
import appSerializer from './app.js';
|
||||
import authSerializer from './auth.js';
|
||||
import triggerSerializer from './trigger.js';
|
||||
import actionSerializer from './action.js';
|
||||
|
||||
const serializers = {
|
||||
User: userSerializer,
|
||||
@@ -20,6 +21,7 @@ const serializers = {
|
||||
App: appSerializer,
|
||||
Auth: authSerializer,
|
||||
Trigger: triggerSerializer,
|
||||
Action: actionSerializer,
|
||||
};
|
||||
|
||||
export default serializers;
|
||||
|
22
packages/backend/test/mocks/rest/api/v1/apps/get-actions.js
Normal file
22
packages/backend/test/mocks/rest/api/v1/apps/get-actions.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const getActionsMock = (actions) => {
|
||||
const actionsData = actions.map((trigger) => {
|
||||
return {
|
||||
name: trigger.name,
|
||||
key: trigger.key,
|
||||
description: trigger.description,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
data: actionsData,
|
||||
meta: {
|
||||
count: actions.length,
|
||||
currentPage: null,
|
||||
isArray: true,
|
||||
totalPages: null,
|
||||
type: 'Object',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getActionsMock;
|
Reference in New Issue
Block a user