authlock

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i authlock

Weekly Downloads

5

Version

1.1.0

License

ISC

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • crowbrammer