aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api
diff options
context:
space:
mode:
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>2024-08-28 16:40:16 +0200
committersonartech <sonartech@sonarsource.com>2024-09-04 20:03:11 +0000
commit0996c6186cfeb8e2c763d2f174b26ab276b232f7 (patch)
tree6a56285befb26ce1b41d9065ab86379cb91d31ac /server/sonar-web/src/main/js/api
parentbed8af05f0c3f2b4c6018634d3d7aaba5b45a83c (diff)
downloadsonarqube-0996c6186cfeb8e2c763d2f174b26ab276b232f7.tar.gz
sonarqube-0996c6186cfeb8e2c763d2f174b26ab276b232f7.zip
CODEFIX-12 Show new suggestion feature in issues page
Diffstat (limited to 'server/sonar-web/src/main/js/api')
-rw-r--r--server/sonar-web/src/main/js/api/fix-suggestions.ts29
-rw-r--r--server/sonar-web/src/main/js/api/mocks/FixIssueServiceMock.ts59
2 files changed, 88 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/api/fix-suggestions.ts b/server/sonar-web/src/main/js/api/fix-suggestions.ts
new file mode 100644
index 00000000000..84570ff31e1
--- /dev/null
+++ b/server/sonar-web/src/main/js/api/fix-suggestions.ts
@@ -0,0 +1,29 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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 { axiosToCatch } from '../helpers/request';
+import { SuggestedFix } from '../types/fix-suggestions';
+
+export interface FixParam {
+ issueId: string;
+}
+
+export function getSuggestions(data: FixParam): Promise<SuggestedFix> {
+ return axiosToCatch.post<SuggestedFix>('/api/v2/fix-suggestions/ai-suggestions', data);
+}
diff --git a/server/sonar-web/src/main/js/api/mocks/FixIssueServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/FixIssueServiceMock.ts
new file mode 100644
index 00000000000..be6dfcfcf69
--- /dev/null
+++ b/server/sonar-web/src/main/js/api/mocks/FixIssueServiceMock.ts
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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 { cloneDeep } from 'lodash';
+import { FixParam, getSuggestions } from '../fix-suggestions';
+import { ISSUE_101 } from './data/ids';
+
+jest.mock('../fix-suggestions');
+
+export default class FixIssueServiceMock {
+ fixSuggestion = {
+ id: '70b14d4c-d302-4979-9121-06ac7d563c5c',
+ issueId: 'AYsVhClEbjXItrbcN71J',
+ explanation:
+ "Replaced 'require' statements with 'import' statements to comply with ECMAScript 2015 module management standards.",
+ changes: [
+ {
+ startLine: 6,
+ endLine: 7,
+ newCode: "import { glob } from 'glob';\nimport fs from 'fs';",
+ },
+ ],
+ };
+
+ constructor() {
+ jest.mocked(getSuggestions).mockImplementation(this.handleGetFixSuggestion);
+ }
+
+ handleGetFixSuggestion = (data: FixParam) => {
+ if (data.issueId === ISSUE_101) {
+ return Promise.reject({ error: { msg: 'Invalid issue' } });
+ }
+ return this.reply(this.fixSuggestion);
+ };
+
+ reply<T>(response: T): Promise<T> {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ resolve(cloneDeep(response));
+ }, 10);
+ });
+ }
+}