Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 9, 2019
1 parent 471af3a commit d26ff26
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
37 changes: 36 additions & 1 deletion test/db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ describe('Querying an entity', () => {
describe('single-row function', () => {
let result;
beforeEach(done => {
db.func('find_user', 1, pgp.queryResult.one)
db.func('findUser', 1, pgp.queryResult.one)
.then(data => {
result = data;
})
Expand Down Expand Up @@ -2122,6 +2122,41 @@ describe('Querying an entity', () => {
}
});
});

describe('stored procedures', () => {
describe('normal call', () => {
let ver;
beforeEach(done => {
db.connect().then(c => {
c.done();
ver = +c.client.version.split('.')[0];
done();
});
});

it('must resolve with null', async () => {
if (ver >= 11) {
const res = await db.proc('test_proc');
expect(res).toBeNull();
}
});
});

describe('with invalid name', () => {
let err;
beforeEach(done => {
db.proc()
.catch(e => {
err = e.message;
done();
});
});
it('must throw error', () => {
expect(err).toBe('Invalid procedure name.');
});
});

});
});

describe('Task', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/db/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const db = header.db;
await db.tx(async t => {

// drop all functions;
await t.none('DROP FUNCTION IF EXISTS find_user(int)');
await t.none('DROP FUNCTION IF EXISTS "findUser"(int)');
await t.none('DROP FUNCTION IF EXISTS get_users()');

// drop all tables;
Expand Down Expand Up @@ -62,7 +62,7 @@ const db = header.db;
await t.none('INSERT INTO person(name, dob) VALUES($1, $2)', ['Peter', new Date(1992, 11, 3)]);

// adding functions & procedures;
await t.none('CREATE OR REPLACE FUNCTION find_user(userId int) RETURNS SETOF users AS $$ SELECT * FROM users WHERE id = userId $$ language \'sql\'');
await t.none('CREATE OR REPLACE FUNCTION "findUser"(userId int) RETURNS SETOF users AS $$ SELECT * FROM users WHERE id = userId $$ language \'sql\'');
await t.none('CREATE OR REPLACE FUNCTION get_users() RETURNS SETOF users AS $$ SELECT * FROM users $$ language \'sql\'');

if (serverHighVer >= 11) {
Expand Down
2 changes: 1 addition & 1 deletion test/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ describe('pgFormatting', () => {
ctx.push(e);
};
promise.all([
db.func('find_user', [1]),
db.func('findUser', [1]),
db.one('select * from users where id=$1', [1])
])
.then(data => {
Expand Down

0 comments on commit d26ff26

Please sign in to comment.