Skip to content

Commit b0694d9

Browse files
[FSSDK-11238] event tag utils test addition
1 parent c563da0 commit b0694d9

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

lib/utils/attributes_validator/index.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { OptimizelyError } from '../../error/optimizly_error';
2121

2222
describe('validate', () => {
2323
it('should validate the given attributes if attributes is an object', () => {
24-
// assert.isTrue(attributesValidator.validate({ testAttribute: 'testValue' }));
2524
expect(attributesValidator.validate({ testAttribute: 'testValue' })).toBe(true);
2625
});
2726

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
17+
import { describe, it, expect, beforeEach } from 'vitest';
18+
import { sprintf } from '../../utils/fns';
19+
20+
import * as eventTagUtils from './';
21+
import {
22+
FAILED_TO_PARSE_REVENUE,
23+
PARSED_REVENUE_VALUE,
24+
PARSED_NUMERIC_VALUE,
25+
FAILED_TO_PARSE_VALUE,
26+
} from 'log_message';
27+
28+
const buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
29+
import { getMockLogger } from '../../tests/mock/mock_logger';
30+
import { LoggerFacade } from '../../logging/logger';
31+
32+
describe('getRevenueValue', () => {
33+
let logger: LoggerFacade;
34+
35+
beforeEach(() => {
36+
logger = getMockLogger();
37+
});
38+
39+
it('should return the parseed integer for a valid revenue value', () => {
40+
let parsedRevenueValue = eventTagUtils.getRevenueValue({ revenue: '1337' }, logger);
41+
42+
expect(parsedRevenueValue).toBe(1337);
43+
expect(logger.info).toHaveBeenCalledWith(PARSED_REVENUE_VALUE, 1337);
44+
45+
parsedRevenueValue = eventTagUtils.getRevenueValue({ revenue: '13.37' }, logger);
46+
47+
expect(parsedRevenueValue).toBe(13);
48+
});
49+
50+
it('should return null and log a message for invalid value', () => {
51+
const parsedRevenueValue = eventTagUtils.getRevenueValue({ revenue: 'invalid' }, logger);
52+
53+
expect(parsedRevenueValue).toBe(null);
54+
expect(logger.info).toHaveBeenCalledWith(FAILED_TO_PARSE_REVENUE, 'invalid');
55+
});
56+
57+
it('should return null if the revenue value is not present in the event tags', () => {
58+
const parsedRevenueValue = eventTagUtils.getRevenueValue({ not_revenue: '1337' }, logger);
59+
60+
expect(parsedRevenueValue).toBe(null);
61+
});
62+
});
63+
64+
describe('getEventValue', () => {
65+
let logger: LoggerFacade;
66+
67+
beforeEach(() => {
68+
logger = getMockLogger();
69+
});
70+
71+
it('should return the parsed integer for a valid numeric value', () => {
72+
const parsedNumericValue = eventTagUtils.getEventValue({ value: '1337' }, logger);
73+
74+
expect(parsedNumericValue).toBe(1337);
75+
expect(logger.info).toHaveBeenCalledWith(PARSED_NUMERIC_VALUE, 1337);
76+
});
77+
78+
it('should return null and log a message for invalid value', () => {
79+
const parsedNumericValue = eventTagUtils.getEventValue({ value: 'invalid' }, logger);
80+
81+
expect(parsedNumericValue).toBe(null);
82+
expect(logger.info).toHaveBeenCalledWith(FAILED_TO_PARSE_VALUE, 'invalid');
83+
});
84+
85+
it('should return null if the value is not present in the event tags', () => {
86+
const parsedNumericValue = eventTagUtils.getEventValue({ not_value: '13.37' }, logger);
87+
88+
expect(parsedNumericValue).toBe(null);
89+
});
90+
})

0 commit comments

Comments
 (0)