accountSecurityEnroll.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {Client} from 'app/api';
  4. import AccountSecurityEnroll from 'app/views/settings/account/accountSecurity/accountSecurityEnroll';
  5. const ENDPOINT = '/users/me/authenticators/';
  6. describe('AccountSecurityEnroll', function() {
  7. let wrapper;
  8. describe('Totp', function() {
  9. Client.clearMockResponses();
  10. let authenticator = TestStubs.Authenticators().Totp({
  11. isEnrolled: false,
  12. qrcode: [[1, 0]],
  13. secret: 'secret',
  14. form: [
  15. {
  16. type: 'string',
  17. name: 'otp',
  18. },
  19. ],
  20. });
  21. beforeAll(function() {
  22. Client.addMockResponse({
  23. url: `${ENDPOINT}${authenticator.authId}/enroll/`,
  24. body: authenticator,
  25. });
  26. wrapper = mount(<AccountSecurityEnroll />, {
  27. context: {
  28. router: {
  29. ...TestStubs.router(),
  30. params: {
  31. authId: authenticator.authId,
  32. },
  33. },
  34. },
  35. });
  36. });
  37. it('does not have enrolled circle indicator', function() {
  38. expect(wrapper.find('CircleIndicator').prop('enabled')).toBe(false);
  39. });
  40. it('has qrcode component', function() {
  41. expect(wrapper.find('Qrcode')).toHaveLength(1);
  42. });
  43. it('can enroll', function() {
  44. let enrollMock = Client.addMockResponse({
  45. url: `${ENDPOINT}${authenticator.authId}/enroll/`,
  46. method: 'POST',
  47. });
  48. wrapper.find('input[name="otp"]').simulate('change', {target: {value: 'otp'}});
  49. wrapper.find('Form').simulate('submit');
  50. expect(enrollMock).toHaveBeenCalledWith(
  51. `${ENDPOINT}15/enroll/`,
  52. expect.objectContaining({
  53. method: 'POST',
  54. data: expect.objectContaining({
  55. secret: 'secret',
  56. otp: 'otp',
  57. }),
  58. })
  59. );
  60. });
  61. });
  62. describe.skip('Recovery', function() {
  63. beforeEach(function() {
  64. Client.clearMockResponses();
  65. Client.addMockResponse({
  66. url: `${ENDPOINT}16/`,
  67. body: TestStubs.Authenticators().Recovery(),
  68. });
  69. wrapper = mount(<AccountSecurityEnroll />, {
  70. context: {
  71. router: {
  72. ...TestStubs.router(),
  73. params: {
  74. authId: 16,
  75. },
  76. },
  77. },
  78. });
  79. });
  80. it('has enrolled circle indicator', function() {
  81. expect(wrapper.find('CircleIndicator').prop('enabled')).toBe(true);
  82. });
  83. it('has created and last used dates', function() {
  84. expect(wrapper.find('AuthenticatorDate')).toHaveLength(2);
  85. });
  86. it('does not have remove button', function() {
  87. expect(wrapper.find('RemoveConfirm')).toHaveLength(0);
  88. });
  89. it('regenerates codes', function() {
  90. let deleteMock = Client.addMockResponse({
  91. url: `${ENDPOINT}16/`,
  92. method: 'PUT',
  93. });
  94. wrapper.find('RecoveryCodes').prop('onRegenerateBackupCodes')();
  95. expect(deleteMock).toHaveBeenCalled();
  96. });
  97. });
  98. });