{"size": 1293, "ext": "js", "max_stars_repo_path": "test/src/middleware.test.js", "max_stars_repo_name": "uk-gov-mirror/hmcts.one-per-page-test-suite", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/src/middleware.test.js", "max_issues_repo_name": "uk-gov-mirror/hmcts.one-per-page-test-suite", "max_issues_repo_issues_event_min_datetime": "2018-09-20T16:47:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-23T09:31:18.000Z", "max_forks_repo_path": "test/src/middleware.test.js", "max_forks_repo_name": "uk-gov-mirror/hmcts.one-per-page-test-suite", "max_forks_repo_forks_event_min_datetime": "2018-11-01T21:52:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-10T22:45:23.000Z"}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": 2, "avg_line_length": 26.387755102, "max_line_length": 133, "alphanum_fraction": 0.5761794277}
const modulePath = 'src/middleware';

const { nextMock, hasMiddleware } = require(modulePath);
const chai = require('chai');
const EntryPoint = require('@hmcts/one-per-page/src/steps/EntryPoint');
const sinon = require('sinon');
const { redirectTo } = require('@hmcts/one-per-page/src/flow');

const expect = chai.expect;

describe(modulePath, () => {
  describe('#hasMiddleware', () => {
    const middleware1 = () => {
      return true;
    };
    const middleware2 = () => {
      return false;
    };

    const Step = class extends EntryPoint {
      get middleware() {
        return [ middleware1 ];
      }
      next() {
        return redirectTo({ path: '' });
      }
    };

    it('passes if middleware is defined', () => {
      return hasMiddleware(Step, [ middleware1 ]);
    });

    it('fails if middleware not defined', () => {
      const shouldFail = () => {
        return hasMiddleware(Step, [ middleware2 ]);
      };
      return expect(shouldFail).to.throw('The following middleware was not found in step: expected [ Array(1) ] to deeply equal []');
    });
  });

  describe('#nextmock', () => {
    it('returns a middleware mock', () => {
      const next = sinon.stub();
      nextMock({}, {}, next);
      expect(next.calledOnce).to.eql(true);
    });
  });
});
