<commit_before>var expect = require('chai').expect;

var ArgumentError = require('../../src/exceptions').ArgumentError;

var AuthenticationClient = require('../../src/auth');
var OAuthAuthenticator = require('../../src/auth/OAuthAuthenticator');
var DatabaseAuthenticator = require('../../src/auth/DatabaseAuthenticator');
var PasswordlessAuthenticator = require('../../src/auth/PasswordlessAuthenticator');
var UsersManager = require('../../src/auth/UsersManager');
var TokensManager = require('../../src/auth/TokensManager');


describe('AuthenticationClient', function () {

    it('should raise an error when no options object is provided', function () {
      expect(AuthenticationClient)
        .to.throw(ArgumentError, 'Authentication Client SDK options must be an object');
    });


    it('should raise an error when the token is not valid', function () {
      var options = { token: '', domain: 'tenant.auth.com' };
      var client = AuthenticationClient.bind(null, options);

      expect(client)
        .to.throw(ArgumentError, 'An access token must be provided');
    });


    it('should raise an error when the domain is not valid', function () {
      var client = AuthenticationClient.bind(null, { token: 'token', domain: '' });

      expect(client)
        .to.throw(ArgumentError, 'Must provide a domain');
    });


    describe('instance properties', function () {
      var property;
      var properties = {
        'OAuthAuthenticator': {
          property: 'oauth',
          cls: OAuthAuthenticator
        },
        'DatabaseAuthenticator': {
          property: 'database',
          cls: DatabaseAuthenticator
        },
        'PasswordlessAuthenticator': {
          property: 'passwordless',
          cls: PasswordlessAuthenticator
        },
        'UsersManager': {
          property: 'users',
          cls: UsersManager
        },
        'TokensManager': {
          property: 'tokens',
          cls: TokensManager
        }
      };

      before(function () {
        var options = { token: 'token', domain: 'tenant.auth0.com' };
        this.client = new AuthenticationClient(options);

        // Tests common to all properties.
        for (var name in properties) {
          property = properties[name];

          it('should expose an instance of ' + name, function () {
            expect(this.client[property.property])
              .to.exist
              .to.be.an.instanceOf(property.cls);
          });
        }
      });
    });


    describe('instance methods', function () {
      var method;
      var methods = [];

      before(function () {
        this.client = new AuthenticationClient({ token: '<PASSWORD>', domain: 'auth0.com' });
      });

      for (var i = 0, l = methods.length; i < l; i++) {
        method = methods[i];

        it('should have a ' + method + ' method', function () {
          expect(this.client[method])
            .to.exist
            .to.be.an.instanceOf(Function);
        });
      }
    });<commit_msg>Fix the tests for the AuthenticationClient class<commit_after>var expect = require('chai').expect;

var ArgumentError = require('../../src/exceptions').ArgumentError;

var AuthenticationClient = require('../../src/auth');
var OAuthAuthenticator = require('../../src/auth/OAuthAuthenticator');
var DatabaseAuthenticator = require('../../src/auth/DatabaseAuthenticator');
var PasswordlessAuthenticator = require('../../src/auth/PasswordlessAuthenticator');
var UsersManager = require('../../src/auth/UsersManager');
var TokensManager = require('../../src/auth/TokensManager');

var ensureProperty = require('../utils').ensureProperty;


describe('AuthenticationClient', function () {

  describe('#constructor', function () {
    it('should raise an error when no options object is provided', function () {
      expect(AuthenticationClient)
        .to.throw(ArgumentError, 'Authentication Client SDK options must be an object');
    });


    it('should raise an error when the domain is not valid', function () {
      var client = AuthenticationClient.bind(null, { token: 'token', domain: '' });

      expect(client)
        .to.throw(ArgumentError, 'Must provide a domain');
    });
  });


  describe('instance properties', function () {
    var properties = {
      'OAuthAuthenticator': {
        name: 'oauth',
        cls: OAuthAuthenticator
      },
      'DatabaseAuthenticator': {
        name: 'database',
        cls: DatabaseAuthenticator
      },
      'PasswordlessAuthenticator': {
        name: 'passwordless',
        cls: PasswordlessAuthenticator
      },
      'UsersManager': {
        name: 'users',
        cls: UsersManager
      },
      'TokensManager': {
        name: 'tokens',
        cls: TokensManager
      }
    };
    var options = {
      clientId: 'CLIENT_ID',
      domain: 'tenant.auth0.com'
    };
    var client = new AuthenticationClient(options);

    // Tests common to all properties.
    for (var name in properties) {
      var property = properties[name];

      it('should expose an instance of ' + name, ensureProperty(client, property.name, property.cls));
    }
  });


  describe('instance methods', function () {
    var method;
    var methods = [];
    var client = new AuthenticationClient({ token: 'token', domain: 'auth0.com' });

    methods.forEach(function (method) {
      ensureMethod(client, method);
    });
  });
{'fraction_non_alphanumeric': 0.14163885799035966, 'fraction_numerical': 0.0009269558769002596, 'mean_word_length': 2.5775862068965516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1676979', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1411, 'n_words': 359}