From 3d4a3d278a957142a3d10f216b9a430b89f40607 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Thu, 30 Apr 2020 15:23:04 +0200 Subject: [PATCH] SONAR-132221 Fix qualitygate API type. --- .../src/main/js/api/quality-gates.ts | 16 +++++++-------- .../main/js/apps/projectQualityGate/App.tsx | 2 +- .../main/js/apps/projectQualityGate/Form.tsx | 8 +++----- .../__tests__/Form-test.tsx | 18 ++++++++--------- .../__tests__/DetailsHeader-test.tsx | 4 ++-- .../__snapshots__/Condition-test.tsx.snap | 2 +- .../__snapshots__/Conditions-test.tsx.snap | 20 +++++++++---------- .../CopyQualityGateForm-test.tsx.snap | 2 +- .../__snapshots__/Details-test.tsx.snap | 4 ++-- .../DetailsContent-test.tsx.snap | 6 +++--- .../__snapshots__/DetailsHeader-test.tsx.snap | 2 +- .../__snapshots__/List-test.tsx.snap | 6 +++--- .../main/js/helpers/mocks/quality-gates.ts | 2 +- server/sonar-web/src/main/js/types/types.d.ts | 2 +- 14 files changed, 46 insertions(+), 48 deletions(-) diff --git a/server/sonar-web/src/main/js/api/quality-gates.ts b/server/sonar-web/src/main/js/api/quality-gates.ts index 9e9255e02ec..c81bc29a120 100644 --- a/server/sonar-web/src/main/js/api/quality-gates.ts +++ b/server/sonar-web/src/main/js/api/quality-gates.ts @@ -46,14 +46,14 @@ export function createQualityGate(data: { } export function deleteQualityGate(data: { - id: number; + id: string; organization?: string; }): Promise { return post('/api/qualitygates/destroy', data).catch(throwGlobalError); } export function renameQualityGate(data: { - id: number; + id: string; name: string; organization?: string; }): Promise { @@ -61,7 +61,7 @@ export function renameQualityGate(data: { } export function copyQualityGate(data: { - id: number; + id: string; name: string; organization?: string; }): Promise { @@ -69,7 +69,7 @@ export function copyQualityGate(data: { } export function setQualityGateAsDefault(data: { - id: number; + id: string; organization?: string; }): Promise { return post('/api/qualitygates/set_as_default', data).catch(throwGlobalError); @@ -77,7 +77,7 @@ export function setQualityGateAsDefault(data: { export function createCondition( data: { - gateId: number; + gateId: string; organization?: string; } & T.Omit ): Promise { @@ -109,7 +109,7 @@ export function getGateForProject(data: { } export function searchProjects(data: { - gateId: number; + gateId: string; organization?: string; page?: number; pageSize?: number; @@ -123,7 +123,7 @@ export function searchProjects(data: { } export function associateGateWithProject(data: { - gateId: number; + gateId: string; organization?: string; projectKey: string; }): Promise { @@ -131,7 +131,7 @@ export function associateGateWithProject(data: { } export function dissociateGateWithProject(data: { - gateId: number; + gateId: string; organization?: string; projectKey: string; }): Promise { diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx index fa6f38802eb..904280fd446 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx @@ -91,7 +91,7 @@ export default class App extends React.PureComponent { ); } - handleChangeGate = (oldId?: number, newId?: number) => { + handleChangeGate = (oldId?: string, newId?: string) => { const { allGates } = this.state; if ((!oldId && !newId) || !allGates) { return Promise.resolve(); diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx index 3237229c642..bdd3eb375c2 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx @@ -24,7 +24,7 @@ import { translate } from 'sonar-ui-common/helpers/l10n'; interface Props { allGates: T.QualityGate[]; gate?: T.QualityGate; - onChange: (oldGate?: number, newGate?: number) => Promise; + onChange: (oldGate?: string, newGate?: string) => Promise; } interface State { @@ -60,14 +60,12 @@ export default class Form extends React.PureComponent { const isSet = gate == null && option.value != null; const isUnset = gate != null && option.value == null; - const isChanged = gate != null && gate.id !== Number(option.value); + const isChanged = gate != null && gate.id !== option.value; const hasChanged = isSet || isUnset || isChanged; if (hasChanged) { this.setState({ loading: true }); - this.props - .onChange(gate && gate.id, Number(option.value)) - .then(this.stopLoading, this.stopLoading); + this.props.onChange(gate && gate.id, option.value).then(this.stopLoading, this.stopLoading); } }; diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx index 1a6bffc4e78..b69f987d2e9 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx @@ -22,25 +22,25 @@ import * as React from 'react'; import Form from '../Form'; it('renders', () => { - const foo = randomGate(1); - const allGates = [foo, randomGate(2)]; + const foo = randomGate('1'); + const allGates = [foo, randomGate('2')]; expect(shallow(
)).toMatchSnapshot(); }); it('changes quality gate', () => { - const allGates = [randomGate(1), randomGate(2)]; + const allGates = [randomGate('1'), randomGate('2')]; const onChange = jest.fn(() => Promise.resolve()); const wrapper = shallow(); - wrapper.find('Select').prop('onChange')({ value: 2 }); - expect(onChange).lastCalledWith(undefined, 2); + wrapper.find('Select').prop('onChange')({ value: '2' }); + expect(onChange).lastCalledWith(undefined, '2'); - wrapper.setProps({ gate: randomGate(1) }); - wrapper.find('Select').prop('onChange')({ value: 2 }); - expect(onChange).lastCalledWith(1, 2); + wrapper.setProps({ gate: randomGate('1') }); + wrapper.find('Select').prop('onChange')({ value: '2' }); + expect(onChange).lastCalledWith('1', '2'); }); -function randomGate(id: number) { +function randomGate(id: string) { return { id, name: `name-${id}` diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsHeader-test.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsHeader-test.tsx index c3d927b6efb..4ff383a6eb7 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsHeader-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsHeader-test.tsx @@ -54,11 +54,11 @@ it('should allow the QG to be set as the default', async () => { const refreshItem = jest.fn(); const refreshList = jest.fn(); - const qualityGate = mockQualityGate({ id: 1, actions: { setAsDefault: true } }); + const qualityGate = mockQualityGate({ id: 'one', actions: { setAsDefault: true } }); const wrapper = shallowRender({ onSetDefault, qualityGate, refreshItem, refreshList }); click(wrapper.find('Button#quality-gate-toggle-default')); - expect(setQualityGateAsDefault).toBeCalledWith({ id: 1 }); + expect(setQualityGateAsDefault).toBeCalledWith({ id: 'one' }); expect(onSetDefault).toBeCalled(); await waitAndUpdate(wrapper); expect(refreshItem).toBeCalled(); diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Condition-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Condition-test.tsx.snap index 427e1faef9e..50f735e44ee 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Condition-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Condition-test.tsx.snap @@ -194,7 +194,7 @@ exports[`should render the update modal correctly 1`] = ` onClose={[Function]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Conditions-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Conditions-test.tsx.snap index 1c75a3af287..14bf9466228 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Conditions-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Conditions-test.tsx.snap @@ -78,7 +78,7 @@ exports[`should render correctly 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -107,7 +107,7 @@ exports[`should render correctly 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -220,7 +220,7 @@ exports[`should render correctly with an updated condition 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -249,7 +249,7 @@ exports[`should render correctly with an updated condition 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -339,7 +339,7 @@ exports[`should render correctly with new code conditions 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -368,7 +368,7 @@ exports[`should render correctly with new code conditions 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -440,7 +440,7 @@ exports[`should render correctly with new code conditions 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -469,7 +469,7 @@ exports[`should render correctly with new code conditions 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -578,7 +578,7 @@ exports[`should render the add conditions button and modal 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -607,7 +607,7 @@ exports[`should render the add conditions button and modal 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/CopyQualityGateForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/CopyQualityGateForm-test.tsx.snap index dae3160544a..e961412c207 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/CopyQualityGateForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/CopyQualityGateForm-test.tsx.snap @@ -6,7 +6,7 @@ exports[`should render correctly 1`] = ` onCopy={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap index bdcfec6b95d..ba5a76662eb 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap @@ -17,7 +17,7 @@ exports[`should render correctly: loaded 1`] = ` onSetDefault={[Function]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -32,7 +32,7 @@ exports[`should render correctly: loaded 1`] = ` onSaveCondition={[Function]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap index 8aa1b677220..c98a62ada70 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap @@ -12,7 +12,7 @@ exports[`should render correctly: is default 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -49,7 +49,7 @@ exports[`should render correctly: is not default 1`] = ` onSaveCondition={[MockFunction]} qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } @@ -73,7 +73,7 @@ exports[`should render correctly: is not default 1`] = ` key="1" qualityGate={ Object { - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsHeader-test.tsx.snap index 8e593a3fd98..9326e5cf1d1 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsHeader-test.tsx.snap @@ -47,7 +47,7 @@ exports[`should render correctly: admin actions 1`] = ` "rename": true, "setAsDefault": true, }, - "id": 1, + "id": "1", "name": "qualitygate", } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/List-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/List-test.tsx.snap index ab4398468dd..9fad96d9809 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/List-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/List-test.tsx.snap @@ -7,7 +7,7 @@ exports[`should render correctly 1`] = ` = {}): T.QualityGate { return { - id: 1, + id: '1', name: 'qualitygate', ...overrides }; diff --git a/server/sonar-web/src/main/js/types/types.d.ts b/server/sonar-web/src/main/js/types/types.d.ts index 3559864277f..0ae48e4efbe 100644 --- a/server/sonar-web/src/main/js/types/types.d.ts +++ b/server/sonar-web/src/main/js/types/types.d.ts @@ -654,7 +654,7 @@ declare namespace T { setAsDefault?: boolean; }; conditions?: Condition[]; - id: number; + id: string; isBuiltIn?: boolean; isDefault?: boolean; name: string; -- 2.39.5