Skip to content
Snippets Groups Projects
Select Git revision
22 results Searching

core_test.go

Blame
  • master-issue.spec.ts 15.10 KiB
    import fs from 'fs';
    import { mock } from 'jest-mock-extended';
    import { RenovateConfig, getConfig, platform } from '../../../test/util';
    import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms';
    import { PR_STATE_NOT_OPEN } from '../../constants/pull-requests';
    import { Platform, Pr } from '../../platform';
    import { BranchConfig, BranchUpgradeConfig } from '../common';
    import * as dependencyDashboard from './master-issue';
    
    type PrUpgrade = BranchUpgradeConfig;
    
    let config: RenovateConfig;
    beforeEach(() => {
      jest.resetAllMocks();
      config = getConfig();
      config.platform = PLATFORM_TYPE_GITHUB;
      config.errors = [];
      config.warnings = [];
    });
    
    async function dryRun(
      branches: BranchConfig[],
      // eslint-disable-next-line no-shadow
      platform: jest.Mocked<Platform>,
      ensureIssueClosingCalls = 0,
      ensureIssueCalls = 0,
      getBranchPrCalls = 0,
      findPrCalls = 0
    ) {
      jest.resetAllMocks();
      config.dryRun = true;
      await dependencyDashboard.ensureMasterIssue(config, branches);
      expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(
        ensureIssueClosingCalls
      );
      expect(platform.ensureIssue).toHaveBeenCalledTimes(ensureIssueCalls);
      expect(platform.getBranchPr).toHaveBeenCalledTimes(getBranchPrCalls);
      expect(platform.findPr).toHaveBeenCalledTimes(findPrCalls);
    }
    
    describe('workers/repository/master-issue', () => {
      describe('ensureMasterIssue()', () => {
        it('do nothing if masterissue is disable', async () => {
          const branches: BranchConfig[] = [];
          await dependencyDashboard.ensureMasterIssue(config, branches);
          expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
          expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
          expect(platform.getBranchPr).toHaveBeenCalledTimes(0);
          expect(platform.findPr).toHaveBeenCalledTimes(0);
    
          // same with dry run
          await dryRun(branches, platform);
        });
    
        it('do nothing if it has no masterissueapproval branches', async () => {
          const branches = [
            {
              ...mock<BranchConfig>(),
              prTitle: 'pr1',
            },
            {
              ...mock<BranchConfig>(),
              prTitle: 'pr2',
              dependencyDashboardApproval: false,
            },
          ];
          await dependencyDashboard.ensureMasterIssue(config, branches);
          expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0);
          expect(platform.ensureIssue).toHaveBeenCalledTimes(0);
          expect(platform.getBranchPr).toHaveBeenCalledTimes(0);