Skip to content
Snippets Groups Projects
Select Git revision
  • 2dd240986d5e6018cfcd919d48dba67c4f84fa45
  • main default protected
  • renovate/immich
  • renovate/redis-21.x
  • renovate/cloudflare-5.x
  • renovate/mikefarah-yq-4.x
  • renovate/prometheus-json-exporter-0.x
  • renovate/prometheus-smartctl-exporter-0.x
  • renovate/hcloud-exporter-4.x
  • renovate/gitlab-runner-0.x
  • renovate/gcr.io-projectsigstore-cosign-2.x
  • renovate/docker.io-bitnami-kubectl-1.x
  • renovate/siderolabs-kubelet-1.33.x
  • renovate/mariadb-21.x
  • renovate/kubernetes-go
  • renovate/external-dns-1.x
  • renovate/longhorn-1.8.x
  • renovate/docker.io-library-alpine-3.x
  • renovate/kubernetes-kubernetes-1.x
  • renovate/kubernetes-sigs-cluster-api-1.x
  • renovate/tektoncd-cli-0.x
  • v25.07
  • v25.06
  • v25.05
  • v25.04
  • v25.03
  • v25.02
  • v25.01
  • v24.12
  • v24.11
  • v24.10
  • v24.09
  • v24.08
  • v24.07
  • v24.06
  • v24.05
  • v24.04
  • v24.03
  • v24.02
  • v24.01
  • v23.12
41 results

validate.sh

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