Skip to content

Commit

Permalink
refactor: simplify solowallet api proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacknjama committed Feb 12, 2025
1 parent 162670c commit f8a348a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 103 deletions.
1 change: 0 additions & 1 deletion apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { SmsController } from './sms/sms.controller';
import { SharesController } from './shares/shares.controller';
import { AdminController } from './admin/admin.controller';
import { AdminService } from './admin/admin.service';
import { SolowalletService } from './solowallet/solowallet.service';
import { SolowalletController } from './solowallet/solowallet.controller';
import { AuthService } from './auth/auth.service';
import { AuthController } from './auth/auth.controller';
Expand Down
31 changes: 20 additions & 11 deletions apps/api/src/solowallet/solowallet.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import { TestingModule } from '@nestjs/testing';
import { createTestingModuleWithValidation } from '@bitsacco/testing';
import { SolowalletController } from './solowallet.controller';
import { SolowalletService } from './solowallet.service';
import {
SOLOWALLET_SERVICE_NAME,
SolowalletServiceClient,
} from '@bitsacco/common';
import { type ClientGrpc } from '@nestjs/microservices';

describe('SolowalletController', () => {
let controller: SolowalletController;
let walletService: SolowalletService;
let serviceGenerator: ClientGrpc;
let solowalletController: SolowalletController;
let solowalletServiceClient: Partial<SolowalletServiceClient>;

beforeEach(async () => {
serviceGenerator = {
getService: jest.fn().mockReturnValue(solowalletServiceClient),
getClientByServiceName: jest
.fn()
.mockReturnValue(solowalletServiceClient),
};

const module: TestingModule = await createTestingModuleWithValidation({
controllers: [SolowalletController],
providers: [
{
provide: SolowalletService,
useValue: {
depositFunds: jest.fn(),
},
provide: SOLOWALLET_SERVICE_NAME,
useValue: serviceGenerator,
},
],
});

controller = module.get<SolowalletController>(SolowalletController);
walletService = module.get<SolowalletService>(SolowalletService);
solowalletController =
module.get<SolowalletController>(SolowalletController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
expect(walletService).toBeDefined();
expect(solowalletController).toBeDefined();
});
});
23 changes: 20 additions & 3 deletions apps/api/src/solowallet/solowallet.controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import {
ContinueTxRequestDto,
DepositFundsRequestDto,
SOLOWALLET_SERVICE_NAME,
SolowalletServiceClient,
UpdateTxDto,
UserTxsRequestDto,
WithdrawFundsRequestDto,
} from '@bitsacco/common';
import { Body, Controller, Get, Logger, Param, Post } from '@nestjs/common';
import {
Body,
Controller,
Get,
Inject,
Logger,
Param,
Post,
} from '@nestjs/common';
import { ApiOperation, ApiBody, ApiParam } from '@nestjs/swagger';
import { SolowalletService } from './solowallet.service';
import { type ClientGrpc } from '@nestjs/microservices';

@Controller('solowallet')
export class SolowalletController {
private walletService: SolowalletServiceClient;
private readonly logger = new Logger(SolowalletController.name);

constructor(private readonly walletService: SolowalletService) {
constructor(
@Inject(SOLOWALLET_SERVICE_NAME)
private readonly grpc: ClientGrpc,
) {
this.walletService = this.grpc.getService<SolowalletServiceClient>(
SOLOWALLET_SERVICE_NAME,
);
this.logger.log('SolowalletController initialized');
}

Expand Down
37 changes: 0 additions & 37 deletions apps/api/src/solowallet/solowallet.service.spec.ts

This file was deleted.

51 changes: 0 additions & 51 deletions apps/api/src/solowallet/solowallet.service.ts

This file was deleted.

0 comments on commit f8a348a

Please sign in to comment.