From 5141fc088089cdd155e8623e2d2f989e93c4fff4 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 8 Dec 2020 17:35:40 +0100 Subject: [PATCH] SONAR-13999 Drop orgs from webhooks --- server/sonar-web/src/main/js/api/webhooks.ts | 6 +-- .../main/js/apps/webhooks/components/App.tsx | 5 +-- .../components/__tests__/App-test.tsx | 38 +++++-------------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/server/sonar-web/src/main/js/api/webhooks.ts b/server/sonar-web/src/main/js/api/webhooks.ts index 93d9e572c4e..2b4abe28128 100644 --- a/server/sonar-web/src/main/js/api/webhooks.ts +++ b/server/sonar-web/src/main/js/api/webhooks.ts @@ -22,7 +22,6 @@ import throwGlobalError from '../app/utils/throwGlobalError'; export function createWebhook(data: { name: string; - organization: string | undefined; project?: string; secret?: string; url: string; @@ -34,10 +33,7 @@ export function deleteWebhook(data: { webhook: string }): Promise { +export function searchWebhooks(data: { project?: string }): Promise<{ webhooks: T.Webhook[] }> { return getJSON('/api/webhooks/list', data).catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/App.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/App.tsx index d4f3346219a..6e5f88ddc6a 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/App.tsx @@ -28,7 +28,6 @@ import WebhooksList from './WebhooksList'; interface Props { component?: T.LightComponent; - organization: T.Organization | undefined; } interface State { @@ -64,10 +63,8 @@ export default class App extends React.PureComponent { ); }; - getScopeParams = ({ organization, component } = this.props) => { - const organizationKey = organization && organization.key; + getScopeParams = ({ component } = this.props) => { return { - organization: component ? component.organization : organizationKey, project: component && component.key }; }; diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx index a539729cdbe..97196d6cd41 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx @@ -43,7 +43,6 @@ jest.mock('../../../../api/webhooks', () => ({ updateWebhook: jest.fn(() => Promise.resolve()) })); -const organization: T.Organization = { key: 'foo', name: 'Foo', projectVisibility: 'private' }; const component = { key: 'bar', organization: 'foo', qualifier: 'TRK' }; beforeEach(() => { @@ -54,15 +53,15 @@ beforeEach(() => { }); it('should be in loading status', () => { - expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); }); it('should fetch webhooks and display them', async () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.state('loading')).toBe(true); await new Promise(setImmediate); - expect(searchWebhooks).toHaveBeenCalledWith({ organization: organization.key }); + expect(searchWebhooks).toHaveBeenCalledWith({}); wrapper.update(); expect(wrapper).toMatchSnapshot(); @@ -70,35 +69,17 @@ it('should fetch webhooks and display them', async () => { describe('should correctly fetch webhooks when', () => { it('on global scope', async () => { - shallow(); + shallow(); await new Promise(setImmediate); - expect(searchWebhooks).toHaveBeenCalledWith({ organization: undefined }); + expect(searchWebhooks).toHaveBeenCalledWith({ projects: undefined }); }); it('on project scope', async () => { - shallow(); + shallow(); await new Promise(setImmediate); expect(searchWebhooks).toHaveBeenCalledWith({ - project: component.key, - organization: component.organization - }); - }); - - it('on organization scope', async () => { - shallow(); - - await new Promise(setImmediate); - expect(searchWebhooks).toHaveBeenCalledWith({ organization: organization.key }); - }); - - it('on project scope within an organization', async () => { - shallow(); - - await new Promise(setImmediate); - expect(searchWebhooks).toHaveBeenCalledWith({ - organization: organization.key, project: component.key }); }); @@ -106,11 +87,10 @@ describe('should correctly fetch webhooks when', () => { it('should correctly handle webhook creation', async () => { const webhook = { name: 'baz', url: 'http://baz' }; - const wrapper = shallow(); + const wrapper = shallow(); (wrapper.instance() as App).handleCreate({ ...webhook }); expect(createWebhook).lastCalledWith({ ...webhook, - organization: organization.key, project: undefined }); @@ -124,7 +104,7 @@ it('should correctly handle webhook creation', async () => { }); it('should correctly handle webhook deletion', async () => { - const wrapper = shallow(); + const wrapper = shallow(); (wrapper.instance() as App).handleDelete('2'); expect(deleteWebhook).lastCalledWith({ webhook: '2' }); @@ -135,7 +115,7 @@ it('should correctly handle webhook deletion', async () => { it('should correctly handle webhook update', async () => { const newValues = { webhook: '1', name: 'Cfoo', url: 'http://cfoo' }; - const wrapper = shallow(); + const wrapper = shallow(); (wrapper.instance() as App).handleUpdate(newValues); expect(updateWebhook).lastCalledWith(newValues); -- 2.39.5