feat: Implement get app auth API endpoint
This commit is contained in:
8
packages/backend/src/controllers/api/v1/apps/get-auth.js
Normal file
8
packages/backend/src/controllers/api/v1/apps/get-auth.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import App from '../../../../models/app.js';
|
||||||
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
|
|
||||||
|
export default async (request, response) => {
|
||||||
|
const auth = await App.findAuthByKey(request.params.appKey);
|
||||||
|
|
||||||
|
renderObject(response, auth, { serializer: 'Auth' });
|
||||||
|
};
|
@@ -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 getAuthMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/apps/:appKey/auth', () => {
|
||||||
|
let currentUser, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
currentUser = await createUser();
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the app auth info', async () => {
|
||||||
|
const exampleApp = await App.findOneByKey('github');
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/apps/${exampleApp.key}/auth`)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAuthMock(exampleApp.auth);
|
||||||
|
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')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
});
|
@@ -2,9 +2,11 @@ import { Router } from 'express';
|
|||||||
import asyncHandler from 'express-async-handler';
|
import asyncHandler from 'express-async-handler';
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||||
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
||||||
|
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
|
router.get('/:appKey', authenticateUser, asyncHandler(getAppAction));
|
||||||
|
router.get('/:appKey/auth', authenticateUser, asyncHandler(getAuthAction));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
18
packages/backend/test/mocks/rest/api/v1/apps/get-auth.js
Normal file
18
packages/backend/test/mocks/rest/api/v1/apps/get-auth.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const getAuthMock = (auth) => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
fields: auth.fields,
|
||||||
|
authenticationSteps: auth.authenticationSteps,
|
||||||
|
reconnectionSteps: auth.reconnectionSteps,
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
count: 1,
|
||||||
|
currentPage: null,
|
||||||
|
isArray: false,
|
||||||
|
totalPages: null,
|
||||||
|
type: 'Object',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getAuthMock;
|
Reference in New Issue
Block a user