Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { t } from 'i18next';
import type { BottomMenuItem } from '@/components/layout/protected/drawer-navigation';
import { HelpIcon, UserOutlinedIcon } from '@/components/ui/icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { t } from 'i18next';
import type {
BottomMenuItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export function Layout({
</Grid>
<Grid
component="div"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error -- ...
ref={layoutElementRef}
sx={{ height: '100%' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function RegistrationPage() {
<Link
href={oracleData.registrationInstructions ?? ''}
onClick={handleLinkClick}
target="_blank"
rel="noopener"
sx={{ display: 'flex', justifyContent: 'center', width: '100%' }}
target="_blank"
>
{oracleData.registrationInstructions}
</Link>
Expand All @@ -89,10 +89,10 @@ export function RegistrationPage() {
void methods.handleSubmit(handleRegistrationComplete)(event)
}
>
<Stack spacing={2} alignItems="center">
<Stack alignItems="center" spacing={2}>
<FormCaptcha
name="h_captcha_token"
error={userRegistrationError}
name="h_captcha_token"
/>
<Button
disabled={!hasClickedRegistrationLink}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Controller,
Get,
Post,
Put,
Query,
UsePipes,
ValidationPipe,
Expand All @@ -20,6 +21,7 @@ import {
JobsFetchResponse,
ResignJobDto,
ResignJobCommand,
RefreshJobDto,
} from './model/job-assignment.model';
import { Authorization } from '../../common/config/params-decorators';

Expand Down Expand Up @@ -82,4 +84,19 @@ export class JobAssignmentController {
command.token = token;
return this.service.resignJob(command);
}

@Put('/refresh')
@ApiBearerAuth()
@ApiOperation({
summary: 'Request to refresh assigments data',
})
public async refreshAssigments(
@Body() dto: RefreshJobDto,
@Authorization() token: string,
) {
const command = new JobsFetchParamsCommand();
command.oracleAddress = dto.oracle_address;
command.token = token;
return this.service.updateAssignmentsCache(command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export class JobAssignmentService {
): Promise<JobAssignmentResponse> {
const response =
await this.exchangeOracleGateway.postNewJobAssignment(command);

const evmAddress = this.getEvmAddressFromToken(command.token);
const assignmentsParamsCommand = new JobsFetchParamsCommand();
assignmentsParamsCommand.oracleAddress =
await this.escrowUtilsGateway.getExchangeOracleAddressByEscrowAddress(
Expand All @@ -59,7 +57,7 @@ export class JobAssignmentService {
);
assignmentsParamsCommand.token = command.token;

this.updateAssignmentsCache(assignmentsParamsCommand, evmAddress);
this.updateAssignmentsCache(assignmentsParamsCommand);

return response;
}
Expand All @@ -68,12 +66,11 @@ export class JobAssignmentService {
const response =
await this.exchangeOracleGateway.resignAssignedJob(command);

const evmAddress = this.getEvmAddressFromToken(command.token);
const assignmentsParamsCommand = new JobsFetchParamsCommand();
assignmentsParamsCommand.oracleAddress = command.oracleAddress;
assignmentsParamsCommand.token = command.token;

await this.updateAssignmentsCache(assignmentsParamsCommand, evmAddress);
await this.updateAssignmentsCache(assignmentsParamsCommand);

return response;
}
Expand Down Expand Up @@ -136,10 +133,10 @@ export class JobAssignmentService {
});
}

private async updateAssignmentsCache(
public async updateAssignmentsCache(
command: JobsFetchParamsCommand,
evmAddress: string,
): Promise<void> {
const evmAddress = this.getEvmAddressFromToken(command.token);
const cacheRetentionDate = this.getCacheRetentionDate();
const cacheKey = this.makeJobAssignmentCacheKey(
evmAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,10 @@ export class ResignJobData {
@AutoMap()
assignment_id: string;
}

export class RefreshJobDto {
@AutoMap()
@IsString()
@ApiProperty()
oracle_address: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
JobAssignmentDto,
JobsFetchParamsCommand,
JobsFetchParamsDto,
RefreshJobDto,
} from '../model/job-assignment.model';
import {
jobAssignmentDtoFixture,
Expand All @@ -16,6 +17,9 @@ import {
jobsFetchParamsCommandFixture,
jobsFetchResponseFixture,
jobAssignmentToken,
refreshJobDtoFixture,
EXCHANGE_ORACLE_ADDRESS,
TOKEN,
} from './job-assignment.fixtures';
import { AutomapperModule } from '@automapper/nestjs';
import { classes } from '@automapper/classes';
Expand Down Expand Up @@ -93,5 +97,14 @@ describe('JobAssignmentController', () => {
command,
);
});

it('should call service refreshAssigments method with proper fields set', async () => {
const dto: RefreshJobDto = refreshJobDtoFixture;
await controller.refreshAssigments(dto, jobAssignmentToken);
expect(jobAssignmentService.updateAssignmentsCache).toHaveBeenCalledWith({
oracleAddress: EXCHANGE_ORACLE_ADDRESS,
token: TOKEN,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
JobsFetchParamsDto,
JobsFetchResponse,
JobsFetchResponseItem,
RefreshJobDto,
ResignJobCommand,
} from '../model/job-assignment.model';
import {
Expand All @@ -35,7 +36,7 @@ const UPDATED_AT = 'test_date_2';
const EXPIRES_AT = 'test_date_3';
const JOB_ASSIGNMENT_ID = '1';
const URL = 'test_url';
const TOKEN = 'test_user_token';
export const TOKEN = 'test_user_token';
export const USER_ADDRESS = 'test_address';
export const jobAssignmentToken = TOKEN;
export const jobAssignmentOracleUrl = EXCHANGE_ORACLE_URL;
Expand Down Expand Up @@ -141,3 +142,7 @@ export const jobsFetchResponseFixture: JobsFetchResponse = {
total_results: 1,
results: [jobsFetchResponseItemFixture],
};

export const refreshJobDtoFixture: RefreshJobDto = {
oracle_address: EXCHANGE_ORACLE_ADDRESS,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import {
export const jobAssignmentServiceMock = {
processJobAssignment: jest.fn().mockReturnValue(jobAssignmentResponseFixture),
processGetAssignedJobs: jest.fn().mockReturnValue(jobsFetchResponseFixture),
updateAssignmentsCache: jest.fn().mockResolvedValue(undefined),
};
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('JobAssignmentService', () => {
exchangeOracleGatewayMock.fetchAssignedJobs as jest.Mock
).mockResolvedValue({ results: newAssignments });

await service['updateAssignmentsCache'](command, USER_ADDRESS);
await service['updateAssignmentsCache'](command);

expect(cacheManagerMock.get).toHaveBeenCalledWith(cacheKey);
expect(exchangeOracleGatewayMock.fetchAssignedJobs).toHaveBeenCalledWith(
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('JobAssignmentService', () => {

const command = jobsFetchParamsCommandFixture;

await service['updateAssignmentsCache'](command, USER_ADDRESS);
await service['updateAssignmentsCache'](command);

expect(cacheManagerMock.get).toHaveBeenCalledWith(cacheKey);
expect(exchangeOracleGatewayMock.fetchAssignedJobs).toHaveBeenCalledWith(
Expand Down