Skip to content

Commit

Permalink
added mongoose tests from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnaganog committed Jul 8, 2019
2 parents 6c26c6f + 6e0e61a commit 4ea1eca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
58 changes: 58 additions & 0 deletions __tests__/functions/databases/mongoose/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const mongoose = require('mongoose');
const mongooseCreate = require ('../../../../functions/databases/mongoose/create');

describe('tests the create function', () => {
class FakeClient {
constructor(
AccSID,
AuthToken
) {
this.AccSID = AccSID;
this.AuthToken = AuthToken;
this.client = {
verify: {
services: {
create: () => {
const isError = this.isError;
return new Promise((resolve, reject) => {
if (isError) {
reject(new Error("fake error message"));
}
resolve({
sid: "fakeSid"
});
});
}
}
}
};
this.TwoAuthUser = {
create: ({
userID,
sid,
phone
}) => {
return new Promise((resolve, reject) => {
resolve(5)
})
}
};
this.create = mongooseCreate;
}
}

it('generates a user with the right sid', async () => {
const newClient = new FakeClient();
// create a user using client.create()
let result = await newClient.create('ian', '+17604307620')
expect(result).toBe(5)
// query database for that user
});

it('passes error message on rejection', () => {
const newClient = new FakeClient();
let users = newClient.users;
newClient.create('ian', '+17604307620').catch(err => { expect(err instanceof Error).toBeTruthy();
});
});
});
4 changes: 4 additions & 0 deletions __tests__/functions/databases/mongoose/send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const mongoose = require("mongoose");
const mongooseSend = require("../../../../functions/databases/mongoose/send");


0 comments on commit 4ea1eca

Please sign in to comment.