123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import React from 'react';
- import {mount} from 'enzyme';
- import {Client} from 'app/api';
- import AccountSecurityEnroll from 'app/views/settings/account/accountSecurity/accountSecurityEnroll';
- const ENDPOINT = '/users/me/authenticators/';
- describe('AccountSecurityEnroll', function() {
- let wrapper;
- describe('Totp', function() {
- Client.clearMockResponses();
- let authenticator = TestStubs.Authenticators().Totp({
- isEnrolled: false,
- qrcode: [[1, 0]],
- secret: 'secret',
- form: [
- {
- type: 'string',
- name: 'otp',
- },
- ],
- });
- beforeAll(function() {
- Client.addMockResponse({
- url: `${ENDPOINT}${authenticator.authId}/enroll/`,
- body: authenticator,
- });
- wrapper = mount(<AccountSecurityEnroll />, {
- context: {
- router: {
- ...TestStubs.router(),
- params: {
- authId: authenticator.authId,
- },
- },
- },
- });
- });
- it('does not have enrolled circle indicator', function() {
- expect(wrapper.find('CircleIndicator').prop('enabled')).toBe(false);
- });
- it('has qrcode component', function() {
- expect(wrapper.find('Qrcode')).toHaveLength(1);
- });
- it('can enroll', function() {
- let enrollMock = Client.addMockResponse({
- url: `${ENDPOINT}${authenticator.authId}/enroll/`,
- method: 'POST',
- });
- wrapper.find('input[name="otp"]').simulate('change', {target: {value: 'otp'}});
- wrapper.find('Form').simulate('submit');
- expect(enrollMock).toHaveBeenCalledWith(
- `${ENDPOINT}15/enroll/`,
- expect.objectContaining({
- method: 'POST',
- data: expect.objectContaining({
- secret: 'secret',
- otp: 'otp',
- }),
- })
- );
- });
- });
- describe.skip('Recovery', function() {
- beforeEach(function() {
- Client.clearMockResponses();
- Client.addMockResponse({
- url: `${ENDPOINT}16/`,
- body: TestStubs.Authenticators().Recovery(),
- });
- wrapper = mount(<AccountSecurityEnroll />, {
- context: {
- router: {
- ...TestStubs.router(),
- params: {
- authId: 16,
- },
- },
- },
- });
- });
- it('has enrolled circle indicator', function() {
- expect(wrapper.find('CircleIndicator').prop('enabled')).toBe(true);
- });
- it('has created and last used dates', function() {
- expect(wrapper.find('AuthenticatorDate')).toHaveLength(2);
- });
- it('does not have remove button', function() {
- expect(wrapper.find('RemoveConfirm')).toHaveLength(0);
- });
- it('regenerates codes', function() {
- let deleteMock = Client.addMockResponse({
- url: `${ENDPOINT}16/`,
- method: 'PUT',
- });
- wrapper.find('RecoveryCodes').prop('onRegenerateBackupCodes')();
- expect(deleteMock).toHaveBeenCalled();
- });
- });
- });
|