Skip to content

Commit 317de36

Browse files
committed
Adding test file (not tested, just for archive for now).
1 parent e2306a1 commit 317de36

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

test.js

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
const test = require('ava')
2+
const pnotice = require('.')
3+
4+
// TODO: find a way to load config.chat from file?
5+
6+
const config = {
7+
chat: {
8+
id: '21614670',
9+
secret: '37be8b95538a70eb8a08e56c945f38e6dad50bfc',
10+
},
11+
}
12+
13+
14+
console.log('Test file currently being run:', test.meta.file)
15+
16+
test('handle options.disabled = true', async (t) => {
17+
const pn = pnotice('pntest', {
18+
disabled: true,
19+
debug: true,
20+
chat: config.chat,
21+
env: 'test',
22+
})
23+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'Disabled')
24+
})
25+
26+
test('handle options.chat.id = undefined', async (t) => {
27+
const pn = pnotice('pntest', {
28+
disabled: false,
29+
debug: true,
30+
chat: {
31+
id: undefined,
32+
secret: config.chat.secret,
33+
},
34+
env: 'test',
35+
})
36+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatId')
37+
})
38+
39+
test('handle options.chat.secret = undefined', async (t) => {
40+
const pn = pnotice('pntest', {
41+
disabled: false,
42+
debug: true,
43+
chat: {
44+
id: config.chat.id,
45+
secret: undefined,
46+
},
47+
env: 'test',
48+
})
49+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatSecret')
50+
})
51+
52+
test('handle options.chat = undefined', async (t) => {
53+
const pn = pnotice('pntest', {
54+
disabled: false,
55+
debug: true,
56+
chat: undefined,
57+
env: 'test',
58+
})
59+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatObject')
60+
})
61+
62+
test('handle text being an object', async (t) => {
63+
const pn = pnotice('pntest', {
64+
disabled: false,
65+
debug: true,
66+
chat: config.chat,
67+
env: 'test',
68+
})
69+
t.is((await pn({ i: 'am an object' }, 'INFO'))?.error?.title, 'TextMustBeString')
70+
})
71+
72+
test('handle namespace being an object', async (t) => {
73+
const pn = pnotice({ i: 'am an object' }, {
74+
disabled: false,
75+
debug: true,
76+
chat: config.chat,
77+
env: 'test',
78+
})
79+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'NamespaceMustBeString')
80+
})
81+
82+
test('handle successfully sent', async (t) => {
83+
const pn = pnotice('pntest', {
84+
disabled: false,
85+
debug: true,
86+
chat: config.chat,
87+
env: 'test',
88+
})
89+
t.is((await pn('hello world', 'INFO'))?.success, true)
90+
})
91+
const test = require('ava')
92+
const pnotice = require('.')
93+
94+
// TODO: find a way to load config.chat from file?
95+
96+
console.log('Test file currently being run:', test.meta.file)
97+
98+
test('handle options.disabled = true', async (t) => {
99+
const pn = pnotice('pntest', {
100+
disabled: true,
101+
debug: true,
102+
chat: config.chat,
103+
env: 'test',
104+
})
105+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'Disabled')
106+
})
107+
108+
test('handle options.chat.id = undefined', async (t) => {
109+
const pn = pnotice('pntest', {
110+
disabled: false,
111+
debug: true,
112+
chat: {
113+
id: undefined,
114+
secret: config.chat.secret,
115+
},
116+
env: 'test',
117+
})
118+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatId')
119+
})
120+
121+
test('handle options.chat.secret = undefined', async (t) => {
122+
const pn = pnotice('pntest', {
123+
disabled: false,
124+
debug: true,
125+
chat: {
126+
id: config.chat.id,
127+
secret: undefined,
128+
},
129+
env: 'test',
130+
})
131+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatSecret')
132+
})
133+
134+
test('handle options.chat = undefined', async (t) => {
135+
const pn = pnotice('pntest', {
136+
disabled: false,
137+
debug: true,
138+
chat: undefined,
139+
env: 'test',
140+
})
141+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'MissingChatObject')
142+
})
143+
144+
test('handle text being an object', async (t) => {
145+
const pn = pnotice('pntest', {
146+
disabled: false,
147+
debug: true,
148+
chat: config.chat,
149+
env: 'test',
150+
})
151+
t.is((await pn({ i: 'am an object' }, 'INFO'))?.error?.title, 'TextMustBeString')
152+
})
153+
154+
test('handle namespace being an object', async (t) => {
155+
const pn = pnotice({ i: 'am an object' }, {
156+
disabled: false,
157+
debug: true,
158+
chat: config.chat,
159+
env: 'test',
160+
})
161+
t.is((await pn('hello world', 'INFO'))?.error?.title, 'NamespaceMustBeString')
162+
})
163+
164+
test('handle successfully sent', async (t) => {
165+
const pn = pnotice('pntest', {
166+
disabled: false,
167+
debug: true,
168+
chat: config.chat,
169+
env: 'test',
170+
})
171+
t.is((await pn('hello world', 'INFO'))?.success, true)
172+
})

0 commit comments

Comments
 (0)