1
1
import test from 'ava'
2
- import pnotice from '.'
2
+ import pnotice from './index.js '
3
3
4
4
// TODO: find a way to load config.chat from file?
5
+ const config = {
6
+ chat : {
7
+ id : '' ,
8
+ secret : '' ,
9
+ } ,
10
+ }
5
11
6
12
console . log ( 'Test file currently being run:' , test . meta . file )
7
13
@@ -12,7 +18,8 @@ test('handle options.disabled = true', async (t) => {
12
18
chat : config . chat ,
13
19
env : 'test' ,
14
20
} )
15
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. error ?. title , 'Disabled' )
21
+ const response = await pn ( 'hello world' , 'INFO' )
22
+ t . is ( response ?. error ?. title , 'Disabled' )
16
23
} )
17
24
18
25
test ( 'handle options.chat.id = undefined' , async ( t ) => {
@@ -25,7 +32,8 @@ test('handle options.chat.id = undefined', async (t) => {
25
32
} ,
26
33
env : 'test' ,
27
34
} )
28
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. error ?. title , 'MissingChatId' )
35
+ const response = await pn ( 'hello world' , 'INFO' )
36
+ t . is ( response ?. error ?. title , 'MissingChatId' )
29
37
} )
30
38
31
39
test ( 'handle options.chat.secret = undefined' , async ( t ) => {
@@ -38,7 +46,8 @@ test('handle options.chat.secret = undefined', async (t) => {
38
46
} ,
39
47
env : 'test' ,
40
48
} )
41
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. error ?. title , 'MissingChatSecret' )
49
+ const response = await pn ( 'hello world' , 'INFO' )
50
+ t . is ( response ?. error ?. title , 'MissingChatSecret' )
42
51
} )
43
52
44
53
test ( 'handle options.chat = undefined' , async ( t ) => {
@@ -48,7 +57,8 @@ test('handle options.chat = undefined', async (t) => {
48
57
chat : undefined ,
49
58
env : 'test' ,
50
59
} )
51
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. error ?. title , 'MissingChatObject' )
60
+ const response = await pn ( 'hello world' , 'INFO' )
61
+ t . is ( response ?. error ?. title , 'MissingChatObject' )
52
62
} )
53
63
54
64
test ( 'handle text being an object' , async ( t ) => {
@@ -58,7 +68,8 @@ test('handle text being an object', async (t) => {
58
68
chat : config . chat ,
59
69
env : 'test' ,
60
70
} )
61
- t . is ( ( await pn ( { i : 'am an object' } , 'INFO' ) ) ?. error ?. title , 'TextMustBeString' )
71
+ const response = await pn ( { i : 'am an object' } , 'INFO' )
72
+ t . is ( response ?. error ?. title , 'TextMustBeString' )
62
73
} )
63
74
64
75
test ( 'handle namespace being an object' , async ( t ) => {
@@ -68,7 +79,8 @@ test('handle namespace being an object', async (t) => {
68
79
chat : config . chat ,
69
80
env : 'test' ,
70
81
} )
71
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. error ?. title , 'NamespaceMustBeString' )
82
+ const response = await pn ( 'hello world' , 'INFO' )
83
+ t . is ( response ?. error ?. title , 'NamespaceMustBeString' )
72
84
} )
73
85
74
86
test ( 'handle successfully sent' , async ( t ) => {
@@ -78,5 +90,6 @@ test('handle successfully sent', async (t) => {
78
90
chat : config . chat ,
79
91
env : 'test' ,
80
92
} )
81
- t . is ( ( await pn ( 'hello world' , 'INFO' ) ) ?. success , true )
93
+ const response = await pn ( 'hello world' , 'INFO' )
94
+ t . is ( response ?. status , 'ok' )
82
95
} )
0 commit comments