Skip to content

Commit 6c14738

Browse files
committed
test(recaptcha): add test for verifyRecaptcha request arguments
1 parent 243e34e commit 6c14738

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/recaptcha.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fetch from 'jest-fetch-mock';
2+
import { StitchAdminClientFactory } from '../src/admin';
3+
4+
describe('Recaptcha', () => {
5+
const token = 'my-little-token';
6+
7+
beforeEach(async () => {
8+
global['fetch'] = fetch;
9+
fetch.mockResponseOnce(Promise.resolve());
10+
let adminClient = await StitchAdminClientFactory.create();
11+
await adminClient.verifyRecaptcha(token);
12+
});
13+
14+
afterEach(() => fetch.resetMocks());
15+
16+
it('should be verified with cors enabled', () => {
17+
expect(fetch.mock.calls.length).toEqual(1);
18+
expect(fetch.mock.calls[0][1].cors).toBeTruthy();
19+
});
20+
21+
it('should allow cookies to be sent with the request', () => {
22+
expect(fetch.mock.calls.length).toEqual(1);
23+
expect(fetch.mock.calls[0][1].credentials).toEqual('include');
24+
});
25+
26+
it('should use URLSearchParams to submit token', () => {
27+
expect(fetch.mock.calls.length).toEqual(1);
28+
expect(fetch.mock.calls[0][1].body).toBeInstanceOf(URLSearchParams);
29+
});
30+
31+
it('should let the request determine the Content Type', () => {
32+
expect(fetch.mock.calls.length).toEqual(1);
33+
expect(fetch.mock.calls[0][1].headers['Content-Type']).toBeUndefined();
34+
});
35+
});

0 commit comments

Comments
 (0)