forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversionUpdaterTest.js
95 lines (79 loc) · 4.3 KB
/
versionUpdaterTest.js
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
const versionUpdater = require('../../.github/libs/versionUpdater');
const VERSION = '2.3.9-80';
const VERSION_NUMBER = [2, 3, 9, 80];
describe('versionUpdater', () => {
describe('getVersionNumberFromString', () => {
it('should return a list with version levels numbers', () => {
expect(versionUpdater.getVersionNumberFromString(VERSION)).toStrictEqual(VERSION_NUMBER);
});
it('should return build as zero if not present in string', () => {
const versionWithZeroBuild = [VERSION_NUMBER[0], VERSION_NUMBER[1], VERSION_NUMBER[2], 0];
expect(versionUpdater.getVersionNumberFromString(VERSION.split('-')[0])).toStrictEqual(versionWithZeroBuild);
});
});
describe('getVersionStringFromNumber', () => {
it(`should return ${VERSION}`, () => {
expect(versionUpdater.getVersionStringFromNumber(...VERSION_NUMBER)).toBe(VERSION);
});
});
describe('incrementMinor', () => {
it('should only increment minor', () => {
expect(versionUpdater.incrementMinor(2, 3)).toStrictEqual('2.4.0-0');
});
it('should increment major', () => {
expect(versionUpdater.incrementMinor(2, versionUpdater.MAX_INCREMENTS)).toStrictEqual('3.0.0-0');
});
});
describe('incrementPatch', () => {
it('should only increment patch', () => {
expect(versionUpdater.incrementPatch(2, 3, 5)).toStrictEqual('2.3.6-0');
});
it('should increment minor', () => {
expect(versionUpdater.incrementPatch(2, 3, versionUpdater.MAX_INCREMENTS)).toStrictEqual('2.4.0-0');
});
it('should increment major', () => {
expect(versionUpdater.incrementPatch(2, versionUpdater.MAX_INCREMENTS, versionUpdater.MAX_INCREMENTS)).toStrictEqual('3.0.0-0');
});
});
describe('incrementVersion', () => {
it('should increment MAJOR', () => {
expect(versionUpdater.incrementVersion(VERSION, versionUpdater.SEMANTIC_VERSION_LEVELS.MAJOR)).toStrictEqual('3.0.0-0');
});
it('should increment MAJOR even above max level', () => {
expect(versionUpdater.incrementVersion(`${versionUpdater.MAX_INCREMENTS}.5.1-80`, versionUpdater.SEMANTIC_VERSION_LEVELS.MAJOR)).toStrictEqual(
`${versionUpdater.MAX_INCREMENTS + 1}.0.0-0`,
);
});
it('should increment BUILD number', () => {
expect(versionUpdater.incrementVersion(VERSION, versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD)).toStrictEqual('2.3.9-81');
});
it('should add BUILD number if there is no BUILD number', () => {
expect(versionUpdater.incrementVersion(VERSION.split('-')[0], versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD)).toStrictEqual('2.3.9-1');
});
it('should increment patch if MINOR is above max level', () => {
expect(versionUpdater.incrementVersion(`2.3.9-${versionUpdater.MAX_INCREMENTS}`, versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD)).toStrictEqual('2.3.10-0');
});
it('should increment the MAJOR', () => {
expect(
versionUpdater.incrementVersion(
`2.${versionUpdater.MAX_INCREMENTS}.${versionUpdater.MAX_INCREMENTS}-${versionUpdater.MAX_INCREMENTS}`,
versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD,
),
).toStrictEqual('3.0.0-0');
});
});
describe('getPreviousVersion', () => {
test.each([
['1.0.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.MAJOR, '1.0.0-0'],
['1.0.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.MINOR, '1.0.0-0'],
['1.0.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.PATCH, '1.0.0-0'],
['1.0.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD, '1.0.0-0'],
['2.0.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.MAJOR, '1.0.0-0'],
['1.1.0-0', versionUpdater.SEMANTIC_VERSION_LEVELS.MINOR, '1.0.0-0'],
['1.0.1-0', versionUpdater.SEMANTIC_VERSION_LEVELS.PATCH, '1.0.0-0'],
['1.0.0-1', versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD, '1.0.0-0'],
])('%s – get previous %s version', (input, level, expectedOutput) => {
expect(versionUpdater.getPreviousVersion(input, level)).toBe(expectedOutput);
});
});
});