authlock
v1.1.0
Published
For basic backend authentication (designed for use with web socket chat streams).
Downloads
10
Readme
AuthLock
For basic backend authentication (designed for use with web socket chat streams).
const expect = require("chai").expect;
const AuthLock = require("../index");
describe("Auth Setter", () => {
it("Checks the auth and returns an authchecker promise", () => {
let modAuthLock = new AuthLock("moderator");
expect(modAuthLock).to.be.an.instanceof(AuthLock);
expect(modAuthLock.unlock()).to.be.an.instanceof(Promise);
});
it("Checks the auth and returns an authchecker promise", () => {
let userRole = "testPerson"; // The "key"
let modAuthLock = new AuthLock("testPerson");
expect(modAuthLock.keyRole).to.equal("testPerson");
// return in Mocha goes through assertions in the promise chain
return modAuthLock.unlock(userRole).catch(() => {
expect("This shouldn't").to.equal("be called");
});
});
it("Executes code based on role matching", () => {
let userRole = "moderator"; // The "key"
let modAuthLock = new AuthLock("moderator");
// return in Mocha goes through assertions in the promise chain
return modAuthLock
.unlock(userRole)
.then(() => {
expect("This should be run");
})
.catch(() => {
expect("This shouldn't").to.equal("be called");
});
});
it("Executes code 'mismatch' code based on role mismatching", () => {
let userRole = "follower"; // The "key"
let modAuthLock = new AuthLock("moderator");
// return in Mocha goes through assertions in the promise chain
return modAuthLock
.unlock(userRole)
.then(() => {
expect("This shouldn't").to.equal("be called");
})
.catch(() => {
expect("This should be run");
});
});
});