Skip to content

Commit

Permalink
make it so that default level is set when optionsInner is used
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisspiegl committed Mar 22, 2022
1 parent fbb3074 commit 75fd853
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,25 @@ 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,
debug: true,
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')
})

Expand Down

0 comments on commit 75fd853

Please sign in to comment.