<commit_before>'use strict';

describe('SignupCtrl', function() {
  var scope;
  var $controller;
  var controller;

  beforeEach(function() {
    module('impactApp');
    scope = {};
  });

  beforeEach(inject(function(_$controller_) {
    $controller = _$controller_;
  }));

  describe('toggleType', function() {
    beforeEach(function() {
      controller = $controller('SignupCtrl', { $scope: scope });
    });

    describe('password to text', function() {
      it('should toggle the input type', function() {
        scope.inputType = 'password';
        scope.toggleType();
        expect(scope.inputType).toBe('text');
      });
    });

    describe('text to password', function() {
      it('should toggle the input type', function() {
        scope.inputType = 'text';
        scope.toggleType();
        expect(scope.inputType).toBe('password');
      });
    });
  });

});
<commit_msg>add signup test<commit_after>'use strict';

describe('SignupCtrl', function() {
  let $scope;
  let $controller;
  let $q;
  let $state = {
    go() {}
  };

  beforeEach(function() {
    module('impactApp');
    spyOn($state, 'go');
  });

  beforeEach(module(function($urlRouterProvider) {
    $urlRouterProvider.deferIntercept();
  }));

  beforeEach(inject(function($rootScope, _$controller_, _$q_) {
    $scope = $rootScope.$new();
    $controller = _$controller_;
    $q = _$q_;
  }));

  describe('toggleType', function() {
    beforeEach(function() {
      $controller('SignupCtrl', { $scope });
    });

    describe('password to text', function() {
      it('should toggle the input type', function() {
        $scope.inputType = 'password';
        $scope.toggleType();
        expect($scope.inputType).toBe('text');
      });
    });

    describe('text to password', function() {
      it('should toggle the input type', function() {
        $scope.inputType = 'text';
        $scope.toggleType();
        expect($scope.inputType).toBe('password');
      });
    });
  });

  describe('resetMongooseError', function() {
    let fakeForm = {
      fakeField: {
        $setValidity() {}
      }
    };

    beforeEach(function() {
      $controller('SignupCtrl', { $scope });
      spyOn(fakeForm.fakeField, '$setValidity');
    });

    it('should remove mongoose error from the field', function() {
      $scope.resetMongooseError(fakeForm, 'fakeField');
      expect(fakeForm.fakeField.$setValidity).toHaveBeenCalled();
      expect(fakeForm.fakeField.$setValidity).toHaveBeenCalledWith('mongoose', true);
    });
  });

  describe('register', function() {
    let fakeForm = {
      $valid: true,
      email: {
        $modelValue: '<EMAIL>',
        $setValidity() {}
      },
      password: {
        $modelValue: '<PASSWORD>',
        $setValidity() {}
      }
    };

    describe('with correct values', function() {
      let fakeCreatedUser = {
        profile: '1234'
      };

      let Auth = {
        createUser() {
          return $q.resolve(fakeCreatedUser);
        }
      };

      beforeEach(function() {
        $controller('SignupCtrl', {
          $scope,
          $state,
          Auth
        });
      });

      it('should create the user, its profile and redirect to the page beneficiaire', function() {
        $scope.register(fakeForm);
        $scope.$apply();

        expect($state.go).toHaveBeenCalled();
        expect($state.go.calls.argsFor(0)[0]).toEqual('profil.beneficiaire');
        expect($state.go.calls.argsFor(0)[1]).toEqual({profileId: fakeCreatedUser.profile});
      });
    });

    describe('with incorrect values', function() {
      let fakeError = {
        data: {
          errors: {
            email: {
              message: 'Cette adresse est déjà utilisée.',
            }
          }
        }
      };

      let Auth = {
        createUser() {
          return $q.reject(fakeError);
        }
      };

      beforeEach(function() {
        $controller('SignupCtrl', {
          $scope,
          $state,
          Auth
        });
      });

      it('should explicit the error on the form', function() {
        $scope.register(fakeForm);
        $scope.$apply();

        expect($scope.errors.email).toEqual(fakeError.data.errors.email.message);
      });
    });
  });
});

{'fraction_non_alphanumeric': 0.16498474536493782, 'fraction_numerical': 0.0018774935461159353, 'mean_word_length': 2.361198738170347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4817918', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1240, 'n_words': 225}