From cf364563035b4e2d395f90d85d3daba0953ae581 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 26 Jul 2017 11:58:38 +0300 Subject: [PATCH] refactor(cloudfunc) formatMsg: name default value --- common/cloudfunc.js | 3 +-- test/common/cloudfunc.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common/cloudfunc.js b/common/cloudfunc.js index 03d688c2..4364c667 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -21,11 +21,10 @@ module.exports.Entity = Entity; module.exports.formatMsg = (msg, name, status) => { status = status || 'ok'; + name = name || ''; if (name) name = '("' + name + '")'; - else - name = ''; return msg + ': ' + status + name; }; diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index ac2975e8..e27718ea 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -122,3 +122,25 @@ test('render', (t) => { }); }); +test('cloudfunc: formatMsg', (t) => { + const msg = 'hello'; + const name = 'name'; + const status = 'ok'; + + const result = CloudFunc.formatMsg(msg, name, status); + + t.equal(result, 'hello: ok("name")'); + t.end(); +}); + +test('cloudfunc: formatMsg', (t) => { + const msg = 'hello'; + const name = null; + const status = 'ok'; + + const result = CloudFunc.formatMsg(msg, name, status); + + t.equal(result, 'hello: ok'); + t.end(); +}); +