@@ -101,6 +101,7 @@ describe('AssignmentService', () => {
101101 beforeAll ( async ( ) => {
102102 jest . spyOn ( jobRepository , 'createUnique' ) ;
103103 } ) ;
104+
104105 const createAssignmentDto : CreateAssignmentDto = {
105106 chainId,
106107 escrowAddress,
@@ -143,6 +144,36 @@ describe('AssignmentService', () => {
143144 ) ;
144145 } ) ;
145146
147+ it ( 'should reassign user who has previously canceled' , async ( ) => {
148+ jest
149+ . spyOn ( jobRepository , 'findOneByChainIdAndEscrowAddress' )
150+ . mockResolvedValue ( {
151+ id : 1 ,
152+ reputationNetwork : reputationNetwork ,
153+ } as any ) ;
154+ jest
155+ . spyOn ( assignmentRepository , 'findOneByJobIdAndWorker' )
156+ . mockResolvedValue ( { id : 1 , status : AssignmentStatus . CANCELED } as any ) ;
157+
158+ const result = await assignmentService . createAssignment (
159+ createAssignmentDto ,
160+ {
161+ address : workerAddress ,
162+ reputationNetwork : reputationNetwork ,
163+ } as any ,
164+ ) ;
165+
166+ expect ( result ) . toEqual ( undefined ) ;
167+ expect ( assignmentRepository . updateOne ) . toHaveBeenCalledWith ( {
168+ id : 1 ,
169+ status : AssignmentStatus . ACTIVE ,
170+ } ) ;
171+ expect ( jobService . getManifest ) . toHaveBeenCalledWith (
172+ chainId ,
173+ escrowAddress ,
174+ ) ;
175+ } ) ;
176+
146177 it ( 'should fail if escrow address is invalid' , async ( ) => {
147178 jest
148179 . spyOn ( jobRepository , 'findOneByChainIdAndEscrowAddress' )
@@ -183,7 +214,7 @@ describe('AssignmentService', () => {
183214 } as any ) ;
184215 jest
185216 . spyOn ( assignmentRepository , 'findOneByJobIdAndWorker' )
186- . mockResolvedValue ( { id : 1 } as any ) ;
217+ . mockResolvedValue ( { id : 1 , status : AssignmentStatus . REJECTED } as any ) ;
187218
188219 await expect (
189220 assignmentService . createAssignment ( createAssignmentDto , {
0 commit comments