/**
 * @license
 * Copyright 2016 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import '../../test/common-test-setup';
import {
  addListenerForTest,
  assertFails,
  makePrefixedJSON,
  MockPromise,
  mockPromise,
  waitEventLoop,
} from '../../test/test-utils';
import {GrReviewerUpdatesParser} from '../../elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser';
import {listChangesOptionsToHex} from '../../utils/change-util';
import {
  createAccountDetailWithId,
  createAccountWithId,
  createChange,
  createComment,
  createParsedChange,
  createServerInfo,
  TEST_PROJECT_NAME,
} from '../../test/test-data-generators';
import {CURRENT} from '../../utils/patch-set-util';
import {GrRestApiServiceImpl} from './gr-rest-api-impl';
import {
  CommentSide,
  createDefaultEditPrefs,
  HttpMethod,
} from '../../constants/constants';
import {
  AccountDetailInfo,
  BasePatchSetNum,
  ChangeInfo,
  ChangeMessageId,
  CommentInfo,
  DashboardId,
  EDIT,
  Hashtag,
  ListChangesOption,
  NumericChangeId,
  PARENT,
  ParsedJSON,
  PatchSetNum,
  RepoName,
  RevisionPatchSetNum,
  RobotCommentInfo,
  Timestamp,
  UrlEncodedCommentId,
} from '../../types/common';
import {assert} from '@open-wc/testing';
import {AuthService} from '../gr-auth/gr-auth';
import {GrAuthMock} from '../gr-auth/gr-auth_mock';
import {FlagsServiceImplementation} from '../flags/flags_impl';

const EXPECTED_QUERY_OPTIONS = listChangesOptionsToHex(
  ListChangesOption.CHANGE_ACTIONS,
  // Current actions can be costly to calculate (e.g submit action)
  // They are not used in bulk actions.
  // ListChangesOption.CURRENT_ACTIONS,
  ListChangesOption.CURRENT_REVISION,
  ListChangesOption.DETAILED_LABELS,
  ListChangesOption.SUBMIT_REQUIREMENTS
);

suite('gr-rest-api-service-impl tests', () => {
  let element: GrRestApiServiceImpl;
  let authService: AuthService;

  let ctr = 0;
  let originalCanonicalPath: string | undefined;

  setup(() => {
    // Modify CANONICAL_PATH to effectively reset cache.
    ctr += 1;
    originalCanonicalPath = window.CANONICAL_PATH;
    window.CANONICAL_PATH = `test${ctr}`;

    const testJSON = ')]}\'\n{"hello": "bonjour"}';
    sinon.stub(window, 'fetch').resolves(new Response(testJSON));
    // fake auth
    authService = new GrAuthMock();
    sinon.stub(authService, 'authCheck').resolves(true);
    element = new GrRestApiServiceImpl(
      authService,
      new FlagsServiceImplementation()
    );

    element._projectLookup = {};
  });

  teardown(() => {
    window.CANONICAL_PATH = originalCanonicalPath;
  });

  test('parent diff comments are properly grouped', async () => {
    element.addRepoNameToCache(42 as NumericChangeId, TEST_PROJECT_NAME);
    sinon.stub(element._restApiHelper, 'fetchJSON').resolves({
      '/COMMIT_MSG': [],
      'sieve.go': [
        {
          updated: '2017-02-03 22:32:28.000000000',
          message: 'this isn’t quite right',
        },
        {
          side: CommentSide.PARENT,
          message: 'how did this work in the first place?',
          updated: '2017-02-03 22:33:28.000000000',
        },
      ],
    } as unknown as ParsedJSON);
    const obj = await element._getDiffComments(
      42 as NumericChangeId,
      '/comments',
      undefined,
      PARENT,
      1 as PatchSetNum,
      'sieve.go'
    );
    assert.equal(obj.baseComments.length, 1);
    assert.deepEqual(obj.baseComments[0], {
      side: CommentSide.PARENT,
      message: 'how did this work in the first place?',
      path: 'sieve.go',
      updated: '2017-02-03 22:33:28.000000000' as Timestamp,
    } as RobotCommentInfo);
    assert.equal(obj.comments.length, 1);
    assert.deepEqual(obj.comments[0], {
      message: 'this isn’t quite right',
      path: 'sieve.go',
      updated: '2017-02-03 22:32:28.000000000' as Timestamp,
    } as RobotCommentInfo);
  });

  test('_setRange', () => {
    const comments: CommentInfo[] = [
      {
        id: '1' as UrlEncodedCommentId,
        side: CommentSide.PARENT,
        message: 'how did this work in the first place?',
        updated: '2017-02-03 22:32:28.000000000' as Timestamp,
        range: {
          start_line: 1,
          start_character: 1,
          end_line: 2,
          end_character: 1,
        },
      },
      {
        id: '2' as UrlEncodedCommentId,
        in_reply_to: '1' as UrlEncodedCommentId,
        message: 'this isn’t quite right',
        updated: '2017-02-03 22:33:28.000000000' as Timestamp,
      },
    ];
    const expectedResult: CommentInfo = {
      id: '2' as UrlEncodedCommentId,
      in_reply_to: '1' as UrlEncodedCommentId,
      message: 'this isn’t quite right',
      updated: '2017-02-03 22:33:28.000000000' as Timestamp,
      range: {
        start_line: 1,
        start_character: 1,
        end_line: 2,
        end_character: 1,
      },
    };
    const comment = comments[1];
    assert.deepEqual(element._setRange(comments, comment), expectedResult);
  });

  test('_setRanges', () => {
    const comments: CommentInfo[] = [
      {
        id: '3' as UrlEncodedCommentId,
        in_reply_to: '2' as UrlEncodedCommentId,
        message: 'this isn’t quite right either',
        updated: '2017-02-03 22:34:28.000000000' as Timestamp,
      },
      {
        id: '2' as UrlEncodedCommentId,
        in_reply_to: '1' as UrlEncodedCommentId,
        message: 'this isn’t quite right',
        updated: '2017-02-03 22:33:28.000000000' as Timestamp,
      },
      {
        id: '1' as UrlEncodedCommentId,
        side: CommentSide.PARENT,
        message: 'how did this work in the first place?',
        updated: '2017-02-03 22:32:28.000000000' as Timestamp,
        range: {
          start_line: 1,
          start_character: 1,
          end_line: 2,
          end_character: 1,
        },
      },
    ];
    const expectedResult: CommentInfo[] = [
      {
        id: '1' as UrlEncodedCommentId,
        side: CommentSide.PARENT,
        message: 'how did this work in the first place?',
        updated: '2017-02-03 22:32:28.000000000' as Timestamp,
        range: {
          start_line: 1,
          start_character: 1,
          end_line: 2,
          end_character: 1,
        },
      },
      {
        id: '2' as UrlEncodedCommentId,
        in_reply_to: '1' as UrlEncodedCommentId,
        message: 'this isn’t quite right',
        updated: '2017-02-03 22:33:28.000000000' as Timestamp,
        range: {
          start_line: 1,
          start_character: 1,
          end_line: 2,
          end_character: 1,
        },
      },
      {
        id: '3' as UrlEncodedCommentId,
        in_reply_to: '2' as UrlEncodedCommentId,
        message: 'this isn’t quite right either',
        updated: '2017-02-03 22:34:28.000000000' as Timestamp,
        range: {
          start_line: 1,
          start_character: 1,
          end_line: 2,
          end_character: 1,
        },
      },
    ];
    assert.deepEqual(element._setRanges(comments), expectedResult);
  });

  test('differing patch diff comments are properly grouped', async () => {
    sinon.stub(element, 'getRepoName').resolves('test' as RepoName);
    sinon.stub(element._restApiHelper, 'fetchJSON').callsFake(async request => {
      const url = request.url;
      if (url === '/changes/test~42/revisions/1/comments') {
        return {
          '/COMMIT_MSG': [],
          'sieve.go': [
            {
              message: 'this isn’t quite right',
              updated: '2017-02-03 22:32:28.000000000',
            },
            {
              side: CommentSide.PARENT,
              message: 'how did this work in the first place?',
              updated: '2017-02-03 22:33:28.000000000',
            },
          ],
        } as unknown as ParsedJSON;
      } else if (url === '/changes/test~42/revisions/2/comments') {
        return {
          '/COMMIT_MSG': [],
          'sieve.go': [
            {
              message: 'What on earth are you thinking, here?',
              updated: '2017-02-03 22:32:28.000000000',
            },
            {
              side: CommentSide.PARENT,
              message: 'Yeah not sure how this worked either?',
              updated: '2017-02-03 22:33:28.000000000',
            },
            {
              message: '¯\\_(ツ)_/¯',
              updated: '2017-02-04 22:33:28.000000000',
            },
          ],
        } as unknown as ParsedJSON;
      }
      return undefined;
    });
    const obj = await element._getDiffComments(
      42 as NumericChangeId,
      '/comments',
      undefined,
      1 as BasePatchSetNum,
      2 as PatchSetNum,
      'sieve.go'
    );
    assert.equal(obj.baseComments.length, 1);
    assert.deepEqual(obj.baseComments[0], {
      message: 'this isn’t quite right',
      path: 'sieve.go',
      updated: '2017-02-03 22:32:28.000000000' as Timestamp,
    } as RobotCommentInfo);
    assert.equal(obj.comments.length, 2);
    assert.deepEqual(obj.comments[0], {
      message: 'What on earth are you thinking, here?',
      path: 'sieve.go',
      updated: '2017-02-03 22:32:28.000000000' as Timestamp,
    } as RobotCommentInfo);
    assert.deepEqual(obj.comments[1], {
      message: '¯\\_(ツ)_/¯',
      path: 'sieve.go',
      updated: '2017-02-04 22:33:28.000000000' as Timestamp,
    } as RobotCommentInfo);
  });

  test('legacy n,z key in change url is replaced', async () => {
    const stub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves([] as unknown as ParsedJSON);
    await element.getChanges(1, undefined, 'n,z');
    assert.equal(stub.lastCall.args[0].params!.S, 0);
  });

  test('saveDiffPreferences invalidates cache line', () => {
    const cacheKey = '/accounts/self/preferences.diff';
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch');
    element._cache.set(cacheKey, {tab_size: 4} as unknown as ParsedJSON);
    element.saveDiffPreferences({
      tab_size: 8,
      ignore_whitespace: 'IGNORE_NONE',
    });
    assert.isTrue(fetchStub.called);
    assert.isFalse(element._cache.has(cacheKey));
  });

  suite('queryAccounts', () => {
    let fetchStub: sinon.SinonStub;
    const testProject = 'testproject';
    const testChangeNumber = 341682;
    setup(() => {
      fetchStub = sinon
        .stub(element._restApiHelper, 'fetch')
        .resolves(new Response(makePrefixedJSON(createAccountWithId())));
      element.addRepoNameToCache(
        testChangeNumber as NumericChangeId,
        testProject as RepoName
      );
    });

    test('url with just email', async () => {
      await element.queryAccounts('bro');
      assert.isTrue(fetchStub.calledOnce);
      assert.deepEqual(fetchStub.firstCall.args[0].params, {
        o: 'DETAILS',
        q: '"bro"',
      });
    });

    test('url with email and canSee changeId', async () => {
      await element.queryAccounts(
        'bro',
        undefined,
        testChangeNumber as NumericChangeId
      );
      assert.isTrue(fetchStub.calledOnce);
      assert.deepEqual(fetchStub.firstCall.args[0].params, {
        o: 'DETAILS',
        q: `"bro" and cansee:${testProject}~${testChangeNumber}`,
      });
    });

    test('url with email and canSee changeId and isActive', async () => {
      await element.queryAccounts(
        'bro',
        undefined,
        testChangeNumber as NumericChangeId,
        true
      );
      assert.isTrue(fetchStub.calledOnce);
      assert.deepEqual(fetchStub.firstCall.args[0].params, {
        o: 'DETAILS',
        q: `"bro" and cansee:${testProject}~${testChangeNumber} and is:active`,
      });
    });
  });

  test('getAccountSuggestions using suggest query param', () => {
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetch')
      .resolves(new Response());
    element.getAccountSuggestions('user');
    assert.isTrue(fetchStub.calledOnce);
    assert.deepEqual(fetchStub.firstCall.args[0].params, {
      suggest: undefined,
      q: 'user',
    });
  });

  test('getAccount when resp is undefined clears cache', async () => {
    const cacheKey = '/accounts/self/detail';
    const account = createAccountDetailWithId();
    element._cache.set(cacheKey, account as unknown as ParsedJSON);
    const stub = sinon
      .stub(element._restApiHelper, 'fetchCacheJSON')
      .callsFake(async req => {
        req.errFn!(undefined);
        return undefined;
      });
    assert.isTrue(element._cache.has(cacheKey));

    await element.getAccount();
    assert.isTrue(stub.called);
    assert.isFalse(element._cache.has(cacheKey));
  });

  test('getAccount when status is 403 clears cache', async () => {
    const cacheKey = '/accounts/self/detail';
    const account = createAccountDetailWithId();
    element._cache.set(cacheKey, account as unknown as ParsedJSON);
    const stub = sinon
      .stub(element._restApiHelper, 'fetchCacheJSON')
      .callsFake(async req => {
        req.errFn!(new Response(undefined, {status: 403}));
        return undefined;
      });
    assert.isTrue(element._cache.has(cacheKey));

    await element.getAccount();
    assert.isTrue(stub.called);
    assert.isFalse(element._cache.has(cacheKey));
  });

  test('getAccount when resp is successful updates cache', async () => {
    const cacheKey = '/accounts/self/detail';
    const account = createAccountDetailWithId();
    const stub = sinon
      .stub(element._restApiHelper, 'fetchCacheJSON')
      .callsFake(async () => {
        element._cache.set(cacheKey, account as unknown as ParsedJSON);
        return undefined;
      });
    assert.isFalse(element._cache.has(cacheKey));

    await element.getAccount();
    assert.isTrue(stub.called);
    assert.equal(
      element._cache.get(cacheKey),
      account as unknown as ParsedJSON
    );
  });

  const preferenceSetup = function (testJSON: unknown, loggedIn: boolean) {
    sinon
      .stub(element, 'getLoggedIn')
      .callsFake(() => Promise.resolve(loggedIn));
    sinon
      .stub(element._restApiHelper, 'fetchCacheJSON')
      .callsFake(() => Promise.resolve(testJSON as ParsedJSON));
  };

  test('getPreferences returns correctly logged in', async () => {
    const testJSON = {diff_view: 'SIDE_BY_SIDE'};
    const loggedIn = true;

    preferenceSetup(testJSON, loggedIn);

    const obj = await element.getPreferences();
    assert.equal(obj!.diff_view, 'SIDE_BY_SIDE');
  });

  test('getPreferences returns correctly on larger screens logged in', async () => {
    const testJSON = {diff_view: 'UNIFIED_DIFF'};
    const loggedIn = true;

    preferenceSetup(testJSON, loggedIn);

    const obj = await element.getPreferences();
    assert.equal(obj!.diff_view, 'UNIFIED_DIFF');
  });

  test('getPreferences returns correctly on larger screens no login', async () => {
    const testJSON = {diff_view: 'UNIFIED_DIFF'};
    const loggedIn = false;

    preferenceSetup(testJSON, loggedIn);

    const obj = await element.getPreferences();
    assert.equal(obj!.diff_view, 'SIDE_BY_SIDE');
  });

  test('savePreferences normalizes download scheme', () => {
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetch')
      .resolves(new Response());
    element.savePreferences({download_scheme: 'HTTP'});
    assert.isTrue(fetchStub.called);
    assert.equal(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string)
        .download_scheme,
      'http'
    );
  });

  test('getDiffPreferences returns correct defaults', async () => {
    sinon.stub(element, 'getLoggedIn').callsFake(() => Promise.resolve(false));

    const obj = (await element.getDiffPreferences())!;
    assert.equal(obj.context, 10);
    assert.equal(obj.cursor_blink_rate, 0);
    assert.equal(obj.font_size, 12);
    assert.equal(obj.ignore_whitespace, 'IGNORE_NONE');
    assert.equal(obj.line_length, 100);
    assert.equal(obj.line_wrapping, false);
    assert.equal(obj.show_line_endings, true);
    assert.equal(obj.show_tabs, true);
    assert.equal(obj.show_whitespace_errors, true);
    assert.equal(obj.syntax_highlighting, true);
    assert.equal(obj.tab_size, 8);
  });

  test('saveDiffPreferences set show_tabs to false', () => {
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch');
    element.saveDiffPreferences({
      show_tabs: false,
      ignore_whitespace: 'IGNORE_NONE',
    });
    assert.isTrue(fetchStub.called);
    assert.equal(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string)
        .show_tabs,
      false
    );
  });

  test('getEditPreferences returns correct defaults', async () => {
    sinon.stub(element, 'getLoggedIn').callsFake(() => Promise.resolve(false));

    const obj = (await element.getEditPreferences())!;
    assert.equal(obj.auto_close_brackets, false);
    assert.equal(obj.cursor_blink_rate, 0);
    assert.equal(obj.hide_line_numbers, false);
    assert.equal(obj.hide_top_menu, false);
    assert.equal(obj.indent_unit, 2);
    assert.equal(obj.indent_with_tabs, false);
    assert.equal(obj.key_map_type, 'DEFAULT');
    assert.equal(obj.line_length, 100);
    assert.equal(obj.line_wrapping, false);
    assert.equal(obj.match_brackets, true);
    assert.equal(obj.show_base, false);
    assert.equal(obj.show_tabs, true);
    assert.equal(obj.show_whitespace_errors, true);
    assert.equal(obj.syntax_highlighting, true);
    assert.equal(obj.tab_size, 8);
    assert.equal(obj.theme, 'DEFAULT');
  });

  test('saveEditPreferences set show_tabs to false', () => {
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch');
    element.saveEditPreferences({
      ...createDefaultEditPrefs(),
      show_tabs: false,
    });
    assert.isTrue(fetchStub.called);
    assert.equal(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string)
        .show_tabs,
      false
    );
  });

  test('confirmEmail', () => {
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    element.confirmEmail('foo');
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/config/server/email.confirm'
    );
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {token: 'foo'}
    );
  });

  test('setPreferredAccountEmail', async () => {
    const email1 = 'email1@example.com';
    const email2 = 'email2@example.com';
    const encodedEmail = encodeURIComponent(email2);
    const sendStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    element._cache.set('/accounts/self/emails', [
      {email: email1, preferred: true},
      {email: email2, preferred: false},
    ] as unknown as ParsedJSON);

    await element.setPreferredAccountEmail(email2);
    assert.isTrue(sendStub.calledOnce);
    assert.equal(
      sendStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(
      sendStub.lastCall.args[0].url,
      `/accounts/self/emails/${encodedEmail}/preferred`
    );
    assert.deepEqual(element._cache.get('/accounts/self/emails'), [
      {email: email1, preferred: false},
      {email: email2, preferred: true},
    ] as unknown as ParsedJSON);
  });

  test('setAccountStatus', async () => {
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves('OOO' as unknown as ParsedJSON);
    element._cache.set(
      '/accounts/self/detail',
      createAccountDetailWithId() as unknown as ParsedJSON
    );
    await element.setAccountStatus('OOO');
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(fetchStub.lastCall.args[0].url, '/accounts/self/status');
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {status: 'OOO'}
    );
    assert.deepEqual(
      (element._cache.get(
        '/accounts/self/detail'
      ) as unknown as AccountDetailInfo)!.status,
      'OOO'
    );
  });

  suite('draft comments', () => {
    test('_sendDiffDraftRequest pending requests tracked', async () => {
      const obj = element._pendingRequests;
      const promises: MockPromise<string>[] = [];
      sinon.stub(element, '_changeBaseURL').callsFake(() => {
        promises.push(mockPromise<string>());
        return promises[promises.length - 1];
      });
      sinon
        .stub(element._restApiHelper, 'fetch')
        .resolves(new Response(undefined, {status: 201}));
      assert.isFalse(!!element.hasPendingDiffDrafts());

      element._sendDiffDraftRequest(
        HttpMethod.PUT,
        123 as NumericChangeId,
        1 as PatchSetNum,
        {}
      );
      assert.equal(obj.sendDiffDraft.length, 1);
      assert.isTrue(!!element.hasPendingDiffDrafts());

      element._sendDiffDraftRequest(
        HttpMethod.PUT,
        123 as NumericChangeId,
        1 as PatchSetNum,
        {}
      );
      assert.equal(obj.sendDiffDraft.length, 2);
      assert.isTrue(!!element.hasPendingDiffDrafts());

      for (const promise of promises) {
        promise.resolve('');
      }

      await element.awaitPendingDiffDrafts();
      assert.equal(obj.sendDiffDraft.length, 0);
      assert.isFalse(!!element.hasPendingDiffDrafts());
    });

    suite('_failForCreate200', () => {
      test('_sendDiffDraftRequest checks for 200 on create', async () => {
        element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
        sinon.stub(element._restApiHelper, 'fetch').resolves(new Response());
        const failStub = sinon.stub(element, '_failForCreate200').resolves();
        await element._sendDiffDraftRequest(
          HttpMethod.PUT,
          123 as NumericChangeId,
          4 as PatchSetNum,
          {}
        );
        assert.isTrue(failStub.calledOnce);
      });

      test('_sendDiffDraftRequest no checks for 200 on non create', async () => {
        element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
        sinon.stub(element._restApiHelper, 'fetch').resolves(new Response());
        const failStub = sinon.stub(element, '_failForCreate200').resolves();
        await element._sendDiffDraftRequest(
          HttpMethod.PUT,
          123 as NumericChangeId,
          4 as PatchSetNum,
          {
            id: '123' as UrlEncodedCommentId,
          }
        );
        assert.isFalse(failStub.called);
      });

      test('_failForCreate200 fails on 200', async () => {
        const result = new Response(undefined, {
          status: 200,
          headers: {
            'Set-CoOkiE': 'secret',
            Innocuous: 'hello',
          },
        });
        const error = await assertFails<Error>(
          element._failForCreate200(Promise.resolve(result))
        );
        assert.isOk(error);
        assert.include(error.message, 'Saving draft resulted in HTTP 200');
        assert.include(error.message, 'hello');
        assert.notInclude(error.message, 'secret');
      });

      test('_failForCreate200 does not fail on 201', () => {
        const result = new Response(undefined, {status: 201});
        return element._failForCreate200(Promise.resolve(result));
      });
    });
  });

  test('saveChangeEdit', async () => {
    element._projectLookup = {1: Promise.resolve('test' as RepoName)};
    const change_num = 1 as NumericChangeId;
    const file_name = 'index.php';
    const file_contents = '<?php';
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    element._cache.set(
      `/changes/${change_num}/edit/${file_name}`,
      {} as unknown as ParsedJSON
    );
    await element.saveChangeEdit(change_num, file_name, file_contents);
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/changes/test~1/edit/' + file_name
    );
    assert.equal(fetchStub.lastCall.args[0].fetchOptions?.body, file_contents);
  });

  test('putChangeCommitMessage', async () => {
    element._projectLookup = {1: Promise.resolve('test' as RepoName)};
    const change_num = 1 as NumericChangeId;
    const message = 'this is a commit message';
    const committer_email = 'test@example.com';
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    element._cache.set(
      `/changes/${change_num}/message`,
      {} as unknown as ParsedJSON
    );
    await element.putChangeCommitMessage(change_num, message, committer_email);
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(fetchStub.lastCall.args[0].url, '/changes/test~1/message');
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {
        message,
        committer_email,
      }
    );
  });

  test('updateIdentityInChangeEdit', async () => {
    element._projectLookup = {1: Promise.resolve('test' as RepoName)};
    const change_num = 1 as NumericChangeId;
    const name = 'user';
    const email = 'user@example.com';
    const type = 'AUTHOR';
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    await element.updateIdentityInChangeEdit(change_num, name, email, type);
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.PUT
    );
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/changes/test~1/edit:identity'
    );
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {
        email: 'user@example.com',
        name: 'user',
        type: 'AUTHOR',
      }
    );
  });

  test('deleteChangeCommitMessage', async () => {
    element._projectLookup = {1: Promise.resolve('test' as RepoName)};
    const change_num = 1 as NumericChangeId;
    const messageId = 'abc' as ChangeMessageId;
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    await element.deleteChangeCommitMessage(change_num, messageId);
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.DELETE
    );
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/changes/test~1/messages/abc'
    );
  });

  test('startWorkInProgress', async () => {
    element.addRepoNameToCache(42 as NumericChangeId, TEST_PROJECT_NAME);
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetch')
      .resolves(new Response());
    const urlSpy = sinon.spy(element, '_changeBaseURL');
    await element.startWorkInProgress(42 as NumericChangeId);
    assert.isTrue(fetchStub.calledOnce);
    assert.isTrue(urlSpy.calledOnce);
    assert.equal(urlSpy.lastCall.args[0], 42 as NumericChangeId);
    assert.isNotOk(urlSpy.lastCall.args[1]);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.POST
    );
    assert.isTrue(fetchStub.lastCall.args[0].url.endsWith('/wip'));
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {}
    );

    await element.startWorkInProgress(42 as NumericChangeId, 'revising...');
    assert.isTrue(fetchStub.calledTwice);
    assert.equal(urlSpy.lastCall.args[0], 42 as NumericChangeId);
    assert.isNotOk(urlSpy.lastCall.args[1]);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.POST
    );
    assert.isTrue(fetchStub.lastCall.args[0].url.endsWith('/wip'));
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {
        message: 'revising...',
      }
    );
  });

  test('deleteComment', async () => {
    element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
    const comment = createComment();
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves(comment as unknown as ParsedJSON);
    const response = await element.deleteComment(
      123 as NumericChangeId,
      1 as PatchSetNum,
      '01234' as UrlEncodedCommentId,
      'removal reason'
    );
    assert.equal(response, comment);
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(
      fetchStub.lastCall.args[0].fetchOptions?.method,
      HttpMethod.POST
    );
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/changes/test-project~123/revisions/1/comments/01234/delete'
    );
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {
        reason: 'removal reason',
      }
    );
  });

  test('createRepo encodes name', async () => {
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();
    await element.createRepo({name: 'x/y' as RepoName});
    assert.isTrue(fetchStub.calledOnce);
    assert.equal(fetchStub.lastCall.args[0].url, '/projects/x%2Fy');
  });

  test('queryChangeFiles', async () => {
    element.addRepoNameToCache(42 as NumericChangeId, TEST_PROJECT_NAME);
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves();
    await element.queryChangeFiles(42 as NumericChangeId, EDIT, 'test/path.js');
    assert.equal(
      fetchStub.lastCall.args[0].url,
      '/changes/test-project~42/revisions/edit/files?q=test%2Fpath.js'
    );
  });

  test('normal use', () => {
    const defaultQuery = '';

    assert.equal(
      element._getReposUrl('test', 25).toString(),
      [false, '/projects/?n=26&S=0&d=&m=test'].toString()
    );

    assert.equal(
      element._getReposUrl(undefined, 25).toString(),
      [false, `/projects/?n=26&S=0&d=&m=${defaultQuery}`].toString()
    );

    assert.equal(
      element._getReposUrl('test', 25, 25).toString(),
      [false, '/projects/?n=26&S=25&d=&m=test'].toString()
    );

    assert.equal(
      element._getReposUrl('inname:test', 25, 25).toString(),
      [true, '/projects/?n=26&S=25&query=inname%3Atest'].toString()
    );
  });

  test('invalidateReposCache', () => {
    const url = '/projects/?n=26&S=0&query=test';

    element._cache.set(url, {} as unknown as ParsedJSON);

    element.invalidateReposCache();

    assert.isUndefined(element._sharedFetchPromises.get(url));

    assert.isFalse(element._cache.has(url));
  });

  test('invalidateAccountsCache', () => {
    const url = '/accounts/self/detail';

    element._cache.set(url, {} as unknown as ParsedJSON);

    element.invalidateAccountsCache();

    assert.isUndefined(element._sharedFetchPromises.get(url));

    assert.isFalse(element._cache.has(url));
  });

  suite('getRepos', () => {
    const defaultQuery = '';
    let fetchCacheJSONStub: sinon.SinonStub;
    setup(() => {
      fetchCacheJSONStub = sinon
        .stub(element._restApiHelper, 'fetchCacheJSON')
        .resolves([] as unknown as ParsedJSON);
    });

    test('normal use', () => {
      element.getRepos('test', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=test'
      );

      element.getRepos(undefined, 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        `/projects/?n=26&S=0&d=&m=${defaultQuery}`
      );

      element.getRepos('test', 25, 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=25&d=&m=test'
      );
    });

    test('with blank', () => {
      element.getRepos('test/test', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=test%2Ftest'
      );
    });

    test('with hyphen', () => {
      element.getRepos('foo-bar', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=foo-bar'
      );
    });

    test('with leading hyphen', () => {
      element.getRepos('-bar', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=-bar'
      );
    });

    test('with trailing hyphen', () => {
      element.getRepos('foo-bar-', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=foo-bar-'
      );
    });

    test('with underscore', () => {
      element.getRepos('foo_bar', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=foo_bar'
      );
    });

    test('with underscore', () => {
      element.getRepos('foo_bar', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=foo_bar'
      );
    });

    test('hyphen only', () => {
      element.getRepos('-', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&d=&m=-'
      );
    });

    test('using query', () => {
      element.getRepos('description:project', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/projects/?n=26&S=0&query=description%3Aproject'
      );
    });
  });

  test('_getGroupsUrl normal use', () => {
    assert.equal(element._getGroupsUrl('test', 25), '/groups/?n=26&S=0&m=test');

    assert.equal(element._getGroupsUrl('', 25), '/groups/?n=26&S=0');

    assert.equal(
      element._getGroupsUrl('test', 25, 25),
      '/groups/?n=26&S=25&m=test'
    );
  });

  test('invalidateGroupsCache', () => {
    const url = '/groups/?n=26&S=0&m=test';

    element._cache.set(url, {} as unknown as ParsedJSON);

    element.invalidateGroupsCache();

    assert.isUndefined(element._sharedFetchPromises.get(url));

    assert.isFalse(element._cache.has(url));
  });

  suite('getGroups', () => {
    let fetchCacheJSONStub: sinon.SinonStub;
    setup(() => {
      fetchCacheJSONStub = sinon.stub(element._restApiHelper, 'fetchCacheJSON');
    });

    test('normal use', () => {
      element.getGroups('test', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/groups/?n=26&S=0&m=test'
      );

      element.getGroups('', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/groups/?n=26&S=0'
      );

      element.getGroups('test', 25, 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/groups/?n=26&S=25&m=test'
      );
    });

    test('regex', () => {
      element.getGroups('^test.*', 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/groups/?n=26&S=0&r=%5Etest.*'
      );

      element.getGroups('^test.*', 25, 25);
      assert.equal(
        fetchCacheJSONStub.lastCall.args[0].url,
        '/groups/?n=26&S=25&r=%5Etest.*'
      );
    });
  });

  test('gerrit auth is used', () => {
    const fetchStub = sinon.stub(authService, 'fetch').resolves();
    element._restApiHelper.fetchJSON({url: 'foo'});
    assert(fetchStub.called);
  });

  test('queryAccounts does not return fetchJSON', async () => {
    const fetchJSONSpy = sinon.spy(element._restApiHelper, 'fetchJSON');
    const accts = await element.queryAccounts('');
    assert.isFalse(fetchJSONSpy.called);
    assert.equal(accts!.length, 0);
  });

  test('fetchJSON gets called by queryAccounts', async () => {
    const fetchJSONStub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves();
    await element.queryAccounts('own');
    assert.deepEqual(fetchJSONStub.lastCall.args[0].params, {
      q: '"own"',
      o: 'DETAILS',
    });
  });

  suite('getChangeDetail', () => {
    let getConfigStub: sinon.SinonStub;

    setup(() => {
      getConfigStub = sinon
        .stub(element, 'getConfig')
        .resolves(createServerInfo());
    });

    suite('change detail options', () => {
      let changeDetailStub: sinon.SinonStub;
      setup(() => {
        changeDetailStub = sinon
          .stub(element, '_getChangeDetail')
          .resolves({...createChange(), _number: 123 as NumericChangeId});
      });

      test('signed pushes disabled', async () => {
        getConfigStub.resolves({
          ...createServerInfo(),
          receive: {enable_signed_push: undefined},
        });
        const change = await element.getChangeDetail(123 as NumericChangeId);
        assert.strictEqual(123, change!._number);
        const options = changeDetailStub.firstCall.args[1];
        assert.isNotOk(
          parseInt(options, 16) & (1 << ListChangesOption.PUSH_CERTIFICATES)
        );
      });

      test('signed pushes enabled', async () => {
        getConfigStub.resolves({
          ...createServerInfo(),
          receive: {enable_signed_push: 'true'},
        });
        const change = await element.getChangeDetail(123 as NumericChangeId);
        assert.strictEqual(123, change!._number);
        const options = changeDetailStub.firstCall.args[1];
        assert.ok(
          parseInt(options, 16) & (1 << ListChangesOption.PUSH_CERTIFICATES)
        );
      });
    });

    test('GrReviewerUpdatesParser.parse is used', async () => {
      element.addRepoNameToCache(42 as NumericChangeId, TEST_PROJECT_NAME);
      const changeInfo = createParsedChange();
      const parseStub = sinon
        .stub(GrReviewerUpdatesParser, 'parse')
        .resolves(changeInfo);
      const result = await element.getChangeDetail(42 as NumericChangeId);
      assert.isTrue(parseStub.calledOnce);
      assert.equal(result, changeInfo);
    });

    test('_getChangeDetail passes params to ETags decorator', async () => {
      const changeNum = 4321 as NumericChangeId;
      element._projectLookup[changeNum] = Promise.resolve('test' as RepoName);
      const expectedUrl = `${window.CANONICAL_PATH}/changes/test~4321/detail?O=516714`;
      const optionsStub = sinon.stub(element._etags, 'getOptions');
      const collectStub = sinon.stub(element._etags, 'collect');
      sinon.stub(element._restApiHelper, 'fetch').resolves(
        new Response(
          makePrefixedJSON({
            ...createChange(),
            _number: 123 as NumericChangeId,
          })
        )
      );
      await element._getChangeDetail(changeNum, '516714');
      assert.isTrue(optionsStub.calledWithExactly(expectedUrl));
      assert.equal(collectStub.lastCall.args[0], expectedUrl);
    });

    test('_getChangeDetail calls errFn on 500', async () => {
      const errFn = sinon.stub();
      sinon.stub(element, 'getChangeActionURL').resolves('');
      sinon
        .stub(element._restApiHelper, 'fetch')
        .resolves(new Response(undefined, {status: 500}));
      await element._getChangeDetail(123 as NumericChangeId, '516714', errFn);
      assert.isTrue(errFn.called);
    });

    test('_getChangeDetail populates _projectLookup', async () => {
      sinon.stub(element, 'getChangeActionURL').resolves('');
      sinon.stub(element._restApiHelper, 'fetch').resolves(
        new Response(')]}\'{"_number":1,"project":"test"}', {
          status: 200,
        })
      );
      await element._getChangeDetail(1 as NumericChangeId, '516714');
      assert.equal(Object.keys(element._projectLookup).length, 1);
      const project = await element._projectLookup[1];
      assert.equal(project, 'test' as RepoName);
    });

    suite('_getChangeDetail ETag cache', () => {
      let requestUrl: string;
      let mockResponseSerial: string;
      let collectSpy: sinon.SinonSpy;

      setup(() => {
        requestUrl = '/foo/bar';
        const mockResponse = {foo: 'bar', baz: 42};
        mockResponseSerial = makePrefixedJSON(mockResponse);
        sinon.stub(element._restApiHelper, 'urlWithParams').returns(requestUrl);
        sinon.stub(element, 'getChangeActionURL').resolves(requestUrl);
        collectSpy = sinon.spy(element._etags, 'collect');
      });

      test('contributes to cache', async () => {
        const getPayloadSpy = sinon.spy(element._etags, 'getCachedPayload');
        sinon.stub(element._restApiHelper, 'fetch').resolves(
          new Response(mockResponseSerial, {
            status: 200,
          })
        );

        await element._getChangeDetail(123 as NumericChangeId, '516714');
        assert.isFalse(getPayloadSpy.called);
        assert.isTrue(collectSpy.calledOnce);
        const cachedResponse = element._etags.getCachedPayload(requestUrl);
        assert.equal(cachedResponse, mockResponseSerial);
      });

      test('uses cache on HTTP 304', async () => {
        const getPayloadStub = sinon.stub(element._etags, 'getCachedPayload');
        getPayloadStub.returns(mockResponseSerial);
        sinon.stub(element._restApiHelper, 'fetch').resolves(
          new Response(undefined, {
            status: 304,
          })
        );

        await element._getChangeDetail(123 as NumericChangeId, '');
        assert.isFalse(collectSpy.called);
        assert.isTrue(getPayloadStub.calledOnce);
      });
    });
  });

  test('addRepoNameToCache', async () => {
    element.addRepoNameToCache(555 as NumericChangeId, 'project' as RepoName);
    const project = await element.getRepoName(555 as NumericChangeId);
    assert.deepEqual(project, 'project' as RepoName);
  });

  suite('getRepoName', () => {
    const changeNum = 555 as NumericChangeId;
    const repo = 'test-repo' as RepoName;

    test('getChange fails to yield a project', async () => {
      const promise = mockPromise<undefined>();
      sinon.stub(element, 'getChange').returns(promise);

      const projectLookup = element.getRepoName(changeNum);
      promise.resolve(undefined);

      const err: Error = await assertFails(projectLookup);
      assert.equal(
        err.message,
        'Failed to lookup the repo for change number 555'
      );
    });

    test('getChange succeeds with project', async () => {
      const promise = mockPromise<undefined | ChangeInfo>();
      sinon.stub(element, 'getChange').returns(promise);

      const projectLookup = element.getRepoName(changeNum);
      promise.resolve({...createChange(), project: repo});

      assert.equal(await projectLookup, repo);
      assert.deepEqual(element._projectLookup, {'555': projectLookup});
    });

    test('getChange fails, but a addRepoNameToCache() call is used as fallback', async () => {
      const promise = mockPromise<undefined>();
      sinon.stub(element, 'getChange').returns(promise);

      const projectLookup = element.getRepoName(changeNum);
      element.addRepoNameToCache(changeNum, repo);
      promise.resolve(undefined);

      assert.equal(await projectLookup, repo);
    });
  });

  suite('getChanges populates _projectLookup', () => {
    test('multiple queries', async () => {
      sinon.stub(element._restApiHelper, 'fetchJSON').resolves([
        [
          {_number: 1, project: 'test'},
          {_number: 2, project: 'test'},
        ],
        [{_number: 3, project: 'test/test'}],
      ] as unknown as ParsedJSON);
      // When query instanceof Array, fetchJSON returns
      // Array<Array<Object>>.
      await element.getChangesForMultipleQueries(undefined, []);
      assert.equal(Object.keys(element._projectLookup).length, 3);
      const project1 = await element.getRepoName(1 as NumericChangeId);
      assert.equal(project1, 'test' as RepoName);
      const project2 = await element.getRepoName(2 as NumericChangeId);
      assert.equal(project2, 'test' as RepoName);
      const project3 = await element.getRepoName(3 as NumericChangeId);
      assert.equal(project3, 'test/test' as RepoName);
    });

    test('no query', async () => {
      sinon.stub(element._restApiHelper, 'fetchJSON').resolves([
        {_number: 1, project: 'test'},
        {_number: 2, project: 'test'},
        {_number: 3, project: 'test/test'},
      ] as unknown as ParsedJSON);

      // When query !instanceof Array, fetchJSON returns Array<Object>.
      await element.getChanges();
      assert.equal(Object.keys(element._projectLookup).length, 3);
      const project1 = await element.getRepoName(1 as NumericChangeId);
      assert.equal(project1, 'test' as RepoName);
      const project2 = await element.getRepoName(2 as NumericChangeId);
      assert.equal(project2, 'test' as RepoName);
      const project3 = await element.getRepoName(3 as NumericChangeId);
      assert.equal(project3, 'test/test' as RepoName);
    });
  });

  test('getDetailedChangesWithActions', async () => {
    const c1 = createChange();
    c1._number = 1 as NumericChangeId;
    const c2 = createChange();
    c2._number = 2 as NumericChangeId;
    const getChangesStub = sinon
      .stub(element, 'getChanges')
      .callsFake((changesPerPage, query, offset, options) => {
        assert.isUndefined(changesPerPage);
        assert.strictEqual(query, 'change:1 OR change:2');
        assert.isUndefined(offset);
        assert.strictEqual(options, EXPECTED_QUERY_OPTIONS);
        return Promise.resolve([]);
      });
    await element.getDetailedChangesWithActions([c1._number, c2._number]);
    assert.isTrue(getChangesStub.calledOnce);
  });

  test('setChangeTopic', async () => {
    element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
    const fetchStub = sinon.stub(element._restApiHelper, 'fetchJSON');
    await element.setChangeTopic(123 as NumericChangeId, 'foo-bar');
    assert.isTrue(fetchStub.calledOnce);
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {topic: 'foo-bar'}
    );
  });

  test('setChangeHashtag', async () => {
    element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
    const fetchStub = sinon.stub(element._restApiHelper, 'fetchJSON');
    await element.setChangeHashtag(123 as NumericChangeId, {
      add: ['foo-bar' as Hashtag],
    });
    assert.isTrue(fetchStub.calledOnce);
    assert.sameDeepMembers(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string).add!,
      ['foo-bar']
    );
  });

  test('generateAccountHttpPassword', async () => {
    const fetchStub = sinon
      .stub(element._restApiHelper, 'fetchJSON')
      .resolves();
    await element.generateAccountHttpPassword();
    assert.isTrue(fetchStub.calledOnce);
    assert.deepEqual(
      JSON.parse(fetchStub.lastCall.args[0].fetchOptions?.body as string),
      {generate: true}
    );
  });

  suite('getChangeFiles', () => {
    test('patch only', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      const range = {basePatchNum: PARENT, patchNum: 2 as RevisionPatchSetNum};
      await element.getChangeFiles(123 as NumericChangeId, range);
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/2/files'
      );
      assert.isNotOk(fetchStub.lastCall.args[0].params);
    });

    test('simple range', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      const range = {
        basePatchNum: 4 as BasePatchSetNum,
        patchNum: 5 as RevisionPatchSetNum,
      };
      await element.getChangeFiles(123 as NumericChangeId, range);
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/5/files'
      );
      assert.isOk(fetchStub.lastCall.args[0].params);
      assert.equal(fetchStub.lastCall.args[0].params!.base, 4);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.parent);
    });

    test('parent index', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      const range = {
        basePatchNum: -3 as BasePatchSetNum,
        patchNum: 5 as RevisionPatchSetNum,
      };
      await element.getChangeFiles(123 as NumericChangeId, range);
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/5/files'
      );
      assert.isOk(fetchStub.lastCall.args[0].params);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.base);
      assert.equal(fetchStub.lastCall.args[0].params!.parent, 3);
    });
  });

  suite('getDiff', () => {
    test('patchOnly', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      await element.getDiff(
        123 as NumericChangeId,
        PARENT,
        2 as PatchSetNum,
        'foo/bar.baz'
      );
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/2/files/foo%2Fbar.baz/diff'
      );
      assert.isOk(fetchStub.lastCall.args[0].params);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.parent);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.base);
    });

    test('simple range', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      await element.getDiff(
        123 as NumericChangeId,
        4 as PatchSetNum,
        5 as PatchSetNum,
        'foo/bar.baz'
      );
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/5/files/foo%2Fbar.baz/diff'
      );
      assert.isOk(fetchStub.lastCall.args[0].params);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.parent);
      assert.equal(fetchStub.lastCall.args[0].params!.base, 4);
    });

    test('parent index', async () => {
      element.addRepoNameToCache(123 as NumericChangeId, TEST_PROJECT_NAME);
      const fetchStub = sinon
        .stub(element._restApiHelper, 'fetchJSON')
        .resolves();
      await element.getDiff(
        123 as NumericChangeId,
        -3 as PatchSetNum,
        5 as PatchSetNum,
        'foo/bar.baz'
      );
      assert.isTrue(fetchStub.calledOnce);
      assert.equal(
        fetchStub.lastCall.args[0].url,
        '/changes/test-project~123/revisions/5/files/foo%2Fbar.baz/diff'
      );
      assert.isOk(fetchStub.lastCall.args[0].params);
      assert.isNotOk(fetchStub.lastCall.args[0].params!.base);
      assert.equal(fetchStub.lastCall.args[0].params!.parent, 3);
    });
  });

  test('getDashboard', () => {
    const fetchCacheJSONStub = sinon.stub(
      element._restApiHelper,
      'fetchCacheJSON'
    );
    element.getDashboard(
      'gerrit/project' as RepoName,
      'default:main' as DashboardId
    );
    assert.isTrue(fetchCacheJSONStub.calledOnce);
    assert.equal(
      fetchCacheJSONStub.lastCall.args[0].url,
      '/projects/gerrit%2Fproject/dashboards/default%3Amain'
    );
  });

  test('getFileContent', async () => {
    element.addRepoNameToCache(1 as NumericChangeId, TEST_PROJECT_NAME);
    sinon.stub(element._restApiHelper, 'fetch').callsFake(() =>
      Promise.resolve(
        new Response(makePrefixedJSON('new content'), {
          status: 200,
          headers: {
            'X-FYI-Content-Type': 'text/java',
          },
        })
      )
    );

    const edit = await element.getFileContent(
      1 as NumericChangeId,
      'tst/path',
      'EDIT' as PatchSetNum
    );

    assert.deepEqual(edit, {
      content: 'new content',
      type: 'text/java',
      ok: true,
    });

    const normal = await element.getFileContent(
      1 as NumericChangeId,
      'tst/path',
      '3' as PatchSetNum
    );
    assert.deepEqual(normal, {
      content: 'new content',
      type: 'text/java',
      ok: true,
    });
  });

  test('getFileContent suppresses 404s', async () => {
    const res404 = new Response(undefined, {status: 404});
    const res500 = new Response(undefined, {status: 500});
    const spy = sinon.spy();
    addListenerForTest(document, 'server-error', spy);
    const authStub = sinon.stub(authService, 'fetch').resolves(res404);
    sinon.stub(element, '_changeBaseURL').resolves('');
    await element.getFileContent(
      1 as NumericChangeId,
      'tst/path',
      1 as PatchSetNum
    );
    await waitEventLoop();
    assert.isFalse(spy.called);
    authStub.reset();
    authStub.resolves(res500);
    await element.getFileContent(
      1 as NumericChangeId,
      'tst/path',
      1 as PatchSetNum
    );
    assert.isTrue(spy.called);
    assert.notEqual(spy.lastCall.args[0].detail.response.status, 404);
  });

  test('getChangeFilesOrEditFiles is edit-sensitive', async () => {
    const getChangeFilesStub = sinon
      .stub(element, 'getChangeFiles')
      .resolves({});
    const getChangeEditFilesStub = sinon
      .stub(element, 'getChangeEditFiles')
      .resolves({files: {}});

    await element.getChangeOrEditFiles(1 as NumericChangeId, {
      basePatchNum: PARENT,
      patchNum: EDIT,
    });
    assert.isTrue(getChangeEditFilesStub.calledOnce);
    assert.isFalse(getChangeFilesStub.called);
    await element.getChangeOrEditFiles(1 as NumericChangeId, {
      basePatchNum: PARENT,
      patchNum: 1 as RevisionPatchSetNum,
    });
    assert.isTrue(getChangeEditFilesStub.calledOnce);
    assert.isTrue(getChangeFilesStub.calledOnce);
  });

  test('ported comment errors do not trigger error dialog', () => {
    const change = createChange();
    const handler = sinon.stub();
    addListenerForTest(document, 'server-error', handler);
    sinon.stub(element._restApiHelper, 'fetchJSON').resolves({
      ok: false,
    } as unknown as ParsedJSON);

    element.getPortedComments(change._number, CURRENT);

    assert.isFalse(handler.called);
  });

  test('ported drafts are not requested user is not logged in', () => {
    const change = createChange();
    element.addRepoNameToCache(change._number, TEST_PROJECT_NAME);
    sinon.stub(element, 'getLoggedIn').resolves(false);
    const getChangeURLAndFetchStub = sinon.stub(
      element._restApiHelper,
      'fetchJSON'
    );

    element.getPortedDrafts(change._number, CURRENT);

    assert.isFalse(getChangeURLAndFetchStub.called);
  });

  test('saveChangeStarred', async () => {
    element.addRepoNameToCache(123 as NumericChangeId, 'test' as RepoName);
    element.addRepoNameToCache(456 as NumericChangeId, 'test' as RepoName);
    const fetchStub = sinon.stub(element._restApiHelper, 'fetch').resolves();

    await element.saveChangeStarred(123 as NumericChangeId, true);
    assert.isTrue(fetchStub.calledOnce);
    assert.deepEqual(fetchStub.lastCall.args[0], {
      fetchOptions: {method: HttpMethod.PUT},
      url: '/accounts/self/starred.changes/test~123',
      anonymizedUrl: '/accounts/self/starred.changes/*',
    });

    await element.saveChangeStarred(456 as NumericChangeId, false);
    assert.isTrue(fetchStub.calledTwice);
    assert.deepEqual(fetchStub.lastCall.args[0], {
      fetchOptions: {method: HttpMethod.DELETE},
      url: '/accounts/self/starred.changes/test~456',
      anonymizedUrl: '/accounts/self/starred.changes/*',
    });
  });
});
