Skip to content
Snippets Groups Projects
Select Git revision
  • 01d6899fd914b38aad34ee62ac9c620a06260306
  • master default protected
  • dependabot/npm_and_yarn/webui/npm_and_yarn-7d065cd83c
  • dependabot/go_modules/go_modules-985326579b
  • gh-pages
  • trunk
  • graphql-subscription
  • feat/1467/git-repo-path
  • board
  • I738207f8cb254b66f3ef18aa525fce39c71060e2
  • Ia1ad61e54e305bb073efc6853738d3eed81d576c
  • feat/lipgloss-formatting
  • bootstrap-rework-2
  • boostrap-rework
  • github-config-resilience
  • feat-849-terminal-output-in-core
  • gitea-bridge
  • feat-licences-checks
  • complete-comment
  • graphql-generics
  • fix/810-finish-reading-loop
  • v0.10.1
  • v0.10.0
  • v0.9.0
  • v0.8.1
  • v0.8.0
  • v0.7.2
  • 0.7.1
  • 0.7.0
  • 0.6.0
  • 0.5.0
  • 0.4.0
  • 0.3.0
  • 0.2.0
  • 0.1.0
35 results

main.go

Blame
  • validate.spec.ts 3.55 KiB
    import { PR_STATE_OPEN } from '../../../constants/pull-requests';
    import * as validate from './validate';
    import { platform } from '../../../../test/util';
    import { BranchStatus } from '../../../types';
    
    beforeEach(() => {
      jest.resetAllMocks();
    });
    
    describe('workers/repository/validate', () => {
      describe('validatePrs()', () => {
        it('returns if disabled', async () => {
          await validate.validatePrs({ suppressNotifications: ['prValidation'] });
        });
        it('catches error', async () => {
          platform.getPrList.mockResolvedValueOnce([
            {
              state: PR_STATE_OPEN,
              branchName: 'some/branch',
              title: 'Update Renovate',
            },
          ]);
          await validate.validatePrs({});
          expect(platform.setBranchStatus).toHaveBeenCalledTimes(0);
          expect(platform.ensureComment).toHaveBeenCalledTimes(0);
          expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
        });
        it('returns if no matching files', async () => {
          platform.getPrList.mockResolvedValueOnce([
            {
              state: PR_STATE_OPEN,
              branchName: 'some/branch',
              title: 'Update Renovate',
            },
          ]);
          platform.getPrFiles.mockResolvedValueOnce(['readme.md']);
          await validate.validatePrs({});
          expect(platform.setBranchStatus).toHaveBeenCalledTimes(0);
          expect(platform.ensureComment).toHaveBeenCalledTimes(0);
          expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
        });
        it('validates failures if cannot parse', async () => {
          platform.getPrList.mockResolvedValueOnce([
            {
              state: PR_STATE_OPEN,
              branchName: 'some/branch',
              title: 'Update Renovate',
            },
          ]);
          platform.getPrFiles.mockResolvedValueOnce(['renovate.json']);
          platform.getFile.mockResolvedValue('not JSON');
          await validate.validatePrs({});
          expect(platform.setBranchStatus).toHaveBeenCalledTimes(1);
          expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual(
            BranchStatus.red
          );
          expect(platform.ensureComment).toHaveBeenCalledTimes(1);
          expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
        });
        it('validates failures if config validation fails', async () => {
          platform.getPrList.mockResolvedValueOnce([
            {
              state: PR_STATE_OPEN,
              branchName: 'some/branch',
              title: 'Update Renovate',
            },
          ]);
          platform.getPrFiles.mockResolvedValueOnce(['renovate.json']);
          platform.getFile.mockResolvedValue('{"foo":1}');
          await validate.validatePrs({});
          expect(platform.setBranchStatus).toHaveBeenCalledTimes(1);
          expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual(
            BranchStatus.red
          );
          expect(platform.ensureComment).toHaveBeenCalledTimes(1);
          expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
        });
        it('validates successfully', async () => {
          platform.getPrList.mockResolvedValueOnce([
            {
              state: PR_STATE_OPEN,
              branchName: 'some/branch',
              title: 'Update Renovate',
            },
          ]);
          platform.getPrFiles.mockResolvedValueOnce(['renovate.json']);
          platform.getFile.mockResolvedValue('{}');
          await validate.validatePrs({});
          expect(platform.setBranchStatus).toHaveBeenCalledTimes(1);
          expect(platform.setBranchStatus.mock.calls[0][0].state).toEqual(
            BranchStatus.green
          );
          expect(platform.ensureComment).toHaveBeenCalledTimes(0);
          expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(1);
        });
      });
    });