export function getComponent(
data: { component: string; metricKeys: string } & T.BranchParameters
-): Promise<any> {
- return getJSON('/api/measures/component', data).then(r => r.component, throwGlobalError);
+): Promise<{ component: T.ComponentMeasure }> {
+ return getJSON('/api/measures/component', data);
}
export interface TreeComponent extends T.LightComponent {
return getJSON('/api/components/tree', data).catch(throwGlobalError);
}
+export function getComponentData(data: { component: string } & T.BranchParameters): Promise<any> {
+ return getJSON('/api/components/show', data);
+}
+
export function doesComponentExists(
data: { component: string } & T.BranchParameters
): Promise<boolean> {
- return getJSON('/api/components/show', data).then(
- ({ component }) => component !== undefined,
- () => false
- );
+ return getComponentData(data).then(({ component }) => component !== undefined, () => false);
}
export function getComponentShow(data: { component: string } & T.BranchParameters): Promise<any> {
- return getJSON('/api/components/show', data).catch(throwGlobalError);
+ return getComponentData(data).catch(throwGlobalError);
}
export function getParents(component: string): Promise<any> {
});
}
-export function getComponentData(data: { component: string } & T.BranchParameters): Promise<any> {
- return getComponentShow(data).then(r => r.component);
-}
-
export function getMyProjects(data: {
p?: number;
ps?: number;
getComponentNavigation({ component: key, branch, pullRequest }),
getComponentData({ component: key, branch, pullRequest })
])
- .then(([nav, data]) => {
- const component = this.addQualifier({ ...nav, ...data });
+ .then(([nav, { component }]) => {
+ const componentWithQualifier = this.addQualifier({ ...nav, ...component });
if (isSonarCloud()) {
- this.props.fetchOrganization(component.organization);
+ this.props.fetchOrganization(componentWithQualifier.organization);
}
- return component;
- })
+ return componentWithQualifier;
+ }, onError)
.then(this.fetchBranches)
- .then(({ branchLike, branchLikes, component }) => {
- if (this.mounted) {
- this.setState({
- branchLike,
- branchLikes,
- component,
- loading: false
- });
- this.fetchStatus(component);
- this.fetchWarnings(component, branchLike);
- }
- })
- .catch(onError);
+ .then(
+ ({ branchLike, branchLikes, component }) => {
+ if (this.mounted) {
+ this.setState({
+ branchLike,
+ branchLikes,
+ component,
+ loading: false
+ });
+ this.fetchStatus(component);
+ this.fetchWarnings(component, branchLike);
+ }
+ },
+ () => {}
+ );
}
fetchBranches = (
}));
jest.mock('../../../api/components', () => ({
- getComponentData: jest.fn().mockResolvedValue({ analysisDate: '2018-07-30' })
+ getComponentData: jest.fn().mockResolvedValue({ component: { analysisDate: '2018-07-30' } })
}));
jest.mock('../../../api/nav', () => ({
it('loads organization', async () => {
(isSonarCloud as jest.Mock).mockReturnValue(true);
- (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ organization: 'org' });
+ (getComponentData as jest.Mock<any>).mockResolvedValueOnce({
+ component: { organization: 'org' }
+ });
const fetchOrganization = jest.fn();
shallowRender({ fetchOrganization });
});
it('fetches status', async () => {
- (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ organization: 'org' });
+ (getComponentData as jest.Mock<any>).mockResolvedValueOnce({
+ component: { organization: 'org' }
+ });
shallowRender();
await new Promise(setImmediate);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import handleRequiredAuthentication from '../handleRequiredAuthentication';
-import getHistory from '../getHistory';
-
-jest.mock('../getHistory', () => ({
- default: jest.fn()
-}));
-
-it('should not render for anonymous user', () => {
- const replace = jest.fn();
- (getHistory as jest.Mock<any>).mockReturnValue({ replace });
- handleRequiredAuthentication();
- expect(replace).toBeCalledWith(expect.objectContaining({ pathname: '/sessions/new' }));
-});
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import handleRequiredAuthentication from '../handleRequiredAuthentication';
+import getHistory from '../getHistory';
+
+jest.mock('../getHistory', () => ({
+ default: jest.fn()
+}));
+
+it('should not render for anonymous user', () => {
+ const replace = jest.fn();
+ (getHistory as jest.Mock<any>).mockReturnValue({ replace });
+ handleRequiredAuthentication();
+ expect(replace).toBeCalledWith(expect.objectContaining({ pathname: '/sessions/new' }));
+});
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import throwGlobalError from '../throwGlobalError';
+import getStore from '../getStore';
+
+it('should put the error message in the store', async () => {
+ const response: any = { json: jest.fn().mockResolvedValue({ errors: [{ msg: 'error 1' }] }) };
+ await throwGlobalError({ response }).catch(() => {});
+ expect(getStore().getState().globalMessages[0]).toMatchObject({
+ level: 'ERROR',
+ message: 'error 1'
+ });
+});
+
+it('should put a default error messsage in the store', async () => {
+ const response: any = { json: jest.fn().mockResolvedValue({}) };
+ await throwGlobalError({ response }).catch(() => {});
+ expect(getStore().getState().globalMessages[0]).toMatchObject({
+ level: 'ERROR',
+ message: 'default_error_message'
+ });
+});
const store = getStore();
// eslint-disable-next-line promise/no-promise-in-callback
- parseError(error)
- .then(message => {
+ parseError(error).then(
+ message => {
store.dispatch(addGlobalErrorMessage(message));
- })
- .catch(() => {});
-
+ },
+ () => {}
+ );
return Promise.reject(error.response);
}
component: componentKey,
metricKeys: metrics.join(),
...getBranchLikeQuery(branchLike)
- }).then(component => {
+ }).then(({ component }) => {
addComponent(component);
return component;
});
return Promise.all([
getComponentForSourceViewer({ component, ...getBranchLikeQuery(branchLike) }),
getComponentData({ component, ...getBranchLikeQuery(branchLike) })
- ]).then(([component, data]) => ({
- ...component,
- leakPeriodDate: data.leakPeriodDate
+ ]).then(([sourceViewerComponent, { component }]) => ({
+ ...sourceViewerComponent,
+ leakPeriodDate: component.leakPeriodDate
}));
}