diff --git a/tests/mock/MockErrorService.js b/tests/mock/MockErrorService.js index 0eee401..10465ce 100644 --- a/tests/mock/MockErrorService.js +++ b/tests/mock/MockErrorService.js @@ -5,22 +5,10 @@ var MockErrorService = { resource: 'mock_error_service', - // ------------------------------------------------------------------ - // CRUD Methods - // ------------------------------------------------------------------ + read: async function ({ req, params }) { + const meta = this.meta || params.meta; + this.meta = null; - /** - * read operation (read as in CRUD). - * @method read - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - read: function (req, resource, params, config, callback) { if ( req.query && req.query.cors && @@ -39,87 +27,56 @@ var MockErrorService = { params[key] = value; } } - callback( - { + return { + err: { statusCode: parseInt(params.statusCode), output: params.output, message: params.message, read: 'error', }, - null, - this.meta || params.meta, - ); - this.meta = null; + data: null, + meta, + }; }, - /** - * create operation (create as in CRUD). - * @method create - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} body The JSON object that contains the resource data that is being created - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - create: function (req, resource, params, body, config, callback) { - callback( - { + + create: async function ({ params }) { + const meta = this.meta || params.meta; + this.meta = null; + + return { + err: { statusCode: parseInt(params.statusCode), message: params.message, output: params.output, create: 'error', }, - null, - this.meta || params.meta, - ); - this.meta = null; + data: null, + meta, + }; }, - /** - * update operation (update as in CRUD). - * @method update - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} body The JSON object that contains the resource data that is being updated - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - update: function (req, resource, params, body, config, callback) { - callback( - { + + update: async function ({ params }) { + return { + err: { statusCode: parseInt(params.statusCode), message: params.message, output: params.output, update: 'error', }, - null, - ); + data: null, + }; }, - /** - * delete operation (delete as in CRUD). - * @method delete - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - delete: function (req, resource, params, config, callback) { - callback( - { + + delete: async function ({ params }) { + return { + err: { statusCode: parseInt(params.statusCode), message: params.message, output: params.output, delete: 'error', }, - null, - ); + data: null, + }; }, }; diff --git a/tests/mock/MockService.js b/tests/mock/MockService.js index c3d6a53..ed9ff02 100644 --- a/tests/mock/MockService.js +++ b/tests/mock/MockService.js @@ -5,22 +5,10 @@ var MockService = { resource: 'mock_service', - // ------------------------------------------------------------------ - // CRUD Methods - // ------------------------------------------------------------------ + read: async function ({ req, resource, params }) { + const meta = this.meta || params.meta; + this.meta = null; - /** - * read operation (read as in CRUD). - * @method read - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - read: function (req, resource, params, config, callback) { if ( req.query && req.query.cors && @@ -39,9 +27,9 @@ var MockService = { params[key] = value; } } - callback( - null, - { + + return { + data: { operation: { name: 'read', success: true, @@ -51,26 +39,16 @@ var MockService = { params: params, }, }, - this.meta || params.meta, - ); - this.meta = null; + meta, + }; }, - /** - * create operation (create as in CRUD). - * @method create - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} body The JSON object that contains the resource data that is being created - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - create: function (req, resource, params, body, config, callback) { - callback( - null, - { + + create: async function ({ resource, params }) { + const meta = this.meta || params.meta; + this.meta = null; + + return { + data: { operation: { name: 'create', success: true, @@ -80,26 +58,17 @@ var MockService = { params: params, }, }, - this.meta || params.meta, - ); - this.meta = null; + err: null, + meta, + }; }, - /** - * update operation (update as in CRUD). - * @method update - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} body The JSON object that contains the resource data that is being updated - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - update: function (req, resource, params, body, config, callback) { - callback( - null, - { + + update: async function ({ resource, params }) { + const meta = this.meta || params.meta; + this.meta = null; + + return { + data: { operation: { name: 'update', success: true, @@ -109,25 +78,16 @@ var MockService = { params: params, }, }, - this.meta || params.meta, - ); - this.meta = null; + meta, + }; }, - /** - * delete operation (delete as in CRUD). - * @method delete - * @param {Object} req The request object from connect/express - * @param {String} resource The resource name - * @param {Object} params The parameters identify the resource, and along with information - * carried in query and matrix parameters in typical REST API - * @param {Object} [config={}] The config object. It can contain "config" for per-request config data. - * @param {Fetcher~fetcherCallback} callback callback invoked when fetcher is complete. - * @static - */ - delete: function (req, resource, params, config, callback) { - callback( - null, - { + + delete: async function ({ resource, params }) { + const meta = this.meta || params.meta; + this.meta = null; + + return { + data: { operation: { name: 'delete', success: true, @@ -137,9 +97,8 @@ var MockService = { params: params, }, }, - this.meta || params.meta, - ); - this.meta = null; + meta, + }; }, };