Skip to content

Commit

Permalink
Merge pull request #26 from two-factor/editnpm
Browse files Browse the repository at this point in the history
updated package.json
  • Loading branch information
starkspark committed Jul 7, 2019
2 parents 8541a96 + c7c374a commit 2fe7223
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 72 deletions.
2 changes: 1 addition & 1 deletion __tests__/functions/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const create = require("../functions/create");
const create = require("../../functions/create");
describe("tests the create function", () => {
class FakeClient {
constructor(isError) {
Expand Down
50 changes: 25 additions & 25 deletions __tests__/functions/test-send.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const send = require('./../functions/send');
const send = require("../../functions/send");

describe('send unit tests', () => {
describe("send unit tests", () => {
const sid = 1;
const phone = 2;
let mockVerificationCreate = jest.fn();
Expand All @@ -9,63 +9,63 @@ describe('send unit tests', () => {
users: {
test: {
sid,
phone,
phone
}
},
send,
client: {
verify: {
services: () => ({
verifications: {
create: (obj) => {
create: obj => {
mockVerificationCreate();
return new Promise((resolve) => {
return new Promise(resolve => {
resolve(obj);
});
},
},
}),
},
},
}
}
})
}
}
};

beforeEach(() => {
mockVerificationCreate.mockClear();
})
});

it('send should throw error upon sending to nonexistent user', () => {
it("send should throw error upon sending to nonexistent user", () => {
try {
client.send('nonexistent');
client.send("nonexistent");
} catch (err) {
expect(err).toBeInstanceOf(Error);
}
});

it('send should throw error upon nonexistent sid', () => {
it("send should throw error upon nonexistent sid", () => {
try {
client.send('test');
client.send("test");
} catch (err) {
expect(err).toBeInstanceOf(Error);
}
});

it('send should throw error upon nonexistent phone number', () => {
it("send should throw error upon nonexistent phone number", () => {
try {
client.send('test');
client.send("test");
} catch (err) {
expect(err).toBeInstanceOf(Error);
}
})
});

it('send should create a verification', () => {
client.send('test');
client.send('test');
it("send should create a verification", () => {
client.send("test");
client.send("test");
expect(mockVerificationCreate.mock.calls.length).toBe(2);
})
});

it('send should be passing an object to the verification.create call containing phone number and channel', (done) => {
client.send('test').then((res) => {
expect(res).toEqual({ to: phone, channel: 'sms' });
it("send should be passing an object to the verification.create call containing phone number and channel", done => {
client.send("test").then(res => {
expect(res).toEqual({ to: phone, channel: "sms" });
done();
});
});
Expand Down
82 changes: 41 additions & 41 deletions __tests__/functions/verify.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
const verify = require('../functions/verify')
//On client check verify
const verify = require("../../functions/verify");
//On client check verify

describe('#verify', () => {
class FakeClient {
describe("#verify", () => {
class FakeClient {
constructor(isError) {
this.client = {
verify: {
services: () => ({
verificationChecks: {
create: ({to, code}) => {
return new Promise((resolve,reject) => {
if(!isError) resolve({status: 'approved'})
else reject({status: false })
})
}
}
})
verify: {
services: () => ({
verificationChecks: {
create: ({ to, code }) => {
return new Promise((resolve, reject) => {
if (!isError) resolve({ status: "approved" });
else reject({ status: false });
});
}
}
})
}
};
this.verify = verify;
this.users = { Zep: { sid: "Zep3246", phone: "3479087000" } };
}
this.verify = verify
this.users = {'Zep': {'sid':'Zep3246', 'phone':'3479087000'}}
}
}

it('throws an error if this.users is empty', () => {
const fakeClient = new FakeClient(false)
// FakeClient.users = {}
return expect((fakeClient.verify('ian'))).rejects.toBeInstanceOf(Error)
})
it("throws an error if this.users is empty", () => {
const fakeClient = new FakeClient(false);
// FakeClient.users = {}
return expect(fakeClient.verify("ian")).rejects.toBeInstanceOf(Error);
});

it('throws an error if sid of the user not found', () => {
const fakeClient = new FakeClient(false)
fakeClient.users['Zep'].sid = null
// FakeClient.users = {}
return expect((fakeClient.verify('Zep'))).rejects.toBeInstanceOf(Error)
})
it("throws an error if sid of the user not found", () => {
const fakeClient = new FakeClient(false);
fakeClient.users["Zep"].sid = null;
// FakeClient.users = {}
return expect(fakeClient.verify("Zep")).rejects.toBeInstanceOf(Error);
});

it('throws an error if phone of the user not found', () => {
const fakeClient = new FakeClient(false)
fakeClient.users['Zep'].phone = null
// FakeClient.users = {}
return expect((fakeClient.verify('Zep'))).rejects.toBeInstanceOf(Error)
})
it("throws an error if phone of the user not found", () => {
const fakeClient = new FakeClient(false);
fakeClient.users["Zep"].phone = null;
// FakeClient.users = {}
return expect(fakeClient.verify("Zep")).rejects.toBeInstanceOf(Error);
});

it('status approved if the code matches', () => {
const fakeClient = new FakeClient(false)
return expect((fakeClient.verify('Zep'))).resolves.toBeTruthy()
})
})
it("status approved if the code matches", () => {
const fakeClient = new FakeClient(false);

return expect(fakeClient.verify("Zep")).resolves.toBeTruthy();
});
});
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "two-factor",
"name": "two-auth",
"version": "1.0.0",
"description": "This is the two factor twilio library.",
"main": "index.js",
Expand All @@ -10,9 +10,19 @@
"type": "git",
"url": "git+https://github.com/two-factor/two-factor.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"keywords": [
"2fa",
"two-factor",
"two",
"two-factor-authentication",
"factor",
"authentication",
"twilio",
"two-factor",
"two factor authentication"
],
"author": "Ryan Dang, Daniel Nagano-Gerace, Sierra Swaby, Giuseppe Valentino, Ian Geckeler",
"license": "MIT",
"bugs": {
"url": "https://github.com/two-factor/two-factor/issues"
},
Expand All @@ -25,4 +35,4 @@
"dotenv": "^8.0.0",
"jest": "^24.8.0"
}
}
}

0 comments on commit 2fe7223

Please sign in to comment.