From 512eb925d4033bbeee797008b9c94c7cac260845 Mon Sep 17 00:00:00 2001 From: Nandana-NNR Date: Thu, 22 Aug 2024 15:35:37 +0530 Subject: [PATCH] FIRECERT-2274-errorschema fix --- src/EventInvocation.js | 4 +- src/MethodInvoker.js | 4 +- src/Test_Runner.js | 12 +++--- src/constant.js | 2 - src/source/errorSchema.json | 76 ++++++++++--------------------------- src/utils/Utils.js | 5 +-- 6 files changed, 33 insertions(+), 70 deletions(-) diff --git a/src/EventInvocation.js b/src/EventInvocation.js index 63297d1a..40c29421 100644 --- a/src/EventInvocation.js +++ b/src/EventInvocation.js @@ -138,7 +138,7 @@ export class EventInvocation { let schemaValidationResult = {}; let schemaValidationStatus = CONSTANTS.PASS; if (message.params.isNotSupportedApi == true) { - schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE); + schemaValidationResult = errorSchemaCheck(listenerResponse); schemaValidationStatus = CONSTANTS.FAIL; } registrationResponse['eventListenerSchemaResult'] = { @@ -153,7 +153,7 @@ export class EventInvocation { } registrationResponse['eventListenerResponse'] = { result: null, error: listenerResponse }; // In case of error, validate error against errorschema - const schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE); + const schemaValidationResult = errorSchemaCheck(listenerResponse); if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) { registrationResponse['eventListenerSchemaResult'] = { status: CONSTANTS.FAIL, diff --git a/src/MethodInvoker.js b/src/MethodInvoker.js index d5d2305b..476a9579 100644 --- a/src/MethodInvoker.js +++ b/src/MethodInvoker.js @@ -103,7 +103,7 @@ export class MethodInvoker { if (process.env.STANDALONE == true) { // if the method is not supported and it gives a valid response, validate against errorschema instead of api schema if (message.params.isNotSupportedApi == true && response != undefined) { - schemaValidationResult = errorSchemaCheck(response, process.env.COMMUNICATION_MODE); + schemaValidationResult = errorSchemaCheck(response); } } } catch (error) { @@ -135,7 +135,7 @@ export class MethodInvoker { let apiResponse, responseCode, schemaValidationStatus; if (err) { apiResponse = { result: null, error: err }; - schemaValidationResult = errorSchemaCheck(err, process.env.COMMUNICATION_MODE); + schemaValidationResult = errorSchemaCheck(err); if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) { if (err.message != undefined && CONSTANTS.ERROR_LIST.includes(err.message)) { responseCode = CONSTANTS.STATUS_CODE[3]; diff --git a/src/Test_Runner.js b/src/Test_Runner.js index 812ff2d9..1954137e 100644 --- a/src/Test_Runner.js +++ b/src/Test_Runner.js @@ -52,7 +52,7 @@ const TAG = '[Test_Runner]: '; */ let execMode; let invokedSdk; -let errorSchemaBasedOnMode; +let errorSchemaValue; /* Start and End time of API invocation @@ -103,7 +103,7 @@ export class Test_Runner { const resultStartTime = new Date(); let suiteStartTime = new Date(); let errorSchemaResult; - errorSchemaBasedOnMode = process.env.COMMUNICATION_MODE == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK]; + errorSchemaValue = errorSchema[errorSchema]; // This is the list of validation Results for each api ,This is the list that will be used for creating the report for (const executionMode of execModes) { @@ -200,9 +200,9 @@ export class Test_Runner { } if (this.methodFilters.isExceptionMethod(methodObj.name, example.params)) { if (method.examples[exampleIndex].schema) { - method.examples[exampleIndex].schema = errorSchemaBasedOnMode; + method.examples[exampleIndex].schema = errorSchemaValue; } else { - method.result.schema = errorSchemaBasedOnMode; + method.result.schema = errorSchemaValue; } } if (communicationMode == CONSTANTS.TRANSPORT) { @@ -1206,7 +1206,7 @@ export class Test_Runner { let obj; const NOT_SUPPORTED_ERROR_MESSAGES = ['Unsupported', 'Not supported', 'not supported']; const errMessage = '{"code":' + error.code + ',"message":' + error.message + '}'; - const schemaValidationResult = errorSchemaCheck(error, process.env.COMMUNICATION_MODE); + const schemaValidationResult = errorSchemaCheck(error); if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) { obj = { error: error, @@ -1214,7 +1214,7 @@ export class Test_Runner { errorSchemaResult: true, methodWithExampleName: methodWithExampleName, methodUuid: this.createUUID(), - schemaData: errorSchemaBasedOnMode, + schemaData: errorSchemaValue, }; } else { NOT_SUPPORTED_ERROR_MESSAGES.some((errorMessage) => error.message.includes(errorMessage)); diff --git a/src/constant.js b/src/constant.js index 0d98cab4..90f29a9e 100644 --- a/src/constant.js +++ b/src/constant.js @@ -172,6 +172,4 @@ export const CONSTANTS = { EXCLUDED_METHODS_FOR_MFOS: [], ...CONFIG_CONSTANTS, VERSIONS: 'Versions', - ERROR_SCHEMA_TRANSPORT: 'errorSchemaTransport', - ERROR_SCHEMA_SDK: 'errorSchemaSDK', }; diff --git a/src/source/errorSchema.json b/src/source/errorSchema.json index 0f7e4011..7f115d7d 100644 --- a/src/source/errorSchema.json +++ b/src/source/errorSchema.json @@ -1,57 +1,23 @@ { - "errorSchemaSDK": { - "oneOf": [ - { - "type": "object", - "additionalProperties": false, - "required": [ - "code", - "message" - ], - "properties": { - "code": { - "title": "errorObjectCode", - "description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.", - "type": "integer" - }, - "message": { - "title": "errorObjectMessage", - "description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.", - "type": "string" - }, - "data": { - "title": "errorObjectData", - "description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)." - } - } - }, - { - "type": "string" - } - ] - }, - "errorSchemaTransport": { - "type": "object", - "additionalProperties": false, - "required": [ - "code", - "message" - ], - "properties": { - "code": { - "title": "errorObjectCode", - "description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.", - "type": "integer" - }, - "message": { - "title": "errorObjectMessage", - "description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.", - "type": "string" - }, - "data": { - "title": "errorObjectData", - "description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)." - } - } + "errorSchema": { + "type": "object", + "additionalProperties": false, + "required": ["code", "message"], + "properties": { + "code": { + "title": "errorObjectCode", + "description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.", + "type": "integer" + }, + "message": { + "title": "errorObjectMessage", + "description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.", + "type": "string" + }, + "data": { + "title": "errorObjectData", + "description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)." + } } -} \ No newline at end of file + } +} diff --git a/src/utils/Utils.js b/src/utils/Utils.js index ad91a998..cc7103d7 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -292,11 +292,10 @@ function filterExamples(programlist, programType, offeringType) { return offeringList; } -function errorSchemaCheck(err, communicationMode) { +function errorSchemaCheck(err) { let schemaValidationResult; if (errorSchema) { - const errorSchemaBasedOnMode = communicationMode == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK]; - schemaValidationResult = validator.validate(err, errorSchemaBasedOnMode); + schemaValidationResult = validator.validate(err, errorSchema[errorSchema]); } return schemaValidationResult; }