text: 'use strict';
  
  const Bell = require('../../');
  const Code = require('code');
  const Hapi = require('hapi');
  const Hoek = require('hoek');
  const Lab = require('lab');
  
  const Mock = require('../mock');
  
  
  const internals = {};
  
  
  const { describe, it } = exports.lab = Lab.script();
  const expect = Code.expect;
  
  
  describe('digitalocean', () => {
  
      it('authenticates with mock', async (flags) => {
  
          const mock = await Mock.v2(flags);
          const server = Hapi.server({ host: 'localhost', port: 80 });
          await server.register(Bell);
  
          const custom = Bell.providers.digitalocean();
          Hoek.merge(custom, mock.provider);
  
          const data = {
              account: {
                  uuid: '1234',
                  email: 'stevesmith@test.com',
                  status: 'active',
                  droplet_limit: 3
              }
          };
  
          Mock.override('https://api.digitalocean.com/v2/account', data);
  
          server.auth.strategy('custom', 'bell', {
              password: 'cookie_encryption_password_secure',
              isSecure: false,
              clientId: 'digitalocean',
              clientSecret: 'secret',
              provider: custom
          });
  
          server.route({
              method: '*',
              path: '/login',
              config: {
                  auth: 'custom',
                  handler: function (request, h) {
  
                      return request.auth.credentials;
                  }
              }
          });
  
          const res1 = await server.inject('/login');
          const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';
  
          const res2 = await mock.server.inject(res1.headers.location);
  
          const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
          expect(res3.result).to.equal({
              provider: 'custom',
              token: '456',
              expiresIn: 3600,
              refreshToken: undefined,
              query: {},
              profile: {
  
                  id: data.account.uuid,
                  email: data.account.email,
                  status: data.account.status,
                  dropletLimit: data.account.droplet_limit,
                  raw: data.account
              }
          });
      });
  
      it('authenticates with mock when user has no email set', async (flags) => {
  
          const mock = await Mock.v2(flags);
          const server = Hapi.server({ host: 'localhost', port: 80 });
          await server.register(Bell);
  
          const custom = Bell.providers.digitalocean();
          Hoek.merge(custom, mock.provider);
  
          const data = {
              account: {
                  uuid: '1234',
                  status: 'active',
                  dropletLimit: 3
              }
          };
  
          Mock.override('https://api.digitalocean.com/v2/account', data);
  
          server.auth.strategy('custom', 'bell', {
              password: 'cookie_encryption_password_secure',
              isSecure: false,
              clientId: 'digitalocean',
              clientSecret: 'secret',
              provider: custom
          });
  
          server.route({
              method: '*',
              path: '/login',
              config: {
                  auth: 'custom',
                  handler: function (request, h) {
  
                      return request.auth.credentials;
                  }
              }
          });
  
          const res1 = await server.inject('/login');
          const cookie = res1.headers['set-cookie'][0].split(';')[0] + ';';
  
          const res2 = await mock.server.inject(res1.headers.location);
  
          const res3 = await server.inject({ url: res2.headers.location, headers: { cookie } });
          expect(res3.result).to.equal({
              provider: 'custom',
              token: '456',
              expiresIn: 3600,
              refreshToken: undefined,
              query: {},
              profile: {
  
                  id: data.account.uuid,
                  email: undefined,
                  status: data.account.status,
                  dropletLimit: data.account.droplet_limit,
                  raw: data.account
              }
          });
      });
  });
  