diff options
author | Tulio Casagrande <tuliocasagrande@gmail.com> | 2017-04-04 13:14:34 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 13:14:34 -0300 |
commit | f70c2827d41d1d805d6446670b861b7abf0761b1 (patch) | |
tree | df266fda0c593a27c568215716d48d9994fbd344 /web-ui/src/common/util.spec.js | |
parent | af454c71da106644eee644c4286bbae4788b8e14 (diff) | |
parent | d7914b9b5640c3d85c6230a032180b2e64520bca (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/common/util.spec.js')
-rw-r--r-- | web-ui/src/common/util.spec.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/web-ui/src/common/util.spec.js b/web-ui/src/common/util.spec.js index 805d9dd5..a79859a0 100644 --- a/web-ui/src/common/util.spec.js +++ b/web-ui/src/common/util.spec.js @@ -1,4 +1,7 @@ import expect from 'expect'; +import fetchMock from 'fetch-mock'; + +import browser from 'helpers/browser'; import Util from 'src/common/util'; describe('Utils', () => { @@ -17,4 +20,36 @@ describe('Utils', () => { expect(Util.hasQueryParameter('error')).toBe(false); }); }); + + describe('submitForm', () => { + const event = {}; + + beforeEach(() => { + event.preventDefault = expect.createSpy(); + expect.spyOn(browser, 'getCookie').andReturn('abc123'); + + fetchMock.post('/some-url', 200); + Util.submitForm(event, '/some-url', { userCode: '123' }); + }); + + it('sends csrftoken as content', () => { + expect(fetchMock.lastOptions('/some-url').body).toContain('"csrftoken":["abc123"]'); + }); + + it('sends body as content', () => { + expect(fetchMock.lastOptions('/some-url').body).toContain('"userCode":"123"'); + }); + + it('sends content-type header', () => { + expect(fetchMock.lastOptions('/some-url').headers['Content-Type']).toEqual('application/json'); + }); + + it('sends same origin headers', () => { + expect(fetchMock.lastOptions('/some-url').credentials).toEqual('same-origin'); + }); + + it('prevents default call to refresh page', () => { + expect(event.preventDefault).toHaveBeenCalled(); + }); + }); }); |