mirror of https://github.com/renovatebot/renovate
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import type { Indent } from 'detect-indent';
|
|
import { Fixtures } from '../../../../test/fixtures';
|
|
import { mockedFunction, partial } from '../../../../test/util';
|
|
import { getConfig } from '../../../config/defaults';
|
|
import { checkConfigMigrationBranch } from './branch';
|
|
import { MigratedDataFactory } from './branch/migrated-data';
|
|
import { ensureConfigMigrationPr } from './pr';
|
|
import { configMigration } from './index';
|
|
|
|
jest.mock('./pr');
|
|
jest.mock('./branch');
|
|
jest.mock('./branch/migrated-data');
|
|
|
|
const content = Fixtures.getJson('./migrated-data.json', './branch');
|
|
const filename = 'renovate.json';
|
|
const branchName = 'renovate/config-migration';
|
|
const config = {
|
|
...getConfig(),
|
|
configMigration: true,
|
|
};
|
|
|
|
describe('workers/repository/config-migration/index', () => {
|
|
beforeEach(() => {
|
|
mockedFunction(MigratedDataFactory.getAsync).mockResolvedValue({
|
|
filename,
|
|
content,
|
|
indent: partial<Indent>(),
|
|
});
|
|
});
|
|
|
|
it('does nothing when in silent mode', async () => {
|
|
await configMigration({ ...config, mode: 'silent' }, []);
|
|
expect(MigratedDataFactory.getAsync).toHaveBeenCalledTimes(0);
|
|
expect(checkConfigMigrationBranch).toHaveBeenCalledTimes(0);
|
|
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
it('does nothing when config migration is disabled', async () => {
|
|
await configMigration({ ...config, configMigration: false }, []);
|
|
expect(MigratedDataFactory.getAsync).toHaveBeenCalledTimes(0);
|
|
expect(checkConfigMigrationBranch).toHaveBeenCalledTimes(0);
|
|
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
it('ensures config migration PR when migrated', async () => {
|
|
const branchList: string[] = [];
|
|
mockedFunction(checkConfigMigrationBranch).mockResolvedValue(branchName);
|
|
await configMigration(config, branchList);
|
|
expect(branchList).toContainEqual(branchName);
|
|
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('skips pr creation when migration is not needed', async () => {
|
|
const branchList: string[] = [];
|
|
mockedFunction(checkConfigMigrationBranch).mockResolvedValue(null);
|
|
await configMigration(config, branchList);
|
|
expect(checkConfigMigrationBranch).toHaveBeenCalledTimes(1);
|
|
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
|
});
|
|
});
|