From ca6e860f473ee2b2eb1b038665d4bde2b9082fc2 Mon Sep 17 00:00:00 2001 From: Sierra Date: Mon, 8 Jul 2019 18:24:41 -0400 Subject: [PATCH] mongoose create test --- .../functions/databases/mongoose/create.js | 58 +++++++++++++++++++ .../functions/databases/mongoose/send.js | 4 ++ 2 files changed, 62 insertions(+) diff --git a/__tests__/functions/databases/mongoose/create.js b/__tests__/functions/databases/mongoose/create.js index e69de29..9d4ea26 100644 --- a/__tests__/functions/databases/mongoose/create.js +++ b/__tests__/functions/databases/mongoose/create.js @@ -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(); + }); + }); +}); \ No newline at end of file diff --git a/__tests__/functions/databases/mongoose/send.js b/__tests__/functions/databases/mongoose/send.js index e69de29..6590125 100644 --- a/__tests__/functions/databases/mongoose/send.js +++ b/__tests__/functions/databases/mongoose/send.js @@ -0,0 +1,4 @@ +const mongoose = require("mongoose"); +const mongooseSend = require("../../../../functions/databases/mongoose/send"); + +