-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
131 lines (119 loc) · 3.55 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import process from 'node:process'
import 'dotenv/config.js'// eslint-disable-line import/no-unassigned-import
import test from 'ava'
import pnotice from './index.js'
const config = {
chat: {
id: process.env.PUSHNOTICE_CHAT_ID,
secret: process.env.PUSHNOTICE_CHAT_SECRET,
},
}
if (config.chat.id) {
console.log('Test file currently being run:', test.meta.file)
test('handle options.disabled = true', async (t) => {
const pn = pnotice('pntest', {
disabled: true,
debug: true,
chat: config.chat,
env: 'test',
})
const response = await pn('hello world', 'INFO')
t.is(response?.error?.title, 'Disabled')
})
test('handle options.chat.id = undefined', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: {
id: undefined,
secret: config.chat.secret,
},
env: 'test',
})
const response = await pn('hello world', 'INFO')
t.is(response?.error?.title, 'MissingChatId')
})
test('handle options.chat.secret = undefined', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: {
id: config.chat.id,
secret: undefined,
},
env: 'test',
})
const response = await pn('hello world', 'INFO')
t.is(response?.error?.title, 'MissingChatSecret')
})
test('handle options.chat = undefined', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: undefined,
env: 'test',
})
const response = await pn('hello world', 'INFO')
t.is(response?.error?.title, 'MissingChatObject')
})
test('handle text being an object', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: config.chat,
env: 'test',
})
const response = await pn({ i: 'am an object' }, 'INFO')
t.is(response?.error?.title, 'TextMustBeString')
})
test('handle namespace being an object', async (t) => {
const pn = pnotice({ i: 'am an object' }, {
disabled: false,
debug: true,
chat: config.chat,
env: 'test',
})
const response = await pn('hello world', 'INFO')
t.is(response?.error?.title, 'NamespaceMustBeString')
})
test('handle level and optionsInner sent', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: config.chat,
env: 'test',
})
const response = await pn('handle level and optionsInner sent', 'WARNING', { silent: true })
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', { silent: true })
t.is(response?.status, 'ok')
})
test('handle successfully sent', async (t) => {
const pn = pnotice('pntest', {
disabled: false,
debug: true,
chat: config.chat,
env: 'test',
})
const response = await pn('handle successfully sent', 'INFO')
t.is(response?.status, 'ok')
})
}