]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-132221 Fix qualitygate API type.
authorMathieu Suen <mathieu.suen@sonarsource.com>
Thu, 30 Apr 2020 13:23:04 +0000 (15:23 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:21 +0000 (20:05 +0000)
14 files changed:
server/sonar-web/src/main/js/api/quality-gates.ts
server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx
server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx
server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsHeader-test.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Condition-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Conditions-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/CopyQualityGateForm-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsHeader-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/List-test.tsx.snap
server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts
server/sonar-web/src/main/js/types/types.d.ts

index 9e9255e02ec1bd81c368aa325bec953be9ec00c6..c81bc29a1207f95c6ac2d0bc2cd1cabde4618ea8 100644 (file)
@@ -46,14 +46,14 @@ export function createQualityGate(data: {
 }
 
 export function deleteQualityGate(data: {
-  id: number;
+  id: string;
   organization?: string;
 }): Promise<void | Response> {
   return post('/api/qualitygates/destroy', data).catch(throwGlobalError);
 }
 
 export function renameQualityGate(data: {
-  id: number;
+  id: string;
   name: string;
   organization?: string;
 }): Promise<void | Response> {
@@ -61,7 +61,7 @@ export function renameQualityGate(data: {
 }
 
 export function copyQualityGate(data: {
-  id: number;
+  id: string;
   name: string;
   organization?: string;
 }): Promise<T.QualityGate> {
@@ -69,7 +69,7 @@ export function copyQualityGate(data: {
 }
 
 export function setQualityGateAsDefault(data: {
-  id: number;
+  id: string;
   organization?: string;
 }): Promise<void | Response> {
   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<T.Condition, 'id'>
 ): Promise<T.Condition> {
@@ -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<void | Response> {
@@ -131,7 +131,7 @@ export function associateGateWithProject(data: {
 }
 
 export function dissociateGateWithProject(data: {
-  gateId: number;
+  gateId: string;
   organization?: string;
   projectKey: string;
 }): Promise<void | Response> {
index fa6f38802eba20519c572f8f9ec728c82ccd6e38..904280fd446c7c5052b6cedd905885d95d7cfeb9 100644 (file)
@@ -91,7 +91,7 @@ export default class App extends React.PureComponent<Props> {
     );
   }
 
-  handleChangeGate = (oldId?: number, newId?: number) => {
+  handleChangeGate = (oldId?: string, newId?: string) => {
     const { allGates } = this.state;
     if ((!oldId && !newId) || !allGates) {
       return Promise.resolve();
index 3237229c642cdd597209c8e3f9e332a9e51eb5b2..bdd3eb375c2b20a3ff8c71fbbb9aa2748543dff5 100644 (file)
@@ -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<void>;
+  onChange: (oldGate?: string, newGate?: string) => Promise<void>;
 }
 
 interface State {
@@ -60,14 +60,12 @@ export default class Form extends React.PureComponent<Props, State> {
 
     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);
     }
   };
 
index 1a6bffc4e7878b5c7c10822608d53527837d69c0..b69f987d2e918d1d71727b3f6bdff32a6e613bfb 100644 (file)
@@ -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(<Form allGates={allGates} gate={foo} onChange={jest.fn()} />)).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(<Form allGates={allGates} onChange={onChange} />);
 
-  wrapper.find('Select').prop<Function>('onChange')({ value: 2 });
-  expect(onChange).lastCalledWith(undefined, 2);
+  wrapper.find('Select').prop<Function>('onChange')({ value: '2' });
+  expect(onChange).lastCalledWith(undefined, '2');
 
-  wrapper.setProps({ gate: randomGate(1) });
-  wrapper.find('Select').prop<Function>('onChange')({ value: 2 });
-  expect(onChange).lastCalledWith(1, 2);
+  wrapper.setProps({ gate: randomGate('1') });
+  wrapper.find('Select').prop<Function>('onChange')({ value: '2' });
+  expect(onChange).lastCalledWith('1', '2');
 });
 
-function randomGate(id: number) {
+function randomGate(id: string) {
   return {
     id,
     name: `name-${id}`
index c3d927b6efb693e9e5e201a2e006db7dc6f1f825..4ff383a6eb7f79774b5100d3700c73b02eeabd73 100644 (file)
@@ -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();
index 427e1faef9e499501ec164ad9a3ce94ec182caf1..50f735e44eed630c79d20b9ead26ac3992146f41 100644 (file)
@@ -194,7 +194,7 @@ exports[`should render the update modal correctly 1`] = `
     onClose={[Function]}
     qualityGate={
       Object {
-        "id": 1,
+        "id": "1",
         "name": "qualitygate",
       }
     }
index 1c75a3af287b4ae51c9fede2edcab4ee06de99fe..14bf94662280a8402f211630f1f6426c398f31e1 100644 (file)
@@ -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",
             }
           }
index dae3160544a07129c9491e72bd1ebc128917ffff..e961412c2074d1f297499653ea527c7bf89daf10 100644 (file)
@@ -6,7 +6,7 @@ exports[`should render correctly 1`] = `
   onCopy={[MockFunction]}
   qualityGate={
     Object {
-      "id": 1,
+      "id": "1",
       "name": "qualitygate",
     }
   }
index bdcfec6b95d39b2f7529c7dfb5a99bcb3b2422f6..ba5a76662eb205c14556317ad96dc323ace583ea 100644 (file)
@@ -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",
         }
       }
index 8aa1b677220b8d7e925db941e12e1de8177da4a8..c98a62ada70c89724c55209409cecc889ec23a37 100644 (file)
@@ -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",
         }
       }
index 8e593a3fd9866899a8261cd8d26cfd0058ff4ccb..9326e5cf1d1f38fac362d1a88fd8f1c749eab830 100644 (file)
@@ -47,7 +47,7 @@ exports[`should render correctly: admin actions 1`] = `
                 "rename": true,
                 "setAsDefault": true,
               },
-              "id": 1,
+              "id": "1",
               "name": "qualitygate",
             }
           }
index ab4398468ddade45794ed97b4398a4e318f80344..9fad96d9809c0b936623caf87e0696479a81a2bd 100644 (file)
@@ -7,7 +7,7 @@ exports[`should render correctly 1`] = `
   <Link
     activeClassName="active"
     className="list-group-item display-flex-center"
-    data-id={1}
+    data-id="1"
     key="1"
     onlyActiveOnIndex={false}
     style={Object {}}
@@ -26,7 +26,7 @@ exports[`should render correctly 1`] = `
   <Link
     activeClassName="active"
     className="list-group-item display-flex-center"
-    data-id={1}
+    data-id="1"
     key="1"
     onlyActiveOnIndex={false}
     style={Object {}}
@@ -48,7 +48,7 @@ exports[`should render correctly 1`] = `
   <Link
     activeClassName="active"
     className="list-group-item display-flex-center"
-    data-id={1}
+    data-id="1"
     key="1"
     onlyActiveOnIndex={false}
     style={Object {}}
index 1da53327e55a0c52d734273179d142fad794239b..057a069e47f105c4f35becf4b9972e72a54e9c34 100644 (file)
@@ -29,7 +29,7 @@ import { mockMeasureEnhanced, mockMetric } from '../testMocks';
 
 export function mockQualityGate(overrides: Partial<T.QualityGate> = {}): T.QualityGate {
   return {
-    id: 1,
+    id: '1',
     name: 'qualitygate',
     ...overrides
   };
index 3559864277ff3f33465d186b943b6164cff7eb8a..0ae48e4efbef85982b538b383cd507be1f1441a4 100644 (file)
@@ -654,7 +654,7 @@ declare namespace T {
       setAsDefault?: boolean;
     };
     conditions?: Condition[];
-    id: number;
+    id: string;
     isBuiltIn?: boolean;
     isDefault?: boolean;
     name: string;