-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement get app auth API endpoint
- Loading branch information
1 parent
356668a
commit 5dca019
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }); | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/backend/src/controllers/api/v1/apps/get-auth.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |