Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the unit tests for db repos to test calls for pg-promise helpers namespace #1649

Closed
nazarhussain opened this issue Feb 28, 2018 · 4 comments

Comments

Projects
3 participants
@nazarhussain
Copy link
Contributor

commented Feb 28, 2018

Expected behavior

Should be able to stub pg-promise helpers namespace.

sinonSandbox.spy(pgp.helpers, 'insert')

Actual behavior

Currently we can't stub the helpers namespace due to which we are not testing helper functions calls.

Steps to reproduce

In any unit test file add this line

sinonSandbox.spy(db.$config.pgp.helpers, 'insert')

This will cause an error TypeError: Cannot redefine property: insert

Fix

The issue is reported on pg-promise and is fixed. vitaly-t/pg-promise#473. Need to upgrade pg-promise higher than 8.1.1 and go through all db repos unit tests to see such use cases.

Which version(s) does this affect? (Environment, OS, etc...)

1.0.0

@karmacoma karmacoma added the update label Mar 1, 2018

@karmacoma karmacoma changed the title Upgrade pg-promise to 8.1.1 Update pg-promise to 8.1.1 Mar 1, 2018

@karmacoma karmacoma added this to New Issues in Sprint Board 26-02-18 via automation Mar 1, 2018

@karmacoma karmacoma added this to Open Issues in Version 1.0.0 via automation Mar 1, 2018

@karmacoma karmacoma added the *easy label Mar 1, 2018

@karmacoma karmacoma removed this from New Issues in Sprint Board 26-02-18 Mar 1, 2018

@karmacoma karmacoma added this to New Issues in Sprint Board 05-03-18 via automation Mar 5, 2018

@MaciejBaj MaciejBaj added this to New Issues in Sprint Board 12-03-18 via automation Mar 13, 2018

@MaciejBaj MaciejBaj removed this from New Issues in Sprint Board 05-03-18 Mar 13, 2018

@MaciejBaj MaciejBaj moved this from New Issues to Previous Issues in Sprint Board 12-03-18 Mar 13, 2018

@nazarhussain nazarhussain changed the title Update pg-promise to 8.1.1 Update the unit tests for db repos to test call to pg-promise helpers namespace Mar 15, 2018

@nazarhussain nazarhussain changed the title Update the unit tests for db repos to test call to pg-promise helpers namespace Update the unit tests for db repos to test calls for pg-promise helpers namespace Mar 15, 2018

@nazarhussain

This comment has been minimized.

Copy link
Contributor Author

commented Mar 15, 2018

@vitaly-t I am working not this task and it seems upgrade to 8.2.1 still didn't solved the problem.

console.log(db.$config.version);   // 8.2.1
console.log(db.$config.options.noLocking);  // true
sinonSandbox.spy(db.$config.pgp.helpers, 'insert');

Still getting same error:

TypeError: Cannot redefine property: insert
@vitaly-t

This comment has been minimized.

Copy link
Collaborator

commented Mar 15, 2018

@nazarhussain I just did a quick test...

This one throws an error:

const pgp = require('pg-promise')({});
const db = pgp('test');
db.$config.pgp.helpers.insert = 123;

and this one doesn't:

const pgp = require('pg-promise')({
    noLocking: true
});
const db = pgp('test');
db.$config.pgp.helpers.insert = 123;

So the problem was fixed correctly. Not sure why the stubbing wouldn't work on your end...

@nazarhussain

This comment has been minimized.

Copy link
Contributor Author

commented Mar 15, 2018

Ok I run this outside the app and its working as expected, now need to look what's blocking this behavior inside our app code base.

https://runkit.com/nazarhussain/5aaa8014ba34410012a86157

@nazarhussain

This comment has been minimized.

Copy link
Contributor Author

commented Mar 16, 2018

@MaciejBaj MaciejBaj closed this in e83391b Mar 16, 2018

Version 1.0.0 automation moved this from Open Issues to Closed Issues Mar 16, 2018

Sprint Board 12-03-18 automation moved this from Previous Issues to Closed Issues Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.