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

Completed tests for Create method using postgres #36

Merged
merged 3 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions __tests__/functions/databases/postgresql/create.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
// const client = require('../../../../index')(process.env.SID, process.env.AUTH, {
// isPostgres: true,
// appName: 'testApp',
// connectionURI: 'postgres://postgres:yellowjacket@localhost/twoauthtest',
// });

// // client.create("ian", "+17604207520");

// client
// .create('ian', '+12016750593')
// .then(res => console.log(res))
// .catch(err => console.log(err));
// // describe("Tests for Postgres Send", () => {

// // });
const create = require("../../../../functions/databases/postgres/create");
describe('tests the pg create method', () => {
class FakeClient {
constructor(isError) {
this.users = {};
this.isError = isError;
this.pgConnect = function () {
return new Promise((resolve, reject) => {
resolve({
database: {
query: (query, values) => new Promise((resolve, reject) => {
resolve('fakeUser');
}),
},
done: () => null,
});
});
};
this.client = {
verify: {
services: {
create: () => new Promise((resolve, reject) => {
resolve({ sid: 'testSID' });
}),
},
},
};
this.create = create;
}
}

it("generates a postgres row with the correct sid", () => {
const fakeClient = new FakeClient(false);
let database = fakeClient.pgConnect();
return fakeClient.create('fakeUser', '+11231231234').then((user) => {
expect(user).toEqual('fakeUser');
})
})
});
2 changes: 2 additions & 0 deletions functions/databases/postgres/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module.exports = function (userID, phone) {
this.pgConnect()
.then(({ database, done }) => {
if (typeof phone !== 'string') {
done();
reject(new Error('typeof phone must be string'));
}
if (phone.substring(0, 2) !== '+1') {
done();
reject(new Error('phone must be string formatted as such: +1XXXXXXXXXX'));
}
client.verify.services
Expand Down