@@ -24,6 +24,29 @@ import { NotificationStatus } from '@shared/model/notification.model';
2424import { rest } from 'msw' ;
2525import { applyPagination , extractPagination } from '../pagination.helper' ;
2626import { buildMockInvestigations , getInvestigationById , InvestigationIdPrefix } from './investigations.model' ;
27+ import {
28+ buildMockInvestigations as testBuildMockInvestigations ,
29+ getInvestigationById as testGetInvestigationById ,
30+ InvestigationIdPrefix as testInvestigationIdPrefix ,
31+ } from './investigations.test.model' ;
32+
33+ const commonHandler = [
34+ rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/close` , ( req , res , ctx ) => {
35+ return res ( ctx . status ( 204 ) ) ;
36+ } ) ,
37+
38+ rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/approve` , ( req , res , ctx ) => {
39+ return res ( ctx . status ( 204 ) ) ;
40+ } ) ,
41+
42+ rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/cancel` , ( req , res , ctx ) => {
43+ return res ( ctx . status ( 204 ) ) ;
44+ } ) ,
45+
46+ rest . post ( `${ environment . apiUrl } /investigations/:investigationId/update` , ( req , res , ctx ) => {
47+ return res ( ctx . status ( 204 ) ) ;
48+ } ) ,
49+ ] ;
2750
2851export const investigationsHandlers = [
2952 rest . get ( `*${ environment . apiUrl } /investigations/created` , ( req , res , ctx ) => {
@@ -35,6 +58,8 @@ export const investigationsHandlers = [
3558 NotificationStatus . ACKNOWLEDGED ,
3659 NotificationStatus . ACCEPTED ,
3760 NotificationStatus . DECLINED ,
61+ NotificationStatus . CLOSED ,
62+ NotificationStatus . CANCELED ,
3863 ] ;
3964
4065 return res (
@@ -46,7 +71,14 @@ export const investigationsHandlers = [
4671 rest . get ( `*${ environment . apiUrl } /investigations/received` , ( req , res , ctx ) => {
4772 const pagination = extractPagination ( req ) ;
4873
49- const currentStatus = [ NotificationStatus . RECEIVED , NotificationStatus . ACKNOWLEDGED ] ;
74+ const currentStatus = [
75+ NotificationStatus . RECEIVED ,
76+ NotificationStatus . ACKNOWLEDGED ,
77+ NotificationStatus . ACCEPTED ,
78+ NotificationStatus . DECLINED ,
79+ NotificationStatus . CLOSED ,
80+ NotificationStatus . CANCELED ,
81+ ] ;
5082 return res (
5183 ctx . status ( 200 ) ,
5284 ctx . json ( applyPagination ( buildMockInvestigations ( currentStatus , 'RECEIVER' ) , pagination ) ) ,
@@ -67,14 +99,18 @@ export const investigationsHandlers = [
6799 NotificationStatus . ACKNOWLEDGED ,
68100 NotificationStatus . ACCEPTED ,
69101 NotificationStatus . DECLINED ,
102+
70103 NotificationStatus . ACKNOWLEDGED ,
104+ NotificationStatus . ACCEPTED ,
105+ NotificationStatus . DECLINED ,
106+ NotificationStatus . CLOSED ,
107+ NotificationStatus . CANCELED ,
71108 ] ;
72- const channel = indexFromId === 2 || indexFromId === 8 ? 'RECEIVER' : 'SENDER' ;
109+ const channel = [ 2 , 8 , 9 , 10 , 11 , 12 ] . includes ( indexFromId ) ? 'RECEIVER' : 'SENDER' ;
73110 const randomNotification = buildMockInvestigations ( [ statusCollection [ indexFromId ] ] , channel ) [ 0 ] ;
74111
75112 return res ( ctx . status ( 200 ) , ctx . json ( { ...randomNotification , id : investigationId } ) ) ;
76113 } ) ,
77-
78114 rest . post ( `*${ environment . apiUrl } /investigations` , ( _ , res , ctx ) => {
79115 return res ( ctx . status ( 200 ) , ctx . json ( { id : InvestigationIdPrefix + 1 } ) ) ;
80116 } ) ,
@@ -86,20 +122,68 @@ export const investigationsHandlers = [
86122 const investigation = getInvestigationById ( investigationId as string ) ;
87123 return res ( ctx . status ( 200 ) , ctx . json ( { ...investigation , status } ) ) ;
88124 } ) ,
125+ ...commonHandler ,
126+ ] ;
89127
90- rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/close` , ( req , res , ctx ) => {
91- return res ( ctx . status ( 204 ) ) ;
128+ export const investigationsTestHandlers = [
129+ rest . get ( `*${ environment . apiUrl } /investigations/created` , ( req , res , ctx ) => {
130+ const pagination = extractPagination ( req ) ;
131+
132+ const currentStatus = [
133+ NotificationStatus . CREATED ,
134+ NotificationStatus . APPROVED ,
135+ NotificationStatus . ACKNOWLEDGED ,
136+ NotificationStatus . ACCEPTED ,
137+ NotificationStatus . DECLINED ,
138+ ] ;
139+
140+ return res (
141+ ctx . status ( 200 ) ,
142+ ctx . json ( applyPagination ( testBuildMockInvestigations ( currentStatus , 'SENDER' ) , pagination ) ) ,
143+ ) ;
92144 } ) ,
93145
94- rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/approve` , ( req , res , ctx ) => {
95- return res ( ctx . status ( 204 ) ) ;
146+ rest . get ( `*${ environment . apiUrl } /investigations/received` , ( req , res , ctx ) => {
147+ const pagination = extractPagination ( req ) ;
148+
149+ const currentStatus = [ NotificationStatus . RECEIVED , NotificationStatus . ACKNOWLEDGED ] ;
150+ return res (
151+ ctx . status ( 200 ) ,
152+ ctx . json ( applyPagination ( testBuildMockInvestigations ( currentStatus , 'RECEIVER' ) , pagination ) ) ,
153+ ) ;
96154 } ) ,
97155
98- rest . post ( `*${ environment . apiUrl } /investigations/:investigationId/cancel` , ( req , res , ctx ) => {
99- return res ( ctx . status ( 204 ) ) ;
156+ rest . get ( `*${ environment . apiUrl } /investigations/:investigationId` , ( req , res , ctx ) => {
157+ const { investigationId } = req . params ;
158+
159+ const indexFromId = parseInt ( ( investigationId as string ) . replace ( 'id-' , '' ) , 10 ) ;
160+
161+ const statusCollection = [
162+ NotificationStatus . CREATED ,
163+ NotificationStatus . APPROVED ,
164+ NotificationStatus . RECEIVED ,
165+ NotificationStatus . CLOSED ,
166+ NotificationStatus . CANCELED ,
167+ NotificationStatus . ACKNOWLEDGED ,
168+ NotificationStatus . ACCEPTED ,
169+ NotificationStatus . DECLINED ,
170+ NotificationStatus . ACKNOWLEDGED ,
171+ ] ;
172+ const channel = indexFromId === 2 || indexFromId === 8 ? 'RECEIVER' : 'SENDER' ;
173+ const randomNotification = testBuildMockInvestigations ( [ statusCollection [ indexFromId ] ] , channel ) [ 0 ] ;
174+
175+ return res ( ctx . status ( 200 ) , ctx . json ( { ...randomNotification , id : investigationId } ) ) ;
176+ } ) ,
177+ rest . post ( `*${ environment . apiUrl } /investigations` , ( _ , res , ctx ) => {
178+ return res ( ctx . status ( 200 ) , ctx . json ( { id : testInvestigationIdPrefix + 1 } ) ) ;
100179 } ) ,
101180
102- rest . post ( `${ environment . apiUrl } /investigations/:investigationId/update` , ( req , res , ctx ) => {
103- return res ( ctx . status ( 204 ) ) ;
181+ rest . put ( `*${ environment . apiUrl } /investigations/:investigationId/status` , ( req , res , ctx ) => {
182+ const { investigationId } = req . params ;
183+ const { status } = req . body as Record < string , unknown > ;
184+
185+ const investigation = testGetInvestigationById ( investigationId as string ) ;
186+ return res ( ctx . status ( 200 ) , ctx . json ( { ...investigation , status } ) ) ;
104187 } ) ,
188+ ...commonHandler ,
105189] ;
0 commit comments