text: 'use strict';
  
  // Load modules
  
  const Bell = require('../../');
  const Code = require('code');
  const Hapi = require('hapi');
  const Hoek = require('hoek');
  const Lab = require('lab');
  const Mock = require('../mock');
  
  
  // Test shortcuts
  
  const lab = exports.lab = Lab.script();
  const describe = lab.describe;
  const it = lab.it;
  const expect = Code.expect;
  
  
  describe('twitch', () => {
  
      it('authenticates with mock', {
          parallel: false
      }, (done) => {
  
          const mock = new Mock.V2();
          mock.start((provider) => {
  
              const server = new Hapi.Server();
              server.connection({
                  host: 'localhost',
                  port: 80
              });
              server.register(Bell, (err) => {
  
                  expect(err).to.not.exist();
  
                  const custom = Bell.providers.twitch();
                  Hoek.merge(custom, provider);
  
                  const profile = {
                      display_name: 'Kappa',
                      username: 'kappa',
                      name: 'Kappa',
                      email: 'kappa@example.com'
                  };
  
                  Mock.override('https://api.twitch.tv/kraken/user', profile);
  
                  server.auth.strategy('custom', 'bell', {
                      password: 'cookie_encryption_password_secure',
                      isSecure: false,
                      clientId: 'twitch',
                      clientSecret: 'secret',
                      provider: custom
                  });
  
                  server.route({
                      method: '*',
                      path: '/login',
                      config: {
                          auth: 'custom',
                          handler: function (request, reply) {
  
                              reply(request.auth.credentials);
                          }
                      }
                  });
  
                  server.inject('/login', (res) => {
  
                      const cookie = res.headers['set-cookie'][0].split(';')[0] + ';';
                      mock.server.inject(res.headers.location, (mockRes) => {
  
                          server.inject({
                              url: mockRes.headers.location,
                              headers: {
                                  cookie: cookie
                              }
                          }, (response) => {
  
                              Mock.clear();
                              expect(response.result).to.deep.equal({
                                  provider: 'custom',
                                  token: '456',
                                  expiresIn: 3600,
                                  refreshToken: undefined,
                                  query: {},
                                  profile: profile
                              });
  
                              mock.stop(done);
                          });
                      });
                  });
              });
          });
      });
  });
  