|
| 1 | +const test = require('ava') |
| 2 | +const pnotice = require('.') |
| 3 | + |
| 4 | +// TODO: must be placed outside of this file and not commited to the repo! |
| 5 | +const config = { |
| 6 | + chat: { |
| 7 | + id: 'xXxXxXxXxXx', |
| 8 | + secret: 'xXxXxXxXxXx', |
| 9 | + }, |
| 10 | +} |
| 11 | + |
| 12 | +console.log('Test file currently being run:', test.meta.file) |
| 13 | + |
| 14 | +test('handle options.disabled = true', async (t) => { |
| 15 | + const pn = pnotice('pntest', { |
| 16 | + disabled: true, |
| 17 | + debug: true, |
| 18 | + chat: config.chat, |
| 19 | + env: 'test', |
| 20 | + }) |
| 21 | + t.is((await pn('hello world', 'INFO'))?.error?.title, 'Disabled') |
| 22 | +}) |
| 23 | + |
| 24 | +test('handle options.chat.id = undefined', async (t) => { |
| 25 | + const pn = pnotice('pntest', { |
| 26 | + disabled: false, |
| 27 | + debug: true, |
| 28 | + chat: { |
| 29 | + id: undefined, |
| 30 | + secret: config.chat.secret, |
| 31 | + }, |
| 32 | + env: 'test', |
| 33 | + }) |
| 34 | + t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatId') |
| 35 | +}) |
| 36 | + |
| 37 | +test('handle options.chat.secret = undefined', async (t) => { |
| 38 | + const pn = pnotice('pntest', { |
| 39 | + disabled: false, |
| 40 | + debug: true, |
| 41 | + chat: { |
| 42 | + id: config.chat.id, |
| 43 | + secret: undefined, |
| 44 | + }, |
| 45 | + env: 'test', |
| 46 | + }) |
| 47 | + t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatSecret') |
| 48 | +}) |
| 49 | + |
| 50 | +test('handle options.chat = undefined', async (t) => { |
| 51 | + const pn = pnotice('pntest', { |
| 52 | + disabled: false, |
| 53 | + debug: true, |
| 54 | + chat: undefined, |
| 55 | + env: 'test', |
| 56 | + }) |
| 57 | + t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatObject') |
| 58 | +}) |
| 59 | + |
| 60 | +test('handle text being an object', async (t) => { |
| 61 | + const pn = pnotice('pntest', { |
| 62 | + disabled: false, |
| 63 | + debug: true, |
| 64 | + chat: config.chat, |
| 65 | + env: 'test', |
| 66 | + }) |
| 67 | + t.is((await pn({ i: 'am an object' }, 'INFO'))?.error?.title, 'TextMustBeString') |
| 68 | +}) |
| 69 | + |
| 70 | +test('handle namespace being an object', async (t) => { |
| 71 | + const pn = pnotice({ i: 'am an object' }, { |
| 72 | + disabled: false, |
| 73 | + debug: true, |
| 74 | + chat: config.chat, |
| 75 | + env: 'test', |
| 76 | + }) |
| 77 | + t.is((await pn('hello world', 'INFO'))?.error?.title, 'NamespaceMustBeString') |
| 78 | +}) |
| 79 | + |
| 80 | +test('handle successfully sent', async (t) => { |
| 81 | + const pn = pnotice('pntest', { |
| 82 | + disabled: false, |
| 83 | + debug: true, |
| 84 | + chat: config.chat, |
| 85 | + env: 'test', |
| 86 | + }) |
| 87 | + t.is((await pn('hello world', 'INFO'))?.success, true) |
| 88 | +}) |
0 commit comments