-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgoogle-recaptcha-exception.spec.ts
76 lines (62 loc) · 2.99 KB
/
google-recaptcha-exception.spec.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { ErrorCode, GoogleRecaptchaException } from '../src';
import { HttpStatus } from '@nestjs/common';
describe('Google recaptcha exception', () => {
test('Test error code InvalidInputResponse', () => {
const exception = new GoogleRecaptchaException([ErrorCode.InvalidInputResponse]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code MissingInputResponse', () => {
const exception = new GoogleRecaptchaException([ErrorCode.MissingInputResponse]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code TimeoutOrDuplicate', () => {
const exception = new GoogleRecaptchaException([ErrorCode.TimeoutOrDuplicate]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code InvalidKeys', () => {
const exception = new GoogleRecaptchaException([ErrorCode.InvalidKeys]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code InvalidInputSecret', () => {
const exception = new GoogleRecaptchaException([ErrorCode.InvalidInputSecret]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test error code MissingInputSecret', () => {
const exception = new GoogleRecaptchaException([ErrorCode.MissingInputSecret]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test error code BadRequest', () => {
const exception = new GoogleRecaptchaException([ErrorCode.BadRequest]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test error code SiteMismatch', () => {
const exception = new GoogleRecaptchaException([ErrorCode.SiteMismatch]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code BrowserError', () => {
const exception = new GoogleRecaptchaException([ErrorCode.BrowserError]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code IncorrectCaptchaSol', () => {
const exception = new GoogleRecaptchaException([ErrorCode.IncorrectCaptchaSol]);
expect(exception.getStatus()).toBe(HttpStatus.BAD_REQUEST);
});
test('Test error code UnknownError', () => {
const exception = new GoogleRecaptchaException([ErrorCode.UnknownError]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test unexpected error code', () => {
const exception = new GoogleRecaptchaException(['UnexpectedErrorCode' as ErrorCode]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test network error code', () => {
const exception = new GoogleRecaptchaException([ErrorCode.NetworkError]);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
});
test('Test network error with custom message', () => {
const message = 'TEST_MSG';
const exception = new GoogleRecaptchaException([ErrorCode.NetworkError], message);
expect(exception.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
expect(exception.message).toBe(message);
});
});