forked from shakacode/react_on_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticity.test.js
36 lines (30 loc) · 1.05 KB
/
Authenticity.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ReactOnRails from '../src/ReactOnRails';
const testToken = 'TEST_CSRF_TOKEN';
const meta = document.createElement('meta');
meta.name = 'csrf-token';
meta.content = testToken;
document.head.appendChild(meta);
describe('authenticityToken', () => {
expect.assertions(2);
it('exists in ReactOnRails API', () => {
expect.assertions(1);
expect(typeof ReactOnRails.authenticityToken).toEqual('function');
});
it('can read Rails CSRF token from <meta>', () => {
expect.assertions(1);
const realToken = ReactOnRails.authenticityToken();
expect(realToken).toEqual(testToken);
});
});
describe('authenticityHeaders', () => {
expect.assertions(2);
it('exists in ReactOnRails API', () => {
expect.assertions(1);
expect(typeof ReactOnRails.authenticityHeaders).toEqual('function');
});
it('returns valid header with CSRF token', () => {
expect.assertions(1);
const realHeader = ReactOnRails.authenticityHeaders();
expect(realHeader).toEqual({ 'X-CSRF-Token': testToken, 'X-Requested-With': 'XMLHttpRequest' });
});
});