From 29415441f7a4be28b8d24087bd74e44d175f3fc8 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 16 Jan 2016 09:48:51 -0600 Subject: [PATCH] tests: Create base class that ApiUser and ApiGroup inherit from --- test/helpers/api-integration.helper.js | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/helpers/api-integration.helper.js b/test/helpers/api-integration.helper.js index a3e2ee407c..4482d604b3 100644 --- a/test/helpers/api-integration.helper.js +++ b/test/helpers/api-integration.helper.js @@ -15,32 +15,36 @@ i18n.translations = require('../../website/src/libs/i18n.js').translations; const API_TEST_SERVER_PORT = 3003; -class ApiUser { +class ApiObject { constructor (options) { assign(this, options); + } + + update (options) { + return new Promise((resolve) => { + _updateDocument(this._docType, this, options, resolve); + }); + } +} + +class ApiUser extends ApiObject { + constructor (options) { + super(options); + + this._docType = 'users'; this.get = _requestMaker(this, 'get'); this.post = _requestMaker(this, 'post'); this.put = _requestMaker(this, 'put'); this.del = _requestMaker(this, 'del'); } - - update (options) { - return new Promise((resolve) => { - _updateDocument('users', this, options, resolve); - }); - } } -class ApiGroup { +class ApiGroup extends ApiObject { constructor (options) { - assign(this, options); - } + super(options); - update (options) { - return new Promise((resolve) => { - _updateDocument('groups', this, options, resolve); - }); + this._docType = 'groups'; } }