-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathnotices.js
78 lines (59 loc) · 2.24 KB
/
notices.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
var PQ = require('../');
var assert = require('assert');
describe('Receive notices', function() {
var notice = null;
before(function() {
this.pq = new PQ();
this.pq.connectSync();
this.pq.exec('SET client_min_messages TO DEBUG');
this.pq.on('notice', function (arg) {
notice = arg;
})
});
this.afterEach(function () {
notice = null;
})
it('works with "debug" messages', function() {
this.pq.exec('DO $$BEGIN RAISE DEBUG \'this is a debug message\'; END$$');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'DEBUG');
assert.equal(notice.messagePrimary, 'this is a debug message');
});
it('works with "log" messages', function() {
this.pq.exec('DO $$BEGIN RAISE LOG \'this is a log message\'; END$$');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'LOG');
assert.equal(notice.messagePrimary, 'this is a log message');
});
it('works with "info" messages', function() {
this.pq.exec('DO $$BEGIN RAISE INFO \'this is an info message\'; END$$');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'INFO');
assert.equal(notice.messagePrimary, 'this is an info message');
});
it('works with "notice" messages', function() {
this.pq.exec('DO $$BEGIN RAISE NOTICE \'this is a notice message\'; END$$');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'NOTICE');
assert.equal(notice.messagePrimary, 'this is a notice message');
});
it('works with "warning" messages', function() {
this.pq.exec('DO $$BEGIN RAISE WARNING \'this is a warning message\'; END$$');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'WARNING');
assert.equal(notice.messagePrimary, 'this is a warning message');
});
it('ignores "exception" messages', function() {
this.pq.exec('DO $$BEGIN RAISE EXCEPTION \'this is an exception message\'; END$$');
assert.equal(notice, null);
});
it('works with internally-generated messages', function() {
this.pq.exec('ROLLBACK');
assert.notEqual(notice, null);
assert.equal(notice.severity, 'WARNING');
assert.equal(typeof notice.messagePrimary, 'string'); // might be localized
});
after(function() {
this.pq.finish();
});
});