Skip to content
Snippets Groups Projects
Select Git revision
  • 91da82aaa8d1ed8e93f3f5215b353343e4132c91
  • main default protected
  • lihiz_preflight
  • release/prepare-v0.10.7
  • dependabot/github_actions/golangci/golangci-lint-action-7
  • release/prepare-v0.9.1
  • gh-pages
  • aquadev
  • v0.11.1
  • v0.11.0
  • v0.10.7
  • v0.10.6
  • v0.10.5
  • v0.10.4
  • v0.10.3
  • v0.10.2
  • v0.10.1
  • v0.10.0
  • v0.9.4
  • v0.9.3
  • v0.9.2
  • v0.9.1
  • v0.9.0
  • v0.8.0
  • v0.7.3
  • v0.7.2
  • v0.7.1
  • v0.7.0
28 results

controls_test.go

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();
      });
    });