1
1
'use strict'
2
- var helper = require ( './test-helper' )
2
+ const helper = require ( './test-helper' )
3
+ const assert = require ( 'assert' )
3
4
const suite = new helper . Suite ( )
4
5
5
6
suite . test ( 'emits notify message' , function ( done ) {
6
- var client = helper . client ( )
7
+ const client = helper . client ( )
7
8
client . query ( 'LISTEN boom' , assert . calls ( function ( ) {
8
- var otherClient = helper . client ( )
9
- var bothEmitted = - 1
9
+ const otherClient = helper . client ( )
10
+ let bothEmitted = - 1
10
11
otherClient . query ( 'LISTEN boom' , assert . calls ( function ( ) {
11
12
assert . emits ( client , 'notification' , function ( msg ) {
12
13
// make sure PQfreemem doesn't invalidate string pointers
@@ -32,17 +33,17 @@ suite.test('emits notify message', function (done) {
32
33
} )
33
34
34
35
// this test fails on travis due to their config
35
- suite . test ( 'emits notice message' , false , function ( done ) {
36
+ suite . test ( 'emits notice message' , function ( done ) {
36
37
if ( helper . args . native ) {
37
- console . error ( 'need to get notice message working on native ' )
38
+ console . error ( 'notice messages do not work curreintly with node-libpq ' )
38
39
return done ( )
39
40
}
40
- // TODO this doesn't work on all versions of postgres
41
- var client = helper . client ( )
41
+
42
+ const client = helper . client ( )
42
43
const text = `
43
44
DO language plpgsql $$
44
45
BEGIN
45
- RAISE NOTICE 'hello, world!';
46
+ RAISE NOTICE 'hello, world!' USING ERRCODE = '23505', DETAIL = 'this is a test' ;
46
47
END
47
48
$$;
48
49
`
51
52
} )
52
53
assert . emits ( client , 'notice' , function ( notice ) {
53
54
assert . ok ( notice != null )
55
+ // notice messages should not be error instances
56
+ assert ( notice instanceof Error === false )
57
+ assert . strictEqual ( notice . name , 'notice' )
58
+ assert . strictEqual ( notice . message , 'hello, world!' )
59
+ assert . strictEqual ( notice . detail , 'this is a test' )
60
+ assert . strictEqual ( notice . code , '23505' )
54
61
done ( )
55
62
} )
56
63
} )
0 commit comments