refactor: Rename AppAuthClient model as OAuthClient
This commit is contained in:
@@ -6,14 +6,14 @@ export default async (request, response) => {
|
||||
.findOne({ key: request.params.appKey })
|
||||
.throwIfNotFound();
|
||||
|
||||
const appAuthClient = await appConfig
|
||||
.$relatedQuery('appAuthClients')
|
||||
.insert(appAuthClientParams(request));
|
||||
const oauthClient = await appConfig
|
||||
.$relatedQuery('oauthClients')
|
||||
.insert(oauthClientParams(request));
|
||||
|
||||
renderObject(response, appAuthClient, { status: 201 });
|
||||
renderObject(response, oauthClient, { status: 201 });
|
||||
};
|
||||
|
||||
const appAuthClientParams = (request) => {
|
||||
const oauthClientParams = (request) => {
|
||||
const { active, appKey, name, formattedAuthDefaults } = request.body;
|
||||
|
||||
return {
|
||||
@@ -5,11 +5,11 @@ import app from '../../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../../test/factories/user.js';
|
||||
import { createRole } from '../../../../../../test/factories/role.js';
|
||||
import createAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/create-auth-client.js';
|
||||
import createOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/create-oauth-client.js';
|
||||
import { createAppConfig } from '../../../../../../test/factories/app-config.js';
|
||||
import * as license from '../../../../../helpers/license.ee.js';
|
||||
|
||||
describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
describe('POST /api/v1/admin/apps/:appKey/oauth-clients', () => {
|
||||
let currentUser, adminRole, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -26,7 +26,7 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
key: 'gitlab',
|
||||
});
|
||||
|
||||
const appAuthClient = {
|
||||
const oauthClient = {
|
||||
active: true,
|
||||
appKey: 'gitlab',
|
||||
name: 'First auth client',
|
||||
@@ -39,17 +39,17 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
};
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/v1/admin/apps/gitlab/auth-clients')
|
||||
.post('/api/v1/admin/apps/gitlab/oauth-clients')
|
||||
.set('Authorization', token)
|
||||
.send(appAuthClient)
|
||||
.send(oauthClient)
|
||||
.expect(201);
|
||||
|
||||
const expectedPayload = createAppAuthClientMock(appAuthClient);
|
||||
const expectedPayload = createOAuthClientMock(oauthClient);
|
||||
expect(response.body).toMatchObject(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app config', async () => {
|
||||
const appAuthClient = {
|
||||
const oauthClient = {
|
||||
active: true,
|
||||
appKey: 'gitlab',
|
||||
name: 'First auth client',
|
||||
@@ -62,9 +62,9 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
};
|
||||
|
||||
await request(app)
|
||||
.post('/api/v1/admin/apps/gitlab/auth-clients')
|
||||
.post('/api/v1/admin/apps/gitlab/oauth-clients')
|
||||
.set('Authorization', token)
|
||||
.send(appAuthClient)
|
||||
.send(oauthClient)
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
@@ -73,14 +73,14 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
key: 'gitlab',
|
||||
});
|
||||
|
||||
const appAuthClient = {
|
||||
const oauthClient = {
|
||||
appKey: 'gitlab',
|
||||
};
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/v1/admin/apps/gitlab/auth-clients')
|
||||
.post('/api/v1/admin/apps/gitlab/oauth-clients')
|
||||
.set('Authorization', token)
|
||||
.send(appAuthClient)
|
||||
.send(oauthClient)
|
||||
.expect(422);
|
||||
|
||||
expect(response.body.meta.type).toStrictEqual('ModelValidation');
|
||||
@@ -1,11 +0,0 @@
|
||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const appAuthClient = await AppAuthClient.query()
|
||||
.findById(request.params.appAuthClientId)
|
||||
.where({ app_key: request.params.appKey })
|
||||
.throwIfNotFound();
|
||||
|
||||
renderObject(response, appAuthClient);
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||
import OAuthClient from '../../../../../models/oauth-client.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const oauthClient = await OAuthClient.query()
|
||||
.findById(request.params.oauthClientId)
|
||||
.where({ app_key: request.params.appKey })
|
||||
.throwIfNotFound();
|
||||
|
||||
renderObject(response, oauthClient);
|
||||
};
|
||||
@@ -5,12 +5,12 @@ import app from '../../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../../test/factories/user.js';
|
||||
import { createRole } from '../../../../../../test/factories/role.js';
|
||||
import getAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-client.js';
|
||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||
import getOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-oauth-client.js';
|
||||
import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js';
|
||||
import * as license from '../../../../../helpers/license.ee.js';
|
||||
|
||||
describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||
let currentUser, adminRole, currentAppAuthClient, token;
|
||||
describe('GET /api/v1/admin/apps/:appKey/oauth-clients/:oauthClientId', () => {
|
||||
let currentUser, adminRole, currentOAuthClient, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||
@@ -18,29 +18,29 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||
adminRole = await createRole({ name: 'Admin' });
|
||||
currentUser = await createUser({ roleId: adminRole.id });
|
||||
|
||||
currentAppAuthClient = await createAppAuthClient({
|
||||
currentOAuthClient = await createOAuthClient({
|
||||
appKey: 'deepl',
|
||||
});
|
||||
|
||||
token = await createAuthTokenByUserId(currentUser.id);
|
||||
});
|
||||
|
||||
it('should return specified app auth client', async () => {
|
||||
it('should return specified oauth client', async () => {
|
||||
const response = await request(app)
|
||||
.get(`/api/v1/admin/apps/deepl/auth-clients/${currentAppAuthClient.id}`)
|
||||
.get(`/api/v1/admin/apps/deepl/oauth-clients/${currentOAuthClient.id}`)
|
||||
.set('Authorization', token)
|
||||
.expect(200);
|
||||
|
||||
const expectedPayload = getAppAuthClientMock(currentAppAuthClient);
|
||||
const expectedPayload = getOAuthClientMock(currentOAuthClient);
|
||||
expect(response.body).toStrictEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app auth client ID', async () => {
|
||||
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
||||
it('should return not found response for not existing oauth client ID', async () => {
|
||||
const notExistingOAuthClientUUID = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.get(
|
||||
`/api/v1/admin/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}`
|
||||
`/api/v1/admin/apps/deepl/oauth-clients/${notExistingOAuthClientUUID}`
|
||||
)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
@@ -48,7 +48,7 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||
|
||||
it('should return bad request response for invalid UUID', async () => {
|
||||
await request(app)
|
||||
.get('/api/v1/admin/apps/deepl/auth-clients/invalidAppAuthClientUUID')
|
||||
.get('/api/v1/admin/apps/deepl/oauth-clients/invalidOAuthClientUUID')
|
||||
.set('Authorization', token)
|
||||
.expect(400);
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||
import OAuthClient from '../../../../../models/oauth-client.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const appAuthClients = await AppAuthClient.query()
|
||||
const oauthClients = await OAuthClient.query()
|
||||
.where({ app_key: request.params.appKey })
|
||||
.orderBy('created_at', 'desc');
|
||||
|
||||
renderObject(response, appAuthClients);
|
||||
renderObject(response, oauthClients);
|
||||
};
|
||||
@@ -4,11 +4,11 @@ import app from '../../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../../test/factories/user.js';
|
||||
import { createRole } from '../../../../../../test/factories/role.js';
|
||||
import getAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-clients.js';
|
||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||
import getAdminOAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-oauth-clients.js';
|
||||
import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js';
|
||||
import * as license from '../../../../../helpers/license.ee.js';
|
||||
|
||||
describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
describe('GET /api/v1/admin/apps/:appKey/oauth-clients', () => {
|
||||
let currentUser, adminRole, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -20,23 +20,23 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
token = await createAuthTokenByUserId(currentUser.id);
|
||||
});
|
||||
|
||||
it('should return specified app auth client info', async () => {
|
||||
const appAuthClientOne = await createAppAuthClient({
|
||||
it('should return specified oauth client info', async () => {
|
||||
const oauthClientOne = await createOAuthClient({
|
||||
appKey: 'deepl',
|
||||
});
|
||||
|
||||
const appAuthClientTwo = await createAppAuthClient({
|
||||
const oauthClientTwo = await createOAuthClient({
|
||||
appKey: 'deepl',
|
||||
});
|
||||
|
||||
const response = await request(app)
|
||||
.get('/api/v1/admin/apps/deepl/auth-clients')
|
||||
.get('/api/v1/admin/apps/deepl/oauth-clients')
|
||||
.set('Authorization', token)
|
||||
.expect(200);
|
||||
|
||||
const expectedPayload = getAuthClientsMock([
|
||||
appAuthClientTwo,
|
||||
appAuthClientOne,
|
||||
const expectedPayload = getAdminOAuthClientsMock([
|
||||
oauthClientTwo,
|
||||
oauthClientOne,
|
||||
]);
|
||||
|
||||
expect(response.body).toStrictEqual(expectedPayload);
|
||||
@@ -1,22 +0,0 @@
|
||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const appAuthClient = await AppAuthClient.query()
|
||||
.findById(request.params.appAuthClientId)
|
||||
.throwIfNotFound();
|
||||
|
||||
await appAuthClient.$query().patchAndFetch(appAuthClientParams(request));
|
||||
|
||||
renderObject(response, appAuthClient);
|
||||
};
|
||||
|
||||
const appAuthClientParams = (request) => {
|
||||
const { active, name, formattedAuthDefaults } = request.body;
|
||||
|
||||
return {
|
||||
active,
|
||||
name,
|
||||
formattedAuthDefaults,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||
import OAuthClient from '../../../../../models/oauth-client.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const oauthClient = await OAuthClient.query()
|
||||
.findById(request.params.oauthClientId)
|
||||
.throwIfNotFound();
|
||||
|
||||
await oauthClient.$query().patchAndFetch(oauthClientParams(request));
|
||||
|
||||
renderObject(response, oauthClient);
|
||||
};
|
||||
|
||||
const oauthClientParams = (request) => {
|
||||
const { active, name, formattedAuthDefaults } = request.body;
|
||||
|
||||
return {
|
||||
active,
|
||||
name,
|
||||
formattedAuthDefaults,
|
||||
};
|
||||
};
|
||||
@@ -6,12 +6,12 @@ import app from '../../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../../test/factories/user.js';
|
||||
import { createRole } from '../../../../../../test/factories/role.js';
|
||||
import updateAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/update-auth-client.js';
|
||||
import updateOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/update-oauth-client.js';
|
||||
import { createAppConfig } from '../../../../../../test/factories/app-config.js';
|
||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||
import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js';
|
||||
import * as license from '../../../../../helpers/license.ee.js';
|
||||
|
||||
describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
describe('PATCH /api/v1/admin/apps/:appKey/oauth-clients', () => {
|
||||
let currentUser, adminRole, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -27,8 +27,8 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return updated entity for valid app auth client', async () => {
|
||||
const appAuthClient = {
|
||||
it('should return updated entity for valid oauth client', async () => {
|
||||
const oauthClient = {
|
||||
active: true,
|
||||
appKey: 'gitlab',
|
||||
formattedAuthDefaults: {
|
||||
@@ -39,33 +39,33 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const existingAppAuthClient = await createAppAuthClient({
|
||||
const existingOAuthClient = await createOAuthClient({
|
||||
appKey: 'gitlab',
|
||||
name: 'First auth client',
|
||||
});
|
||||
|
||||
const response = await request(app)
|
||||
.patch(
|
||||
`/api/v1/admin/apps/gitlab/auth-clients/${existingAppAuthClient.id}`
|
||||
`/api/v1/admin/apps/gitlab/oauth-clients/${existingOAuthClient.id}`
|
||||
)
|
||||
.set('Authorization', token)
|
||||
.send(appAuthClient)
|
||||
.send(oauthClient)
|
||||
.expect(200);
|
||||
|
||||
const expectedPayload = updateAppAuthClientMock({
|
||||
...existingAppAuthClient,
|
||||
...appAuthClient,
|
||||
const expectedPayload = updateOAuthClientMock({
|
||||
...existingOAuthClient,
|
||||
...oauthClient,
|
||||
});
|
||||
|
||||
expect(response.body).toMatchObject(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app auth client', async () => {
|
||||
const notExistingAppAuthClientId = Crypto.randomUUID();
|
||||
it('should return not found response for not existing oauth client', async () => {
|
||||
const notExistingOAuthClientId = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.patch(
|
||||
`/api/v1/admin/apps/gitlab/auth-clients/${notExistingAppAuthClientId}`
|
||||
`/api/v1/admin/apps/gitlab/oauth-clients/${notExistingOAuthClientId}`
|
||||
)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
@@ -73,27 +73,27 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||
|
||||
it('should return bad request response for invalid UUID', async () => {
|
||||
await request(app)
|
||||
.patch('/api/v1/admin/apps/gitlab/auth-clients/invalidAuthClientUUID')
|
||||
.patch('/api/v1/admin/apps/gitlab/oauth-clients/invalidAuthClientUUID')
|
||||
.set('Authorization', token)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should return HTTP 422 for invalid payload', async () => {
|
||||
const appAuthClient = {
|
||||
const oauthClient = {
|
||||
formattedAuthDefaults: 'invalid input',
|
||||
};
|
||||
|
||||
const existingAppAuthClient = await createAppAuthClient({
|
||||
const existingOAuthClient = await createOAuthClient({
|
||||
appKey: 'gitlab',
|
||||
name: 'First auth client',
|
||||
});
|
||||
|
||||
const response = await request(app)
|
||||
.patch(
|
||||
`/api/v1/admin/apps/gitlab/auth-clients/${existingAppAuthClient.id}`
|
||||
`/api/v1/admin/apps/gitlab/oauth-clients/${existingOAuthClient.id}`
|
||||
)
|
||||
.set('Authorization', token)
|
||||
.send(appAuthClient)
|
||||
.send(oauthClient)
|
||||
.expect(422);
|
||||
|
||||
expect(response.body.meta.type).toBe('ModelValidation');
|
||||
Reference in New Issue
Block a user