'use strict';

const { Provider } = require('../../lib');
const { expect } = require('chai');
const sinon = require('sinon');

describe('provider instance', function () {
  describe('#urlFor', function () {
    it('returns the route for unprefixed issuers', function () {
      const provider = new Provider('http://localhost');
      expect(provider.urlFor('authorization')).to.equal('http://localhost/auth');
    });

    it('returns the route for prefixed issuers', function () {
      const provider = new Provider('http://localhost/op/2.0');
      expect(provider.urlFor('authorization')).to.equal('http://localhost/op/2.0/auth');
    });

    it('passes the options', function () {
      const provider = new Provider('http://localhost');
      expect(provider.urlFor('resume', { grant: 'foo' })).to.equal('http://localhost/auth/foo');
    });
  });

  describe('#resume', function () {
    it('redirects the context, and sets a cookie', function () {
      const provider = new Provider('http://localhost');

      const ctx = { cookies: { set: sinon.spy() }, redirect: sinon.spy() };

      provider.resume(ctx, 'foo', {});

      expect(ctx.cookies.set.calledOnce).to.be.true;
      expect(ctx.cookies.set.firstCall.calledWith('_grant_result', '{}',
        {
          path: '/auth/foo',
          httpOnly: true,
          maxAge: 3600000,
          signed: true
        }
      )).to.be.true;
      expect(ctx.redirect.calledOnce).to.be.true;
      expect(ctx.redirect.firstCall.calledWith('http://localhost/auth/foo')).to.be.true;
    });
  });
});

@@ -164,16 +164,601 @@
 on () %7B%0A
+  context('when in non test environment', function () %7B%0A    /* eslint-disable no-console */%0A    before(() =%3E %7B%0A      delete process.env.NODE_ENV;%0A      sinon.stub(console, 'warn', () =%3E %7B%7D);%0A    %7D);%0A    after(() =%3E %7B%0A      process.env.NODE_ENV = 'test';%0A      console.warn.restore();%0A    %7D);%0A%0A    it('it warns when draft/experimental specs are enabled', function () %7B%0A      new Provider('http://localhost', %7B // eslint-disable-line no-new%0A        features: %7B sessionManagement: true %7D%0A      %7D);%0A%0A      expect(console.warn.calledOnce).to.be.true;%0A    %7D);%0A    /* eslint-enable */%0A  %7D);%0A%0A
   descri

test feature warnings