aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/config/massage.spec.ts
blob: 0fb0d48fe137b117d7c14ee566879bf8a9d218cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import * as massage from './massage';
import type { RenovateConfig } from './types';

describe('config/massage', () => {
  describe('massageConfig', () => {
    it('returns empty', () => {
      const config: RenovateConfig = {};
      const res = massage.massageConfig(config);
      expect(res).toEqual({});
    });

    it('massages strings to array', () => {
      const config: RenovateConfig = {
        schedule: 'before 5am' as never,
      };
      const res = massage.massageConfig(config);
      expect(Array.isArray(res.schedule)).toBeTrue();
    });

    it('massages packageRules matchUpdateTypes', () => {
      const config: RenovateConfig = {
        packageRules: [
          {
            matchPackageNames: ['foo'],
            separateMajorMinor: false,
            minor: {
              semanticCommitType: 'feat',
            },
            patch: {
              semanticCommitType: 'fix',
            },
          },
        ],
      };
      const res = massage.massageConfig(config);
      expect(res).toEqual({
        packageRules: [
          {
            matchPackageNames: ['foo'],
            separateMajorMinor: false,
          },
          {
            matchPackageNames: ['foo'],
            matchUpdateTypes: ['minor'],
            semanticCommitType: 'feat',
          },
          {
            matchPackageNames: ['foo'],
            matchUpdateTypes: ['patch'],
            semanticCommitType: 'fix',
          },
        ],
      });
      expect(res.packageRules).toHaveLength(3);
    });

    it('filters packageRules with only match/exclude', () => {
      const config: RenovateConfig = {
        packageRules: [
          {
            matchBaseBranches: ['main'],
            major: {
              enabled: true,
            },
          },
        ],
      };
      const res = massage.massageConfig(config);
      expect(res.packageRules).toHaveLength(1);
    });

    it('does not massage lockFileMaintenance', () => {
      const config: RenovateConfig = {
        packageRules: [
          {
            matchManagers: ['helmv3'],
            matchBaseBranches: ['release/ft10/1.9.x'],
            lockFileMaintenance: { enabled: true },
            schedule: ['at any time'],
          },
        ],
      };
      const res = massage.massageConfig(config);
      expect(res).toEqual({
        packageRules: [
          {
            lockFileMaintenance: {
              enabled: true,
            },
            matchBaseBranches: ['release/ft10/1.9.x'],
            matchManagers: ['helmv3'],
            schedule: ['at any time'],
          },
        ],
      });
      expect(res.packageRules).toHaveLength(1);
    });
  });
});