@@ -35,6 +35,9 @@ describe('RPCClient', function(){
35
35
client . handle ( 'Heartbeat' , ( ) => {
36
36
return { currentTime : new Date ( ) . toISOString ( ) } ;
37
37
} ) ;
38
+ client . handle ( 'TestTenth' , ( { params} ) => {
39
+ return { val : params . val / 10 } ;
40
+ } ) ;
38
41
if ( extra . withClient ) {
39
42
extra . withClient ( client ) ;
40
43
}
@@ -71,6 +74,37 @@ describe('RPCClient', function(){
71
74
] ) ;
72
75
}
73
76
77
+ function getNumberTestValidator ( ) {
78
+ return createValidator ( 'numbers1.0' , [
79
+ {
80
+ "$schema" : "http://json-schema.org/draft-07/schema" ,
81
+ "$id" : "urn:TestTenth.req" ,
82
+ "type" : "object" ,
83
+ "properties" : {
84
+ "val" : {
85
+ "type" : "number" ,
86
+ "multipleOf" : 0.1
87
+ }
88
+ } ,
89
+ "additionalProperties" : false ,
90
+ "required" : [ "val" ]
91
+ } ,
92
+ {
93
+ "$schema" : "http://json-schema.org/draft-07/schema" ,
94
+ "$id" : "urn:TestTenth.conf" ,
95
+ "type" : "object" ,
96
+ "properties" : {
97
+ "val" : {
98
+ "type" : "number" ,
99
+ "multipleOf" : 0.01
100
+ }
101
+ } ,
102
+ "additionalProperties" : false ,
103
+ "required" : [ "val" ]
104
+ }
105
+ ] ) ;
106
+ }
107
+
74
108
describe ( '#constructor' , function ( ) {
75
109
76
110
it ( 'should throw on missing identity' , async ( ) => {
@@ -1428,8 +1462,52 @@ describe('RPCClient', function(){
1428
1462
}
1429
1463
} ) ;
1430
1464
1465
+ it ( "should not reject messages due to floating point imprecision in strictMode" , async ( ) => {
1466
+
1467
+ const { endpoint, close, server } = await createServer ( {
1468
+ protocols : [ 'numbers1.0' ] ,
1469
+ } ) ;
1470
+
1471
+ const cli = new RPCClient ( {
1472
+ endpoint,
1473
+ identity : 'X' ,
1474
+ protocols : [ 'numbers1.0' ] ,
1475
+ strictModeValidators : [ getNumberTestValidator ( ) ] ,
1476
+ strictMode : true ,
1477
+ } ) ;
1478
+
1479
+ try {
1480
+ await cli . connect ( ) ;
1481
+
1482
+ const [ c1 , c2 , c3 , c4 , c5 ] = await Promise . allSettled ( [
1483
+ cli . call ( 'TestTenth' , { val : 1 } ) ,
1484
+ cli . call ( 'TestTenth' , { val : 0.1 } ) ,
1485
+ cli . call ( 'TestTenth' , { val : 9.1 } ) ,
1486
+ cli . call ( 'TestTenth' , { val : 9.11 } ) ,
1487
+ cli . call ( 'TestTenth' , { val : 57.3 / 3 } ) ,
1488
+ ] ) ;
1489
+
1490
+ assert . equal ( c1 . status , 'fulfilled' ) ;
1491
+ assert . equal ( c1 . value . val , 1 / 10 ) ;
1492
+ assert . equal ( c2 . status , 'fulfilled' ) ;
1493
+ assert . equal ( c2 . value . val , 0.1 / 10 ) ;
1494
+ assert . equal ( c3 . status , 'fulfilled' ) ;
1495
+ assert . equal ( c3 . value . val , 9.1 / 10 ) ;
1496
+ assert . equal ( c4 . status , 'rejected' ) ;
1497
+ assert . ok ( c4 . reason instanceof RPCOccurenceConstraintViolationError ) ;
1498
+ assert . equal ( c4 . reason . details . errors [ 0 ] . keyword , 'multipleOf' ) ;
1499
+ assert . equal ( c5 . status , 'fulfilled' ) ;
1500
+ assert . equal ( c5 . value . val , 57.3 / 3 / 10 ) ;
1501
+
1502
+ } finally {
1503
+ await cli . close ( ) ;
1504
+ close ( ) ;
1505
+ }
1506
+
1507
+ } ) ;
1508
+
1431
1509
it ( "should validate calls using in-built validators" , async ( ) => {
1432
-
1510
+
1433
1511
const { endpoint, close, server} = await createServer ( {
1434
1512
protocols : [ 'ocpp1.6' ] ,
1435
1513
strictMode : true ,
0 commit comments