Skip to content
Snippets Groups Projects
Select Git revision
  • f0cc3bfad1bdecf383a3485377e3e89f321a8b4b
  • main default protected
  • renovate/main-vitest-monorepo
  • next
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • renovate/main-redis-5.x
  • renovate/main-xmldoc-2.x
  • 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
  • fix/32307-global-extends-repositories
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
  • 41.7.1
  • 41.7.0
  • 41.6.4
  • 41.6.3
  • 41.6.2
  • 41.6.1
  • 41.6.0
  • 41.5.0
  • 41.4.0
  • 41.3.0
  • 41.2.0
  • 41.1.4
  • 41.1.3
41 results

sanitize.ts

Blame
  • limits.spec.ts 2.28 KiB
    import moment from 'moment';
    import { RenovateConfig, getConfig, platform } from '../../../../test/util';
    import { PrState } from '../../../types';
    import { BranchConfig } from '../../common';
    import * as limits from './limits';
    
    let config: RenovateConfig;
    beforeEach(() => {
      jest.resetAllMocks();
      config = getConfig();
    });
    
    describe('workers/repository/process/limits', () => {
      describe('getPrHourlyRemaining()', () => {
        it('calculates hourly limit remaining', async () => {
          config.prHourlyLimit = 2;
          platform.getPrList.mockResolvedValueOnce([
            {
              createdAt: moment().toISOString(),
              sourceBranch: null,
              title: null,
              state: null,
            },
          ]);
          const res = await limits.getPrHourlyRemaining(config);
          expect(res).toEqual(1);
        });
        it('returns 99 if errored', async () => {
          config.prHourlyLimit = 2;
          platform.getPrList.mockResolvedValueOnce([null]);
          const res = await limits.getPrHourlyRemaining(config);
          expect(res).toEqual(99);
        });
      });
      describe('getConcurrentPrsRemaining()', () => {
        it('calculates concurrent limit remaining', async () => {
          config.prConcurrentLimit = 20;
          platform.getBranchPr.mockImplementation((branchName) =>
            branchName
              ? Promise.resolve({
                  sourceBranch: branchName,
                  state: PrState.Open,
                } as never)
              : Promise.reject('some error')
          );
          const branches: BranchConfig[] = [
            { branchName: 'test' },
            { branchName: null },
          ] as never;
          const res = await limits.getConcurrentPrsRemaining(config, branches);
          expect(res).toEqual(19);
        });
        it('returns 99 if no concurrent limit', async () => {
          const res = await limits.getConcurrentPrsRemaining(config, []);
          expect(res).toEqual(99);
        });
      });
    
      describe('getPrsRemaining()', () => {
        it('returns hourly limit', async () => {
          config.prHourlyLimit = 5;
          platform.getPrList.mockResolvedValueOnce([]);
          const res = await limits.getPrsRemaining(config, []);
          expect(res).toEqual(5);
        });
        it('returns concurrent limit', async () => {
          config.prConcurrentLimit = 5;
          const res = await limits.getPrsRemaining(config, []);
          expect(res).toEqual(5);
        });
      });
    });