Skip to content
Snippets Groups Projects
Select Git revision
  • 364163e7a0d4a86a757768921b99033f8f108f13
  • main default protected
  • next
  • renovate/main-ghcr.io-renovatebot-base-image-10.x
  • renovate/main-ghcr.io-containerbase-devcontainer-13.x
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • 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
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
  • 41.27.1
  • 41.27.0
  • 41.26.2
  • 41.26.1
  • 41.26.0
41 results

extract-update.spec.ts

Blame
  • index.spec.ts 3.10 KiB
    import * as httpMock from '../../../test/http-mock';
    import type { PlatformId } from '../../constants';
    import { PLATFORM_NOT_FOUND } from '../../constants/error-messages';
    import { loadModules } from '../../util/modules';
    import type { Platform } from './types';
    import * as platform from '.';
    
    jest.unmock('.');
    
    describe('modules/platform/index', () => {
      beforeEach(() => {
        jest.resetModules();
      });
    
      it('validates', () => {
        function validate(module: Platform | undefined, name: string): boolean {
          // TODO: test required api (#9650)
          if (!module?.initPlatform) {
            throw Error(`Missing api on ${name}`);
          }
          return true;
        }
        const platforms = platform.getPlatforms();
    
        const loadedMgr = loadModules(
          __dirname,
          undefined,
          (m) => !['utils', 'git'].includes(m)
        );
        expect(Array.from(platforms.keys())).toEqual(Object.keys(loadedMgr));
    
        for (const name of platforms.keys()) {
          const value = platforms.get(name);
          expect(validate(value, name)).toBeTrue();
        }
      });
    
      it('throws if no platform', () => {
        expect(() => platform.platform.initPlatform({})).toThrow(
          PLATFORM_NOT_FOUND
        );
      });
    
      it('throws if wrong platform', async () => {
        const config = {
          platform: 'wrong' as PlatformId,
          username: 'abc',
          password: '123',
        };
        await expect(platform.initPlatform(config)).rejects.toThrow();
      });
    
      it('initializes', async () => {
        httpMock
          .scope('https://api.bitbucket.org')
          .get('/2.0/user')
          .basicAuth({ user: 'abc', pass: '123' })
          .reply(200, { uuid: 123 });
        const config = {
          platform: 'bitbucket' as PlatformId,
          gitAuthor: 'user@domain.com',
          username: 'abc',
          password: '123',
        };
        expect(await platform.initPlatform(config)).toEqual({
          endpoint: 'https://api.bitbucket.org/',
          gitAuthor: 'user@domain.com',
          hostRules: [
            {
              hostType: 'bitbucket',
              matchHost: 'api.bitbucket.org',
              password: '123',
              username: 'abc',
            },
          ],
          platform: 'bitbucket',
        });
      });
    
      it('merges config hostRules with platform hostRules', async () => {
        httpMock.scope('https://ghe.renovatebot.com').head('/').reply(200);
    
        const config = {
          platform: 'github' as PlatformId,
          endpoint: 'https://ghe.renovatebot.com',
          gitAuthor: 'user@domain.com',
          username: 'abc',
          token: '123',
          hostRules: [
            {
              hostType: 'github',
              matchHost: 'github.com',
              token: '456',
              username: 'def',
            },
          ],
        };
    
        expect(await platform.initPlatform(config)).toEqual({
          endpoint: 'https://ghe.renovatebot.com/',
          gitAuthor: 'user@domain.com',
          hostRules: [
            {
              hostType: 'github',
              matchHost: 'github.com',
              token: '456',
              username: 'def',
            },
            {
              hostType: 'github',
              matchHost: 'ghe.renovatebot.com',
              token: '123',
              username: 'abc',
            },
          ],
          platform: 'github',
          renovateUsername: 'abc',
        });
      });
    });