diff --git a/index.js b/index.js index fbf8f3f..7591bdc 100644 --- a/index.js +++ b/index.js @@ -104,7 +104,8 @@ function isString(value) { function pnotice(namespace, options = {}) { return (text, level = 'INFO', optionsInner = {}) => { if (!isString(level)) { - optionsInner = level + optionsInner = { ...level } + level = undefined } if (optionsInner.level) { diff --git a/test.js b/test.js index 3f085bc..526f668 100644 --- a/test.js +++ b/test.js @@ -96,6 +96,17 @@ if (config.chat.id) { t.is(response?.status, 'ok') }) + test('handle no level but optionsInner (with level) as second argument', async (t) => { + const pn = pnotice('pntest', { + disabled: false, + debug: true, + chat: config.chat, + env: 'test', + }) + const response = await pn('handle no level but optionsInner (with level) as second argument', { level: 'TESTING', silent: true }) + t.is(response?.status, 'ok') + }) + test('handle no level but optionsInner as second argument', async (t) => { const pn = pnotice('pntest', { disabled: false, @@ -103,7 +114,7 @@ if (config.chat.id) { chat: config.chat, env: 'test', }) - const response = await pn('handle no level but optionsInner as second argument', { level: 'TESTING', silent: true }) + const response = await pn('handle no level but optionsInner as second argument', { silent: true }) t.is(response?.status, 'ok') })