summaryrefslogtreecommitdiff
path: root/web-ui/src/backup_account
diff options
context:
space:
mode:
authorTulio Casagrande <tuliocasagrande@gmail.com>2017-04-04 13:14:34 -0300
committerGitHub <noreply@github.com>2017-04-04 13:14:34 -0300
commitf70c2827d41d1d805d6446670b861b7abf0761b1 (patch)
treedf266fda0c593a27c568215716d48d9994fbd344 /web-ui/src/backup_account
parentaf454c71da106644eee644c4286bbae4788b8e14 (diff)
parentd7914b9b5640c3d85c6230a032180b2e64520bca (diff)
Merge pull request #1042 from pixelated/login-recovery-code
[#935] Sends user recovery code and password to account recovery endpoint
Diffstat (limited to 'web-ui/src/backup_account')
-rw-r--r--web-ui/src/backup_account/backup_email/backup_email.js23
-rw-r--r--web-ui/src/backup_account/backup_email/backup_email.spec.js18
2 files changed, 5 insertions, 36 deletions
diff --git a/web-ui/src/backup_account/backup_email/backup_email.js b/web-ui/src/backup_account/backup_email/backup_email.js
index 8fa71191..ac64f02e 100644
--- a/web-ui/src/backup_account/backup_email/backup_email.js
+++ b/web-ui/src/backup_account/backup_email/backup_email.js
@@ -19,8 +19,8 @@ import 'isomorphic-fetch';
import React from 'react';
import { translate } from 'react-i18next';
import validator from 'validator';
-import browser from 'helpers/browser';
+import { submitForm } from 'src/common/util';
import SubmitButton from 'src/common/submit_button/submit_button';
import InputField from 'src/common/input_field/input_field';
import BackLink from 'src/common/back_link/back_link';
@@ -45,24 +45,11 @@ export class BackupEmail extends React.Component {
};
submitHandler = (event) => {
- event.preventDefault();
-
- fetch('/backup-account', {
- credentials: 'same-origin',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- csrftoken: [browser.getCookie('XSRF-TOKEN')],
- backupEmail: this.state.backupEmail
- })
+ submitForm(event, '/backup-account', {
+ backupEmail: this.state.backupEmail
}).then((response) => {
- if (response.ok) {
- this.props.onSubmit('success');
- } else {
- this.props.onSubmit('error');
- }
+ if (response.ok) this.props.onSubmit('success');
+ else this.props.onSubmit('error');
});
};
diff --git a/web-ui/src/backup_account/backup_email/backup_email.spec.js b/web-ui/src/backup_account/backup_email/backup_email.spec.js
index b23aadaa..a34afa06 100644
--- a/web-ui/src/backup_account/backup_email/backup_email.spec.js
+++ b/web-ui/src/backup_account/backup_email/backup_email.spec.js
@@ -3,7 +3,6 @@ import expect from 'expect';
import React from 'react';
import fetchMock from 'fetch-mock';
import { BackupEmail } from 'src/backup_account/backup_email/backup_email';
-import browser from 'helpers/browser';
describe('BackupEmail', () => {
let backupEmail;
@@ -104,7 +103,6 @@ describe('BackupEmail', () => {
context('on success', () => {
beforeEach((done) => {
mockOnSubmit = expect.createSpy().andCall(() => done());
- expect.spyOn(browser, 'getCookie').andReturn('abc123');
fetchMock.post('/backup-account', 204);
backupEmail = shallow(<BackupEmail t={mockTranslations} onSubmit={mockOnSubmit} />);
@@ -117,26 +115,10 @@ describe('BackupEmail', () => {
expect(fetchMock.called('/backup-account')).toBe(true, 'Backup account POST was not called');
});
- it('sends csrftoken as content', () => {
- expect(fetchMock.lastOptions('/backup-account').body).toContain('"csrftoken":["abc123"]');
- });
-
it('sends user email as content', () => {
expect(fetchMock.lastOptions('/backup-account').body).toContain('"backupEmail":"test@test.com"');
});
- it('sends content-type header', () => {
- expect(fetchMock.lastOptions('/backup-account').headers['Content-Type']).toEqual('application/json');
- });
-
- it('sends same origin headers', () => {
- expect(fetchMock.lastOptions('/backup-account').credentials).toEqual('same-origin');
- });
-
- it('prevents default call to refresh page', () => {
- expect(preventDefaultSpy).toHaveBeenCalled();
- });
-
it('calls onSubmit from props with success', () => {
expect(mockOnSubmit).toHaveBeenCalledWith('success');
});