11/**
22 * @jest -environment node
33 */
4+
45const { server, } = require ( './server' ) ;
56const axios = require ( 'axios' ) . default ;
67
7-
88describe ( 'Testing the Check Route Module' , ( ) => {
99
1010 test ( 'Sending Request to Existing Route' , ( ) => {
1111
1212 expect . assertions ( 1 ) ;
13- return axios . get ( 'http://localhost:5003/' )
13+ return axios . get ( 'http://localhost:5003/' , {
14+ data : {
15+ testField : 'test_data' ,
16+ } ,
17+ } )
1418 . then ( data => {
1519 const redirectCount = data . request . _redirectable . _redirectCount ;
1620 expect ( redirectCount ) . toBe ( 0 ) ;
@@ -34,6 +38,82 @@ describe('Testing the Check Route Module', () => {
3438
3539} ) ;
3640
41+ describe ( 'Testing the Input Validation Module' , ( ) => {
42+
43+ const request = {
44+ method : '' ,
45+ url : 'http://localhost:5003/' ,
46+ data : {
47+ testField : 'test_data' ,
48+ } ,
49+ } ;
50+
51+ const optRequest = {
52+ method : 'OPTIONS' ,
53+ url : 'http://localhost:5003/' ,
54+ } ;
55+
56+ test ( 'Sending OPTIONS Request' , ( ) => {
57+
58+ expect . assertions ( 1 ) ;
59+ return axios ( optRequest )
60+ . then ( data => {
61+ const stCode = data . status ;
62+ expect ( stCode ) . toBe ( 200 ) ;
63+ } ) ;
64+
65+ } ) ;
66+
67+ test ( 'Sending GET Request' , ( ) => {
68+
69+ request . method = 'GET' ;
70+ expect . assertions ( 1 ) ;
71+ return axios ( request )
72+ . then ( data => {
73+ const resBd = data . data . msg ;
74+ expect ( resBd ) . toBe ( 'test_data' ) ;
75+ } ) ;
76+ } ) ;
77+
78+ test ( 'Sending Empty GET Request' , ( ) => {
79+
80+ request . method = 'GET' ;
81+ request . data = '' ;
82+ expect . assertions ( 1 ) ;
83+ return axios ( request )
84+ . catch ( err => {
85+ const errMsg = err . response . data . msg ;
86+ expect ( errMsg ) . toBe ( 'Some fields are missing!' ) ;
87+ } ) ;
88+ } ) ;
89+
90+ test ( 'Sending POST Request' , ( ) => {
91+
92+ request . method = 'POST' ;
93+ request . data = {
94+ testField : 'test_data' ,
95+ } ;
96+ expect . assertions ( 1 ) ;
97+ return axios ( request )
98+ . then ( data => {
99+ const resBd = data . data . msg ;
100+ expect ( resBd ) . toBe ( 'test_data' ) ;
101+ } ) ;
102+ } ) ;
103+
104+ test ( 'Sending Empty POST Request' , ( ) => {
105+ request . method = 'POST' ;
106+ request . data = '' ;
107+ expect . assertions ( 1 ) ;
108+ return axios ( request )
109+ . catch ( err => {
110+ const errMsg = err . response . data . msg ;
111+ expect ( errMsg ) . toBe ( 'Some fields are missing!' ) ;
112+ } ) ;
113+ } ) ;
114+
115+ } ) ;
116+
37117
38118afterAll ( ( ) => {
39119 server . close ( ) ;
0 commit comments