Skip to content

Commit 5e272cf

Browse files
[FSSDK-11238] semantic_version test addition
1 parent 848625e commit 5e272cf

File tree

2 files changed

+112
-5
lines changed

2 files changed

+112
-5
lines changed

lib/utils/event_tag_utils/index.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
import { describe, it, expect, beforeEach } from 'vitest';
18-
import { sprintf } from '../../utils/fns';
19-
2017
import * as eventTagUtils from './';
2118
import {
2219
FAILED_TO_PARSE_REVENUE,
2320
PARSED_REVENUE_VALUE,
2421
PARSED_NUMERIC_VALUE,
2522
FAILED_TO_PARSE_VALUE,
2623
} from 'log_message';
27-
28-
const buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
2924
import { getMockLogger } from '../../tests/mock/mock_logger';
3025
import { LoggerFacade } from '../../logging/logger';
3126

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright 2025, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { describe, it, expect } from 'vitest';
17+
import * as semanticVersion from '.';
18+
19+
describe('compareVersion', () => {
20+
it('should return 0 if user version and target version are equal', () => {
21+
const versions = [
22+
['2.0.1', '2.0.1'],
23+
['2.9.9-beta', '2.9.9-beta'],
24+
['2.1', '2.1.0'],
25+
['2', '2.12'],
26+
['2.9', '2.9.1'],
27+
['2.9+beta', '2.9+beta'],
28+
['2.9.9+beta', '2.9.9+beta'],
29+
['2.9.9+beta-alpha', '2.9.9+beta-alpha'],
30+
['2.2.3', '2.2.3+beta'],
31+
];
32+
33+
versions.forEach(([targetVersion, userVersion]) => {
34+
const result = semanticVersion.compareVersion(targetVersion, userVersion);
35+
36+
expect(result).toBe(0);
37+
})
38+
});
39+
40+
it('should return 1 when user version is greater than target version', () => {
41+
const versions = [
42+
['2.0.0', '2.0.1'],
43+
['2.0', '3.0.1'],
44+
['2.0.0', '2.1'],
45+
['2.1.2-beta', '2.1.2-release'],
46+
['2.1.3-beta1', '2.1.3-beta2'],
47+
['2.9.9-beta', '2.9.9'],
48+
['2.9.9+beta', '2.9.9'],
49+
['2.0.0', '2.1'],
50+
['3.7.0-prerelease+build', '3.7.0-prerelease+rc'],
51+
['2.2.3-beta-beta1', '2.2.3-beta-beta2'],
52+
['2.2.3-beta+beta1', '2.2.3-beta+beta2'],
53+
['2.2.3+beta2-beta1', '2.2.3+beta3-beta2'],
54+
['2.2.3+beta', '2.2.3'],
55+
];
56+
57+
versions.forEach(([targetVersion, userVersion]) => {
58+
const result = semanticVersion.compareVersion(targetVersion, userVersion);
59+
60+
expect(result).toBe(1);
61+
})
62+
});
63+
64+
it('should return -1 when user version is less than target version', () => {
65+
const versions = [
66+
['2.0.1', '2.0.0'],
67+
['3.0', '2.0.1'],
68+
['2.3', '2.0.1'],
69+
['2.3.5', '2.3.1'],
70+
['2.9.8', '2.9'],
71+
['3.1', '3'],
72+
['2.1.2-release', '2.1.2-beta'],
73+
['2.9.9+beta', '2.9.9-beta'],
74+
['3.7.0+build3.7.0-prerelease+build', '3.7.0-prerelease'],
75+
['2.1.3-beta-beta2', '2.1.3-beta'],
76+
['2.1.3-beta1+beta3', '2.1.3-beta1+beta2'],
77+
['2.1.3', '2.1.3-beta'],
78+
];
79+
80+
versions.forEach(([targetVersion, userVersion]) => {
81+
const result = semanticVersion.compareVersion(targetVersion, userVersion);
82+
83+
expect(result).toBe(-1);
84+
})
85+
});
86+
87+
it('should return null when user version is invalid', () => {
88+
const versions = [
89+
'-',
90+
'.',
91+
'..',
92+
'+',
93+
'+test',
94+
' ',
95+
'2 .3. 0',
96+
'2.',
97+
'.2.2',
98+
'3.7.2.2',
99+
'3.x',
100+
',',
101+
'+build-prerelease',
102+
'2..2',
103+
];
104+
const targetVersion = '2.1.0';
105+
106+
versions.forEach((userVersion) => {
107+
const result = semanticVersion.compareVersion(targetVersion, userVersion);
108+
109+
expect(result).toBe(null);
110+
})
111+
});
112+
});

0 commit comments

Comments
 (0)