Skip to content

Commit

Permalink
Merge pull request #21 from blockydevs/unit_tests_fix
Browse files Browse the repository at this point in the history
fix: unit tests
  • Loading branch information
MWBlocky authored Mar 6, 2024
2 parents 66c090b + 37d5bd4 commit c9e2637
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,29 @@ describe('ReputationOracleGateway', () => {
await expect(service.sendWorkerSignup(command)).resolves.not.toThrow();
expect(httpService.request).toHaveBeenCalled();
});

it('should handle http error response correctly', async () => {
jest.spyOn(httpService, 'request').mockReturnValue(
throwError(() => ({
response: {
data: { message: 'Bad request' },
status: 400,
},
})),
);
jest
.spyOn(httpService, 'request')
.mockReturnValue(
throwError(
() =>
new HttpException(
{ message: 'Bad request' },
HttpStatus.BAD_REQUEST,
),
),
);

const command = new SignupWorkerCommand('', '');
await expect(service.sendWorkerSignup(command)).rejects.toThrow(
new HttpException({ message: 'Bad request' }, 400),
new HttpException({ message: 'Bad request' }, HttpStatus.BAD_REQUEST),
);
});

it('should handle network or unknown errors correctly', async () => {
jest
.spyOn(httpService, 'request')
.mockReturnValue(throwError(() => new Error('Network failure')));
.mockReturnValue(throwError(() => new Error('Internal Server Error')));

const command = new SignupWorkerCommand(
'asfdsafdd@asdf.cvd',
Expand All @@ -96,7 +99,7 @@ describe('ReputationOracleGateway', () => {

await expect(service.sendWorkerSignup(command)).rejects.toThrow(
new HttpException(
'Error occurred while redirecting request.',
'Internal Server Error',
HttpStatus.INTERNAL_SERVER_ERROR,
),
);
Expand Down Expand Up @@ -150,14 +153,17 @@ describe('ReputationOracleGateway', () => {
});

it('should handle http error response correctly', async () => {
jest.spyOn(httpService, 'request').mockReturnValue(
throwError(() => ({
response: {
data: { message: 'Bad request' },
status: 400,
},
})),
);
jest
.spyOn(httpService, 'request')
.mockReturnValue(
throwError(
() =>
new HttpException(
{ message: 'Bad request' },
HttpStatus.BAD_REQUEST,
),
),
);

const command: SigninWorkerCommand = {
email: '',
Expand All @@ -170,7 +176,7 @@ describe('ReputationOracleGateway', () => {
it('should handle network or unknown errors correctly', async () => {
jest
.spyOn(httpService, 'request')
.mockReturnValue(throwError(() => new Error('Network failure')));
.mockReturnValue(throwError(() => new Error('Internal Server Error')));

const command: SigninWorkerCommand = {
email: 'johndoe@example.com',
Expand All @@ -179,7 +185,7 @@ describe('ReputationOracleGateway', () => {

await expect(service.sendWorkerSignin(command)).rejects.toThrow(
new HttpException(
'Error occurred while redirecting request.',
'Internal Server Error',
HttpStatus.INTERNAL_SERVER_ERROR,
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Module } from '@nestjs/common';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { OperatorService } from './operator.service';
import { ReputationOracleModule } from '../../integrations/reputation-oracle/reputation-oracle.module';
import { OperatorProfile } from './operator.mapper';
import { TokenMiddleware } from '../../common/interceptors/auth-token.middleware';
import { OperatorController } from './operator.controller';

@Module({
imports: [ReputationOracleModule],
providers: [OperatorService, OperatorProfile],
exports: [OperatorService],
})
export class OperatorModule {}
export class OperatorModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(TokenMiddleware).forRoutes(OperatorController);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Module } from '@nestjs/common';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { WorkerService } from './worker.service';
import { ReputationOracleModule } from '../../integrations/reputation-oracle/reputation-oracle.module';
import { WorkerProfile } from './worker.mapper';
import { TokenMiddleware } from '../../common/interceptors/auth-token.middleware';
import { WorkerController } from './worker.controller';

@Module({
imports: [ReputationOracleModule],
providers: [WorkerService, WorkerProfile],
exports: [WorkerService],
})
export class WorkerModule {}
export class WorkerModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(TokenMiddleware).forRoutes(WorkerController);
}
}

0 comments on commit c9e2637

Please sign in to comment.