@@ -2,7 +2,7 @@ const assert = require('assert/strict');
2
2
const http = require ( 'http' ) ;
3
3
const { once } = require ( 'events' ) ;
4
4
const RPCClient = require ( "../lib/client" ) ;
5
- const { TimeoutError, RPCFrameworkError, RPCError, RPCProtocolError, RPCTypeConstraintViolationError, RPCOccurenceConstraintViolationError, RPCPropertyConstraintViolationError } = require ( '../lib/errors' ) ;
5
+ const { TimeoutError, RPCFrameworkError, RPCError, RPCProtocolError, RPCTypeConstraintViolationError, RPCOccurenceConstraintViolationError, RPCPropertyConstraintViolationError, RPCOccurrenceConstraintViolationError , RPCFormationViolationError } = require ( '../lib/errors' ) ;
6
6
const RPCServer = require ( "../lib/server" ) ;
7
7
const { setTimeout } = require ( 'timers/promises' ) ;
8
8
const { createValidator } = require ( '../lib/validator' ) ;
@@ -1050,7 +1050,7 @@ describe('RPCClient', function(){
1050
1050
1051
1051
describe ( '#call' , function ( ) {
1052
1052
1053
- it ( "should reject with 'RPCError' after invalid payload with strictMode" , async ( ) => {
1053
+ it ( "should reject with 'RPCError' after invalid payload with client strictMode" , async ( ) => {
1054
1054
1055
1055
const { endpoint, close, server} = await createServer ( {
1056
1056
protocols : [ 'echo1.0' ]
@@ -1088,6 +1088,46 @@ describe('RPCClient', function(){
1088
1088
1089
1089
} ) ;
1090
1090
1091
+ it ( "should reject with 'RPCError' after invalid payload with server strictMode" , async ( ) => {
1092
+
1093
+ const { endpoint, close, server} = await createServer ( {
1094
+ protocols : [ 'ocpp1.6' ] ,
1095
+ strictMode : true ,
1096
+ } , { withClient : cli => {
1097
+ cli . handle ( ( ) => { } ) ;
1098
+ } } ) ;
1099
+ const cli = new RPCClient ( {
1100
+ endpoint,
1101
+ identity : 'X' ,
1102
+ protocols : [ 'ocpp1.6' ] ,
1103
+ } ) ;
1104
+
1105
+ try {
1106
+ await cli . connect ( ) ;
1107
+
1108
+ const [ c1 , c2 , c3 ] = await Promise . allSettled ( [
1109
+ cli . call ( 'UpdateFirmware' , { } ) ,
1110
+ cli . call ( 'Heartbeat' , { a :123 } ) ,
1111
+ cli . call ( 'UpdateFirmware' , { location : "a" , retrieveDate : "a" } ) ,
1112
+ ] ) ;
1113
+
1114
+ assert . equal ( c1 . status , 'rejected' ) ;
1115
+ assert . equal ( c1 . reason . rpcErrorCode , 'OccurrenceConstraintViolation' ) ;
1116
+ assert . ok ( c1 . reason instanceof RPCOccurrenceConstraintViolationError ) ;
1117
+ assert . equal ( c2 . status , 'rejected' ) ;
1118
+ assert . equal ( c2 . reason . rpcErrorCode , 'PropertyConstraintViolation' ) ;
1119
+ assert . ok ( c2 . reason instanceof RPCPropertyConstraintViolationError ) ;
1120
+ assert . equal ( c3 . status , 'rejected' ) ;
1121
+ assert . equal ( c3 . reason . rpcErrorCode , 'FormationViolation' ) ;
1122
+ assert . ok ( c3 . reason instanceof RPCFormationViolationError ) ;
1123
+
1124
+ } finally {
1125
+ await cli . close ( ) ;
1126
+ close ( ) ;
1127
+ }
1128
+
1129
+ } ) ;
1130
+
1091
1131
1092
1132
it ( "should reject with 'RPCProtocolError' after invalid response with strictMode" , async ( ) => {
1093
1133
const { endpoint, close, server} = await createServer ( {
0 commit comments