Skip to content

Commit

Permalink
refactor: simplify shares api proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Feb 12, 2025
1 parent b73f768 commit 162670c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 112 deletions.
2 changes: 0 additions & 2 deletions apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { SwapController, SwapService } from './swap';
import { NostrController, NostrService } from './nostr';
import { SmsService } from './sms/sms.service';
import { SmsController } from './sms/sms.controller';
import { SharesService } from './shares/shares.service';
import { SharesController } from './shares/shares.controller';
import { AdminController } from './admin/admin.controller';
import { AdminService } from './admin/admin.service';
Expand Down Expand Up @@ -180,7 +179,6 @@ import { ChamasController } from './chamas/chamas.controller';
SwapService,
NostrService,
SmsService,
SharesService,
SolowalletService,
AdminService,
PhoneAuthStategy,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/chamas/chamas.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestingModule } from '@nestjs/testing';
import { CHAMAS_SERVICE_NAME, ChamasServiceClient } from '@bitsacco/common';
import { createTestingModuleWithValidation } from '@bitsacco/testing';
import { ChamasController } from './chamas.controller';
import { type ClientGrpc } from '@nestjs/microservices';
import { ChamasController } from './chamas.controller';

describe('ChamasController', () => {
let serviceGenerator: ClientGrpc;
Expand Down
26 changes: 14 additions & 12 deletions apps/api/src/shares/shares.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { TestingModule } from '@nestjs/testing';
import { SHARES_SERVICE_NAME, SharesServiceClient } from '@bitsacco/common';
import { createTestingModuleWithValidation } from '@bitsacco/testing';

import { type ClientGrpc } from '@nestjs/microservices';
import { SharesController } from './shares.controller';
import { SharesService } from './shares.service';

describe.skip('SharesController', () => {
let controller: SharesController;
let sharesService: SharesService;
let serviceGenerator: ClientGrpc;
let sharesController: SharesController;
let sharesServiceClient: Partial<SharesServiceClient>;

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

const module: TestingModule = await createTestingModuleWithValidation({
controllers: [SharesController],
providers: [
{
provide: SharesService,
useValue: {
buyShares: jest.fn(),
},
provide: SHARES_SERVICE_NAME,
useValue: serviceGenerator,
},
],
});

controller = module.get<SharesController>(SharesController);
sharesService = module.get<SharesService>(SharesService);
sharesController = module.get<SharesController>(SharesController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
expect(sharesService).toBeDefined();
expect(sharesController).toBeDefined();
});
});
11 changes: 8 additions & 3 deletions apps/api/src/shares/shares.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
default_page,
default_page_size,
ListSwapsDto,
OfferSharesDto,
PaginatedRequestDto,
SHARES_SERVICE_NAME,
SharesServiceClient,
SubscribeSharesDto,
TransferSharesDto,
UpdateSharesDto,
Expand All @@ -12,19 +13,23 @@ import {
Body,
Controller,
Get,
Inject,
Logger,
Param,
Post,
Query,
} from '@nestjs/common';
import { ApiOperation, ApiBody, ApiParam, ApiQuery } from '@nestjs/swagger';
import { SharesService } from './shares.service';
import { type ClientGrpc } from '@nestjs/microservices';

@Controller('shares')
export class SharesController {
private sharesService: SharesServiceClient;
private readonly logger = new Logger(SharesController.name);

constructor(private readonly sharesService: SharesService) {
constructor(@Inject(SHARES_SERVICE_NAME) private readonly grpc: ClientGrpc) {
this.sharesService =
this.grpc.getService<SharesServiceClient>(SHARES_SERVICE_NAME);
this.logger.log('SharesController initialized');
}

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

This file was deleted.

57 changes: 0 additions & 57 deletions apps/api/src/shares/shares.service.ts

This file was deleted.

0 comments on commit 162670c

Please sign in to comment.