1.1.0 • Published 5 years ago

authlock v1.1.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

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");
      });
  });
});
1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago