Skip to content
Snippets Groups Projects
Select Git revision
  • 9b2c4b5af2b9a4bd94724885c6fb062d7ed14bfe
  • main default protected
  • next
  • renovate/main-ghcr.io-renovatebot-base-image-10.x
  • renovate/main-ghcr.io-containerbase-devcontainer-13.x
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
  • 41.27.1
  • 41.27.0
  • 41.26.2
  • 41.26.1
  • 41.26.0
41 results

gitea.spec.ts

Blame
  • gitea.spec.ts 2.56 KiB
    import * as httpMock from '../../../test/http-mock';
    import { GiteaHttp, setBaseUrl } from './gitea';
    
    describe('util/http/gitea', () => {
      const baseUrl = 'https://gitea.renovatebot.com/api/v1';
    
      let giteaHttp: GiteaHttp;
    
      beforeEach(() => {
        giteaHttp = new GiteaHttp();
    
        jest.resetAllMocks();
    
        setBaseUrl(baseUrl);
      });
    
      it('supports responses without pagination when enabled', async () => {
        httpMock
          .scope(baseUrl)
          .get('/pagination-example-1')
          .reply(200, { hello: 'world' });
    
        const res = await giteaHttp.getJson('pagination-example-1', {
          paginate: true,
        });
        expect(res.body).toEqual({ hello: 'world' });
        expect(httpMock.getTrace()).toMatchSnapshot();
      });
    
      it('supports root-level pagination', async () => {
        httpMock
          .scope(baseUrl)
          .get('/pagination-example-1')
          .reply(200, ['abc', 'def', 'ghi'], { 'x-total-count': '5' })
          .get('/pagination-example-1?page=2')
          .reply(200, ['jkl'])
          .get('/pagination-example-1?page=3')
          .reply(200, ['mno', 'pqr']);
    
        const res = await giteaHttp.getJson(`${baseUrl}/pagination-example-1`, {
          paginate: true,
        });
    
        expect(res.body).toHaveLength(6);
        expect(res.body).toEqual(['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr']);
        expect(httpMock.getTrace()).toMatchSnapshot();
      });
    
      it('supports pagination on data property', async () => {
        httpMock
          .scope(baseUrl)
          .get('/pagination-example-2')
          .reply(200, { data: ['abc', 'def', 'ghi'] }, { 'x-total-count': '5' })
          .get('/pagination-example-2?page=2')
          .reply(200, { data: ['jkl'] })
          .get('/pagination-example-2?page=3')
          .reply(200, { data: ['mno', 'pqr'] });
    
        const res = await giteaHttp.getJson<{ data: string[] }>(
          'pagination-example-2',
          {
            paginate: true,
          }
        );
        expect(res.body.data).toHaveLength(6);
        expect(res.body.data).toEqual(['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr']);
        expect(httpMock.getTrace()).toMatchSnapshot();
      });
      it('handles pagination with empty response', async () => {
        httpMock
          .scope(baseUrl)
          .get('/pagination-example-3')
          .reply(200, { data: ['abc', 'def', 'ghi'] }, { 'x-total-count': '5' })
          .get('/pagination-example-3?page=2')
          .reply(200, { data: [] });
    
        const res = await giteaHttp.getJson<{ data: string[] }>(
          'pagination-example-3',
          {
            paginate: true,
          }
        );
        expect(res.body.data).toHaveLength(3);
        expect(res.body.data).toEqual(['abc', 'def', 'ghi']);
        expect(httpMock.getTrace()).toMatchSnapshot();
      });
    });