Skip to content
Snippets Groups Projects
Select Git revision
  • 4cfe151dc1d77cea841a8382b7f287339a5899ab
  • main default protected
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • chore/punycode
  • 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
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.38.2
  • 41.38.1
  • 41.38.0
  • 41.37.12
  • 41.37.11
  • 41.37.10
  • 41.37.9
  • 41.37.8
  • 41.37.7
  • 41.37.6
  • 41.37.5
  • 41.37.4
  • 41.37.3
  • 41.37.2
  • 41.37.1
  • 41.37.0
  • 41.36.2
  • 41.36.1
  • 41.36.0
  • 41.35.2
41 results

pr-body.spec.ts

Blame
  • user avatar
    Gabriel-Ladzaretti authored and GitHub committed
    Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
    23e25088
    History
    pr-body.spec.ts 3.03 KiB
    import hasha from 'hasha';
    import { getPrBodyStruct, hashBody } from './pr-body';
    
    describe('modules/platform/pr-body', () => {
      describe('getPrBodyStruct', () => {
        it('returns hash for empty inputs', () => {
          expect(getPrBodyStruct(null)).toEqual({
            hash: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
          });
          expect(getPrBodyStruct(undefined)).toEqual({
            hash: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
          });
          expect(getPrBodyStruct('')).toEqual({
            hash: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
          });
          expect(
            getPrBodyStruct(
              'something \n<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiAiMS4yLjEiLCJ1cGRhdGVkSW5WZXIiOiAiMS4yLjMifQ==-->'
            )
          ).toEqual({
            hash: '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb',
            debugData: {
              createdInVer: '1.2.1',
              updatedInVer: '1.2.3',
            },
          });
        });
    
        it('checks if we reach warning', () => {
          expect(
            getPrBodyStruct(
              'something \n<!--renovate-debug:some-wrong-data-ABCDEFGHIJKLMNOP-->'
            )
          ).toEqual({
            hash: '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb',
          });
        });
    
        it('hashes ignoring debug info', () => {
          expect(hashBody('foo\n<!--renovate-debug:123-->\n')).toEqual(
            hashBody('foo')
          );
        });
    
        it('hashes ignoring reviewable section', () => {
          expect(hashBody('foo<!-- Reviewable:start -->bar')).toEqual(
            hashBody('foo')
          );
        });
    
        it('hashes an undefined body', () => {
          // nullish operator branch coverage
          const hash =
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
          expect(hashBody(undefined)).toBe(hash);
        });
    
        it('returns rebaseRequested=true flag', () => {
          const input = '- [x] <!-- rebase-check -->';
          const hash = hashBody(input);
          expect(getPrBodyStruct(input)).toEqual({
            hash,
            rebaseRequested: true,
          });
        });
    
        it('returns rebaseRequested=false flag', () => {
          const input = '- [ ] <!-- rebase-check -->';
          const hash = hashBody(input);
          expect(getPrBodyStruct(input)).toEqual({
            hash,
            rebaseRequested: false,
          });
        });
    
        it('returns rebaseRequested=undefined flag', () => {
          const input = '-  <!-- rebase-check -->';
          const hash = hashBody(input);
          expect(getPrBodyStruct(input)).toEqual({
            hash,
          });
        });
    
        it('returns raw config hash', () => {
          const config = '{}';
          const rawConfigHash = hasha(config, { algorithm: 'sha256' });
          const input = `<!--renovate-config-hash:${rawConfigHash}-->`;
          const hash = hashBody(input);
          expect(getPrBodyStruct(input)).toEqual({
            hash,
            rawConfigHash,
          });
        });
    
        it('strips reviewable section', () => {
          expect(getPrBodyStruct('foo<!-- Reviewable:start -->bar')).toEqual({
            hash: hashBody('foo'),
          });
        });
      });
    });