1+ const assert = require ( 'chai' ) . assert ;
2+
3+ const {
4+ processOperation,
5+ StrategiesType,
6+ OperationsType
7+ } = require ( '../src/lib/snapshot' ) ;
8+
9+ describe ( 'Processing strategy: NUMERIC' , ( ) => {
10+ const mock_values1 = [
11+ '1'
12+ ] ;
13+
14+ const mock_values2 = [
15+ '1' , '3'
16+ ] ;
17+
18+ const mock_values3 = [
19+ '1.5'
20+ ] ;
21+
22+ it ( 'should agree when input EXIST in values - String type' , ( ) => {
23+ const result = processOperation (
24+ StrategiesType . NUMERIC , OperationsType . EXIST , '3' , mock_values2 ) ;
25+ assert . isTrue ( result ) ;
26+ } ) ;
27+
28+ it ( 'should agree when input EXIST in values - Number type' , ( ) => {
29+ const result = processOperation (
30+ StrategiesType . NUMERIC , OperationsType . EXIST , 3 , mock_values2 ) ;
31+ assert . isTrue ( result ) ;
32+ } ) ;
33+
34+ it ( 'should NOT agree when input exist but test as DOES NOT EXIST ' , ( ) => {
35+ const result = processOperation (
36+ StrategiesType . NUMERIC , OperationsType . NOT_EXIST , '1' , mock_values2 ) ;
37+ assert . isFalse ( result ) ;
38+ } ) ;
39+
40+ it ( 'should agree when input DOES NOT EXIST in values' , ( ) => {
41+ const result = processOperation (
42+ StrategiesType . NUMERIC , OperationsType . NOT_EXIST , '2' , mock_values2 ) ;
43+ assert . isTrue ( result ) ;
44+ } ) ;
45+
46+ it ( 'should agree when input is EQUAL to value' , ( ) => {
47+ const result = processOperation (
48+ StrategiesType . NUMERIC , OperationsType . EQUAL , '1' , mock_values1 ) ;
49+ assert . isTrue ( result ) ;
50+ } ) ;
51+
52+ it ( 'should NOT agree when input is not equal but test as EQUAL' , ( ) => {
53+ const result = processOperation (
54+ StrategiesType . NUMERIC , OperationsType . EQUAL , '2' , mock_values1 ) ;
55+ assert . isFalse ( result ) ;
56+ } ) ;
57+
58+ it ( 'should agree when input is NOT EQUAL to value' , ( ) => {
59+ const result = processOperation (
60+ StrategiesType . NUMERIC , OperationsType . NOT_EQUAL , '2' , mock_values1 ) ;
61+ assert . isTrue ( result ) ;
62+ } ) ;
63+
64+ it ( 'should agree when input is GREATER than value' , ( ) => {
65+ let result = processOperation (
66+ StrategiesType . NUMERIC , OperationsType . GREATER , '2' , mock_values1 ) ;
67+ assert . isTrue ( result ) ;
68+
69+ // test decimal
70+ result = processOperation (
71+ StrategiesType . NUMERIC , OperationsType . GREATER , '1.01' , mock_values1 ) ;
72+ assert . isTrue ( result ) ;
73+
74+ result = processOperation (
75+ StrategiesType . NUMERIC , OperationsType . GREATER , '1.55' , mock_values3 ) ;
76+ assert . isTrue ( result ) ;
77+ } ) ;
78+
79+ it ( 'should NOT agree when input is lower but tested as GREATER than value' , ( ) => {
80+ let result = processOperation (
81+ StrategiesType . NUMERIC , OperationsType . GREATER , '0' , mock_values1 ) ;
82+ assert . isFalse ( result ) ;
83+
84+ // test decimal
85+ result = processOperation (
86+ StrategiesType . NUMERIC , OperationsType . GREATER , '0.99' , mock_values1 ) ;
87+ assert . isFalse ( result ) ;
88+
89+ result = processOperation (
90+ StrategiesType . NUMERIC , OperationsType . GREATER , '1.49' , mock_values3 ) ;
91+ assert . isFalse ( result ) ;
92+ } ) ;
93+
94+ it ( 'should agree when input is LOWER than value' , ( ) => {
95+ let result = processOperation (
96+ StrategiesType . NUMERIC , OperationsType . LOWER , '0' , mock_values1 ) ;
97+ assert . isTrue ( result ) ;
98+
99+ // test decimal
100+ result = processOperation (
101+ StrategiesType . NUMERIC , OperationsType . LOWER , '0.99' , mock_values1 ) ;
102+ assert . isTrue ( result ) ;
103+
104+ result = processOperation (
105+ StrategiesType . NUMERIC , OperationsType . LOWER , '1.49' , mock_values3 ) ;
106+ assert . isTrue ( result ) ;
107+ } ) ;
108+
109+ it ( 'should agree when input is BETWEEN values' , ( ) => {
110+ let result = processOperation (
111+ StrategiesType . NUMERIC , OperationsType . BETWEEN , '1' , mock_values2 ) ;
112+ assert . isTrue ( result ) ;
113+
114+ // test decimal
115+ result = processOperation (
116+ StrategiesType . NUMERIC , OperationsType . BETWEEN , '2.99' , mock_values2 ) ;
117+ assert . isTrue ( result ) ;
118+
119+ result = processOperation (
120+ StrategiesType . NUMERIC , OperationsType . BETWEEN , '1.001' , mock_values2 ) ;
121+ assert . isTrue ( result ) ;
122+ } ) ;
123+ } ) ;
0 commit comments