From 7be03150100d319c6d373241f614a29b374cb74d Mon Sep 17 00:00:00 2001 From: Anike Arni Date: Thu, 30 Mar 2017 17:23:41 -0300 Subject: [#935] Submits user recovery code to new endpoint with @deniscostadsc --- .../backup_account/backup_email/backup_email.js | 23 +++++----------------- .../backup_email/backup_email.spec.js | 18 ----------------- 2 files changed, 5 insertions(+), 36 deletions(-) (limited to 'web-ui/src/backup_account') 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(); @@ -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'); }); -- cgit v1.2.3