Skip to content

Commit

Permalink
API-1 - Logging API codeless block improvement(fixed convert function…
Browse files Browse the repository at this point in the history
… and tests)
  • Loading branch information
macbookpro committed Feb 26, 2024
1 parent 4f38bda commit ef82afd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/logging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export default class Logging {
}

function convertMessageToString(message) {
if (typeof message === 'undefined') {
return 'undefined'
}

if (typeof message === 'function') {
return Object.prototype.toString.call(message)
}

if (typeof message !== 'string') {
return JSON.stringify(message)
}
Expand Down
18 changes: 10 additions & 8 deletions test/unit/specs/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,29 @@ describe('<Logging>', function() {
const req = prepareMockRequest({})

logger.debug(0)
logger.debug('4')
logger.debug(123)
logger.debug(true)
logger.debug(false)
logger.debug(null)
logger.debug(undefined)
logger.debug(_ => _)
logger.debug({foo: 'bar'})
logger.debug({ foo: 'bar' })
logger.debug(['foo', 123, true, false, null, undefined, { bar: 123 }])

await Backendless.Logging.flush()

expect(req.body.map(b => b.message)).to.deep.equal([
'0',
'4',
'123',
"true",
"false",
"null",
undefined,
undefined,
"{\"foo\":\"bar\"}",
"[\"foo\",123,true,false,null,null,{\"bar\":123}]"
'true',
'false',
'null',
'undefined',
'[object Function]',
'{\"foo\":\"bar\"}',
'[\"foo\",123,true,false,null,null,{\"bar\":123}]'
])
})

Expand Down

0 comments on commit ef82afd

Please sign in to comment.