@@ -3,12 +3,14 @@ import { TrackingService } from "./tracking.service";
33import { HistoryService } from "../history/history.service" ;
44import { NotFoundException } from "@nestjs/common" ;
55import { TargetModel } from "../history/schema/history.schema" ;
6- import {
7- historyServiceMock ,
8- mockHistoryItem ,
9- mockHistoryResponse
6+ import {
7+ historyServiceMock ,
8+ mockHistoryItem ,
9+ mockHistoryResponse
1010} from "../mocks/HistoryMock" ;
1111import { VerificationRequestStatus } from "../verification-request/dto/types" ;
12+ import { VerificationRequestService } from "../verification-request/verification-request.service" ;
13+ import { mockVerificationRequestModel } from "../mocks/VerificationRequestMock" ;
1214
1315describe ( "TrackingService (Unit)" , ( ) => {
1416 let service : TrackingService ;
@@ -22,6 +24,10 @@ describe("TrackingService (Unit)", () => {
2224 provide : HistoryService ,
2325 useValue : historyServiceMock ,
2426 } ,
27+ {
28+ provide : VerificationRequestService ,
29+ useValue : mockVerificationRequestModel ,
30+ } ,
2531 ] ,
2632 } ) . compile ( ) ;
2733
@@ -31,6 +37,11 @@ describe("TrackingService (Unit)", () => {
3137
3238 beforeEach ( ( ) => {
3339 jest . clearAllMocks ( ) ;
40+
41+ mockVerificationRequestModel . getById . mockResolvedValue ( {
42+ id : String ( mockHistoryItem . targetId ) ,
43+ status : VerificationRequestStatus . PRE_TRIAGE ,
44+ } ) ;
3445 } ) ;
3546
3647 describe ( "getTrackingStatus" , ( ) => {
@@ -49,6 +60,7 @@ describe("TrackingService (Unit)", () => {
4960 TargetModel . VerificationRequest ,
5061 expect . objectContaining ( { pageSize : 50 } )
5162 ) ;
63+ expect ( mockVerificationRequestModel . getById ) . toHaveBeenCalledWith ( targetIdStr ) ;
5264 } ) ;
5365
5466 it ( "should filter out events where status did not change" , async ( ) => {
@@ -76,7 +88,7 @@ describe("TrackingService (Unit)", () => {
7688
7789 it ( "should throw NotFoundException and log warning when no history exists" , async ( ) => {
7890 historyService . getHistoryForTarget . mockResolvedValue ( { history : [ ] } ) ;
79-
91+
8092 const loggerWarnSpy = jest . spyOn ( service [ 'logger' ] , 'warn' ) ;
8193
8294 await expect ( service . getTrackingStatus ( targetIdStr ) ) . rejects . toThrow (
@@ -90,7 +102,7 @@ describe("TrackingService (Unit)", () => {
90102 it ( "should throw a generic error and log error when an unexpected failure occurs" , async ( ) => {
91103 const unexpectedError = new Error ( "Database connection lost" ) ;
92104 historyService . getHistoryForTarget . mockRejectedValue ( unexpectedError ) ;
93-
105+
94106 const loggerErrorSpy = jest . spyOn ( service [ 'logger' ] , 'error' ) ;
95107
96108 await expect ( service . getTrackingStatus ( targetIdStr ) ) . rejects . toThrow (
@@ -102,30 +114,16 @@ describe("TrackingService (Unit)", () => {
102114 ) ;
103115 } ) ;
104116
105- it ( "should correctly identify the latestStatus as the last item in the array" , async ( ) => {
106- const multipleHistory = {
107- ...mockHistoryResponse ,
108- history : [
109- {
110- ...mockHistoryItem ,
111- details : { after : { status : VerificationRequestStatus . PRE_TRIAGE } }
112- } ,
113- {
114- ...mockHistoryItem ,
115- _id : "latest-id" ,
116- details : {
117- before : { status : VerificationRequestStatus . PRE_TRIAGE } ,
118- after : { status : VerificationRequestStatus . IN_TRIAGE }
119- }
120- }
121- ] ,
122- } ;
123- historyService . getHistoryForTarget . mockResolvedValue ( multipleHistory ) ;
117+ it ( "should return currentStatus from the verification request regardless of history" , async ( ) => {
118+ historyService . getHistoryForTarget . mockResolvedValue ( mockHistoryResponse ) ;
119+ mockVerificationRequestModel . getById . mockResolvedValue ( {
120+ id : targetIdStr ,
121+ status : VerificationRequestStatus . IN_TRIAGE ,
122+ } ) ;
124123
125124 const result = await service . getTrackingStatus ( targetIdStr ) ;
126125
127126 expect ( result . currentStatus ) . toBe ( VerificationRequestStatus . IN_TRIAGE ) ;
128- expect ( result . historyEvents . at ( - 1 ) ?. status ) . toBe ( VerificationRequestStatus . IN_TRIAGE ) ;
129127 } ) ;
130128 } ) ;
131- } ) ;
129+ } ) ;
0 commit comments