Skip to content

Commit cd5ff4d

Browse files
authored
[Exchange Oracle] Add test for reassignation (#2585)
Add test for reassignation
1 parent 5745f16 commit cd5ff4d

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

packages/apps/fortune/exchange-oracle/server/src/modules/assignment/assignment.service.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)