blob: ebbdc9c207dd5f11549f9a8c2eee0a102fafac79 [file] [log] [blame]
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +01001/* eslint-disable @typescript-eslint/no-unused-vars */
2/**
3 * @license
4 * Copyright (C) 2020 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
Ben Rohlfsa9d2cff2021-01-22 21:33:58 +010018import {RestApiService} from '../../services/gr-rest-api/gr-rest-api';
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010019import {
20 AccountDetailInfo,
21 AccountExternalIdInfo,
22 AccountInfo,
23 ServerInfo,
24 ProjectInfo,
25 AccountCapabilityInfo,
26 SuggestedReviewerInfo,
27 GroupNameToGroupInfoMap,
28 ParsedJSON,
29 EditPreferencesInfo,
30 SshKeyInfo,
31 RepoName,
32 GpgKeyInfo,
33 PreferencesInfo,
34 EmailInfo,
35 ProjectAccessInfo,
36 CapabilityInfoMap,
37 ChangeInfo,
38 ProjectInfoWithName,
39 GroupInfo,
40 BranchInfo,
41 ConfigInfo,
42 EditInfo,
43 DashboardInfo,
44 ProjectAccessInfoMap,
45 IncludedInInfo,
46 CommentInfo,
47 PathToCommentsInfoMap,
48 PluginInfo,
49 DocResult,
50 ContributorAgreementInfo,
51 Password,
52 ProjectWatchInfo,
53 NameToProjectInfoMap,
54 GroupAuditEventInfo,
55 Base64FileContent,
56 TagInfo,
57 RelatedChangesInfo,
58 SubmittedTogetherInfo,
59 FilePathToDiffInfoMap,
60 BlameInfo,
61 ImagesForDiff,
62 ActionNameToActionInfoMap,
63 Hashtag,
64 FileNameToFileInfoMap,
65 TopMenuEntryInfo,
66 MergeableInfo,
67 CommitInfo,
68 GroupId,
69 GroupName,
70 UrlEncodedRepoName,
Dhruv Srivastavab0cebc12022-03-08 15:16:57 +010071 NumericChangeId,
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010072} from '../../types/common';
73import {DiffInfo, DiffPreferencesInfo} from '../../types/diff';
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010074import {readResponsePayload} from '../../elements/shared/gr-rest-api-interface/gr-rest-apis/gr-rest-api-helper';
75import {
76 createAccountDetailWithId,
77 createChange,
78 createCommit,
79 createConfig,
80 createPreferences,
81 createServerInfo,
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +010082 createSubmittedTogetherInfo,
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010083} from '../test-data-generators';
84import {
85 createDefaultDiffPrefs,
86 createDefaultEditPrefs,
Dhruv Srivastava86be2a32021-10-15 10:46:42 +020087 createDefaultPreferences,
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010088} from '../../constants/constants';
Ben Rohlfsa00ef282021-01-22 21:45:53 +010089import {ParsedChangeInfo} from '../../types/types';
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +010090
91export const grRestApiMock: RestApiService = {
92 addAccountEmail(): Promise<Response> {
93 return Promise.resolve(new Response());
94 },
95 addAccountGPGKey(): Promise<Record<string, GpgKeyInfo>> {
96 return Promise.resolve({});
97 },
98 addAccountSSHKey(): Promise<SshKeyInfo> {
99 throw new Error('addAccountSSHKey() not implemented by RestApiMock.');
100 },
101 addToAttentionSet(): Promise<Response> {
102 return Promise.resolve(new Response());
103 },
104 applyFixSuggestion(): Promise<Response> {
105 return Promise.resolve(new Response());
106 },
107 awaitPendingDiffDrafts(): Promise<void> {
108 return Promise.resolve();
109 },
110 confirmEmail(): Promise<string | null> {
111 return Promise.resolve('');
112 },
113 createChange(): Promise<ChangeInfo | undefined> {
114 throw new Error('createChange() not implemented by RestApiMock.');
115 },
116 createGroup(): Promise<Response> {
117 return Promise.resolve(new Response());
118 },
119 createRepo(): Promise<Response> {
120 return Promise.resolve(new Response());
121 },
122 createRepoBranch(): Promise<Response> {
123 return Promise.resolve(new Response());
124 },
125 createRepoTag(): Promise<Response> {
126 return Promise.resolve(new Response());
127 },
128 deleteAccountEmail(): Promise<Response> {
129 return Promise.resolve(new Response());
130 },
131 deleteAccountGPGKey(): Promise<Response> {
132 return Promise.resolve(new Response());
133 },
134 deleteAccountIdentity(): Promise<unknown> {
135 return Promise.resolve(new Response());
136 },
137 deleteAccountSSHKey(): void {},
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100138 deleteChangeCommitMessage(): Promise<Response> {
139 return Promise.resolve(new Response());
140 },
141 deleteComment(): Promise<CommentInfo> {
142 throw new Error('deleteComment() not implemented by RestApiMock.');
143 },
144 deleteDiffDraft(): Promise<Response> {
145 return Promise.resolve(new Response());
146 },
147 deleteDraftComments(): Promise<Response> {
148 return Promise.resolve(new Response());
149 },
150 deleteFileInChangeEdit(): Promise<Response | undefined> {
151 return Promise.resolve(new Response());
152 },
153 deleteGroupMember(): Promise<Response> {
154 return Promise.resolve(new Response());
155 },
156 deleteIncludedGroup(): Promise<Response> {
157 return Promise.resolve(new Response());
158 },
159 deleteRepoBranches(): Promise<Response> {
160 return Promise.resolve(new Response());
161 },
162 deleteRepoTags(): Promise<Response> {
163 return Promise.resolve(new Response());
164 },
165 deleteVote(): Promise<Response> {
166 return Promise.resolve(new Response());
167 },
168 deleteWatchedProjects(): Promise<Response> {
169 return Promise.resolve(new Response());
170 },
171 executeChangeAction(): Promise<Response | undefined> {
172 return Promise.resolve(new Response());
173 },
Chris Poucet55cbccb2021-11-16 03:17:06 +0100174 finalize(): void {},
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100175 generateAccountHttpPassword(): Promise<Password> {
176 return Promise.resolve('asdf');
177 },
178 getAccount(): Promise<AccountDetailInfo | undefined> {
179 return Promise.resolve(createAccountDetailWithId(1));
180 },
181 getAccountAgreements(): Promise<ContributorAgreementInfo[] | undefined> {
182 return Promise.resolve([]);
183 },
184 getAccountCapabilities(): Promise<AccountCapabilityInfo | undefined> {
185 return Promise.resolve({});
186 },
187 getAccountDetails(): Promise<AccountDetailInfo | undefined> {
188 return Promise.resolve(createAccountDetailWithId(1));
189 },
190 getAccountEmails(): Promise<EmailInfo[] | undefined> {
191 return Promise.resolve([]);
192 },
193 getAccountGPGKeys(): Promise<Record<string, GpgKeyInfo>> {
194 return Promise.resolve({});
195 },
196 getAccountGroups(): Promise<GroupInfo[] | undefined> {
197 return Promise.resolve([]);
198 },
199 getAccountSSHKeys(): Promise<SshKeyInfo[] | undefined> {
200 return Promise.resolve([]);
201 },
202 getAccountStatus(): Promise<string | undefined> {
203 return Promise.resolve('');
204 },
205 getAvatarChangeUrl(): Promise<string | undefined> {
206 return Promise.resolve('');
207 },
208 getBlame(): Promise<BlameInfo[] | undefined> {
209 return Promise.resolve([]);
210 },
211 getCapabilities(): Promise<CapabilityInfoMap | undefined> {
212 return Promise.resolve({});
213 },
214 getChange(): Promise<ChangeInfo | null> {
215 throw new Error('getChange() not implemented by RestApiMock.');
216 },
217 getChangeActionURL(): Promise<string> {
218 return Promise.resolve('');
219 },
220 getChangeCherryPicks(): Promise<ChangeInfo[] | undefined> {
221 return Promise.resolve([]);
222 },
223 getChangeCommitInfo(): Promise<CommitInfo | undefined> {
224 return Promise.resolve(createCommit());
225 },
226 getChangeConflicts(): Promise<ChangeInfo[] | undefined> {
227 return Promise.resolve([]);
228 },
Ben Rohlfsa16c51a2021-11-22 12:50:55 +0100229 getChangeDetail(
230 changeNum?: number | string
Ben Rohlfs1fe7f4d2021-12-06 11:21:49 +0100231 ): Promise<ParsedChangeInfo | undefined> {
Ben Rohlfsa16c51a2021-11-22 12:50:55 +0100232 if (changeNum === undefined) return Promise.resolve(undefined);
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100233 return Promise.resolve(createChange() as ParsedChangeInfo);
234 },
Ben Rohlfscb1e2562021-12-06 10:50:47 +0100235 getChangeEdit(): Promise<EditInfo | undefined> {
236 return Promise.resolve(undefined);
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100237 },
238 getChangeFiles(): Promise<FileNameToFileInfoMap | undefined> {
239 return Promise.resolve({});
240 },
241 getChangeIncludedIn(): Promise<IncludedInInfo | undefined> {
242 throw new Error('getChangeIncludedIn() not implemented by RestApiMock.');
243 },
244 getChangeOrEditFiles(): Promise<FileNameToFileInfoMap | undefined> {
245 return Promise.resolve({});
246 },
247 getChangeRevisionActions(): Promise<ActionNameToActionInfoMap | undefined> {
248 return Promise.resolve({});
249 },
250 getChangeSuggestedCCs(): Promise<SuggestedReviewerInfo[] | undefined> {
251 return Promise.resolve([]);
252 },
253 getChangeSuggestedReviewers(): Promise<SuggestedReviewerInfo[] | undefined> {
254 return Promise.resolve([]);
255 },
256 getChanges() {
257 return Promise.resolve([]);
258 },
Dhruv Srivastava41e486f2022-03-08 13:44:26 +0100259 getChangesForMultipleQueries() {
260 return Promise.resolve([]);
261 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100262 getChangesSubmittedTogether(): Promise<SubmittedTogetherInfo | undefined> {
Milutin Kristoficf4c04fb42021-03-10 16:41:19 +0100263 return Promise.resolve(createSubmittedTogetherInfo());
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100264 },
Dhruv Srivastavab0cebc12022-03-08 15:16:57 +0100265 getDetailedChangesWithActions(changeNums: NumericChangeId[]) {
266 return Promise.resolve(
267 changeNums.map(changeNum => {
268 return {
269 ...createChange(),
270 actions: {},
271 _number: changeNum,
272 subject: `Subject ${changeNum}`,
273 };
274 })
275 );
276 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100277 getChangesWithSameTopic(): Promise<ChangeInfo[] | undefined> {
278 return Promise.resolve([]);
279 },
Milutin Kristoficfc0f0112021-03-08 14:25:06 +0100280 getChangesWithSimilarTopic(): Promise<ChangeInfo[] | undefined> {
281 return Promise.resolve([]);
282 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100283 getConfig(): Promise<ServerInfo | undefined> {
284 return Promise.resolve(createServerInfo());
285 },
286 getDashboard(): Promise<DashboardInfo | undefined> {
Dhruv Srivastavab642c242021-06-11 16:33:35 +0200287 return Promise.resolve(undefined);
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100288 },
289 getDefaultPreferences(): Promise<PreferencesInfo | undefined> {
290 throw new Error('getDefaultPreferences() not implemented by RestApiMock.');
291 },
292 getDiff(): Promise<DiffInfo | undefined> {
293 throw new Error('getDiff() not implemented by RestApiMock.');
294 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100295 getDiffComments() {
Chris Poucet55cbccb2021-11-16 03:17:06 +0100296 // NOTE: This method can not be typed properly due to overloads.
297 // eslint-disable-next-line @typescript-eslint/no-explicit-any
298 return Promise.resolve({}) as any;
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100299 },
300 getDiffDrafts() {
Chris Poucet55cbccb2021-11-16 03:17:06 +0100301 // NOTE: This method can not be typed properly due to overloads.
302 // eslint-disable-next-line @typescript-eslint/no-explicit-any
303 return Promise.resolve({}) as any;
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100304 },
305 getDiffPreferences(): Promise<DiffPreferencesInfo | undefined> {
306 return Promise.resolve(createDefaultDiffPrefs());
307 },
308 getDiffRobotComments() {
Chris Poucet55cbccb2021-11-16 03:17:06 +0100309 // NOTE: This method can not be typed properly due to overloads.
310 // eslint-disable-next-line @typescript-eslint/no-explicit-any
311 return Promise.resolve({}) as any;
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100312 },
313 getDocumentationSearches(): Promise<DocResult[] | undefined> {
314 return Promise.resolve([]);
315 },
316 getEditPreferences(): Promise<EditPreferencesInfo | undefined> {
317 return Promise.resolve(createDefaultEditPrefs());
318 },
319 getExternalIds(): Promise<AccountExternalIdInfo[] | undefined> {
320 return Promise.resolve([]);
321 },
322 getFileContent(): Promise<Response | Base64FileContent | undefined> {
323 return Promise.resolve(new Response());
324 },
325 getFromProjectLookup(): Promise<RepoName | undefined> {
326 throw new Error('getFromProjectLookup() not implemented by RestApiMock.');
327 },
328 getGroupAuditLog(): Promise<GroupAuditEventInfo[] | undefined> {
329 return Promise.resolve([]);
330 },
331 getGroupConfig(id: GroupId | GroupName): Promise<GroupInfo | undefined> {
332 return Promise.resolve({
333 id: id as GroupId,
334 });
335 },
336 getGroupMembers(): Promise<AccountInfo[]> {
337 return Promise.resolve([]);
338 },
339 getGroups(): Promise<GroupNameToGroupInfoMap | undefined> {
340 return Promise.resolve({});
341 },
342 getImagesForDiff(): Promise<ImagesForDiff> {
343 throw new Error('getImagesForDiff() not implemented by RestApiMock.');
344 },
345 getIncludedGroup(): Promise<GroupInfo[] | undefined> {
346 return Promise.resolve([]);
347 },
348 getIsAdmin(): Promise<boolean | undefined> {
349 return Promise.resolve(false);
350 },
351 getIsGroupOwner(): Promise<boolean> {
352 return Promise.resolve(false);
353 },
354 getLoggedIn(): Promise<boolean> {
355 return Promise.resolve(true);
356 },
357 getMergeable(): Promise<MergeableInfo | undefined> {
358 throw new Error('getMergeable() not implemented by RestApiMock.');
359 },
360 getPlugins(): Promise<{[p: string]: PluginInfo} | undefined> {
361 return Promise.resolve({});
362 },
363 getPortedComments(): Promise<PathToCommentsInfoMap | undefined> {
364 return Promise.resolve({});
365 },
366 getPortedDrafts(): Promise<PathToCommentsInfoMap | undefined> {
367 return Promise.resolve({});
368 },
369 getPreferences(): Promise<PreferencesInfo | undefined> {
370 return Promise.resolve(createPreferences());
371 },
372 getProjectConfig(): Promise<ConfigInfo | undefined> {
373 return Promise.resolve(createConfig());
374 },
375 getRelatedChanges(): Promise<RelatedChangesInfo | undefined> {
376 return Promise.resolve({changes: []});
377 },
378 getRepo(repo: RepoName): Promise<ProjectInfo | undefined> {
379 return Promise.resolve({
Chris Poucetcaeea1b2021-08-19 22:12:56 +0000380 id: repo as string as UrlEncodedRepoName,
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100381 name: repo,
382 });
383 },
384 getRepoAccess(): Promise<ProjectAccessInfoMap | undefined> {
385 return Promise.resolve({});
386 },
387 getRepoAccessRights(): Promise<ProjectAccessInfo | undefined> {
388 return Promise.resolve(undefined);
389 },
390 getRepoBranches(): Promise<BranchInfo[] | undefined> {
391 return Promise.resolve([]);
392 },
393 getRepoDashboards(): Promise<DashboardInfo[] | undefined> {
394 return Promise.resolve([]);
395 },
396 getRepoTags(): Promise<TagInfo[]> {
397 return Promise.resolve([]);
398 },
399 getRepos(): Promise<ProjectInfoWithName[] | undefined> {
400 return Promise.resolve([]);
401 },
402 getResponseObject(response: Response): Promise<ParsedJSON> {
403 return readResponsePayload(response).then(payload => payload.parsed);
404 },
405 getReviewedFiles(): Promise<string[] | undefined> {
406 return Promise.resolve([]);
407 },
408 getRobotCommentFixPreview(): Promise<FilePathToDiffInfoMap | undefined> {
409 return Promise.resolve({});
410 },
411 getSuggestedAccounts(): Promise<AccountInfo[] | undefined> {
412 return Promise.resolve([]);
413 },
414 getSuggestedGroups(): Promise<GroupNameToGroupInfoMap | undefined> {
415 return Promise.resolve({});
416 },
417 getSuggestedProjects(): Promise<NameToProjectInfoMap | undefined> {
418 return Promise.resolve({});
419 },
420 getTopMenus(): Promise<TopMenuEntryInfo[] | undefined> {
421 return Promise.resolve([]);
422 },
423 getVersion(): Promise<string | undefined> {
424 return Promise.resolve('');
425 },
426 getWatchedProjects(): Promise<ProjectWatchInfo[] | undefined> {
427 return Promise.resolve([]);
428 },
429 hasPendingDiffDrafts(): number {
430 return 0;
431 },
432 invalidateAccountsCache(): void {},
433 invalidateGroupsCache(): void {},
434 invalidateReposCache(): void {},
Przemyslaw Waliszewski5e036062021-05-31 17:10:18 +0200435 invalidateAccountsDetailCache(): void {},
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100436 probePath(): Promise<boolean> {
437 return Promise.resolve(true);
438 },
439 putChangeCommitMessage(): Promise<Response> {
440 return Promise.resolve(new Response());
441 },
442 queryChangeFiles(): Promise<string[] | undefined> {
443 return Promise.resolve([]);
444 },
445 removeChangeReviewer(): Promise<Response | undefined> {
446 return Promise.resolve(new Response());
447 },
448 removeFromAttentionSet(): Promise<Response> {
449 return Promise.resolve(new Response());
450 },
451 renameFileInChangeEdit(): Promise<Response | undefined> {
452 return Promise.resolve(new Response());
453 },
454 restoreFileInChangeEdit(): Promise<Response | undefined> {
455 return Promise.resolve(new Response());
456 },
457 runRepoGC(): Promise<Response> {
458 return Promise.resolve(new Response());
459 },
460 saveAccountAgreement(): Promise<Response> {
461 return Promise.resolve(new Response());
462 },
463 saveChangeEdit(): Promise<Response> {
464 return Promise.resolve(new Response());
465 },
466 saveChangeReview() {
467 return Promise.resolve(new Response());
468 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100469 saveChangeStarred(): Promise<Response> {
470 return Promise.resolve(new Response());
471 },
472 saveDiffDraft(): Promise<Response> {
473 return Promise.resolve(new Response());
474 },
475 saveDiffPreferences(): Promise<Response> {
476 return Promise.resolve(new Response());
477 },
478 saveEditPreferences(): Promise<Response> {
479 return Promise.resolve(new Response());
480 },
481 saveFileReviewed(): Promise<Response> {
482 return Promise.resolve(new Response());
483 },
484 saveFileUploadChangeEdit(): Promise<Response | undefined> {
485 return Promise.resolve(new Response());
486 },
487 saveGroupDescription(): Promise<Response> {
488 return Promise.resolve(new Response());
489 },
490 saveGroupMember(): Promise<AccountInfo> {
491 return Promise.resolve({});
492 },
493 saveGroupName(): Promise<Response> {
494 return Promise.resolve(new Response());
495 },
496 saveGroupOptions(): Promise<Response> {
497 return Promise.resolve(new Response());
498 },
499 saveGroupOwner(): Promise<Response> {
500 return Promise.resolve(new Response());
501 },
502 saveIncludedGroup(): Promise<GroupInfo | undefined> {
503 throw new Error('saveIncludedGroup() not implemented by RestApiMock.');
504 },
Dhruv Srivastava86be2a32021-10-15 10:46:42 +0200505 savePreferences(): Promise<PreferencesInfo> {
506 return Promise.resolve(createDefaultPreferences());
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100507 },
508 saveRepoConfig(): Promise<Response> {
509 return Promise.resolve(new Response());
510 },
511 saveWatchedProjects(): Promise<ProjectWatchInfo[]> {
512 return Promise.resolve([]);
513 },
514 send() {
515 return Promise.resolve(new Response());
516 },
517 setAccountDisplayName(): Promise<void> {
518 return Promise.resolve();
519 },
520 setAccountName(): Promise<void> {
521 return Promise.resolve();
522 },
523 setAccountStatus(): Promise<void> {
524 return Promise.resolve();
525 },
526 setAccountUsername(): Promise<void> {
527 return Promise.resolve();
528 },
Ben Rohlfs3a6ff7e2021-01-18 14:08:39 +0100529 setChangeHashtag(): Promise<Hashtag[]> {
530 return Promise.resolve([]);
531 },
532 setChangeTopic(): Promise<string> {
533 return Promise.resolve('');
534 },
535 setDescription(): Promise<Response> {
536 return Promise.resolve(new Response());
537 },
538 setInProjectLookup(): void {},
539 setPreferredAccountEmail(): Promise<void> {
540 return Promise.resolve();
541 },
542 setRepoAccessRights(): Promise<Response> {
543 return Promise.resolve(new Response());
544 },
545 setRepoAccessRightsForReview(): Promise<ChangeInfo> {
546 throw new Error('setRepoAccessRightsForReview() not implemented by mock.');
547 },
548 setRepoHead(): Promise<Response> {
549 return Promise.resolve(new Response());
550 },
551};