Not able to compile unit test setup
Basically I have following setup for test:
import { Test, TestingModule } from '@nestjs/testing';
import { BlockchainModule } from '../blockchain/blockchain.module';
import { BlockchainService } from '../blockchain/blockchain.service';
import { FaucetModule } from '../faucet/faucet.module';
import { FaucetService } from '../faucet/faucet.service';
import { UserController } from './user.controller';
import { UserService } from './user.service';
describe('UserController', () => {
let controller: UserController;
let userService: UserService;
let faucetService: FaucetService;
let blockchainService: BlockchainService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [BlockchainModule, FaucetModule],
controllers: [UserController],
providers: [UserService, FaucetService, BlockchainService],
}).compile();
controller = module.get<UserController>(UserController);
userService = module.get<UserService>(UserService);
faucetService = module.get<FaucetService>(FaucetService);
blockchainService = module.get<BlockchainService>(BlockchainService);
});
// it('should be defined', () => {
// expect(controller).toBeDefined();
// });
});
And throws following error: Cannot find module 'src/config/app.config' from 'modules/blockchain/blockchain.service.ts' This is how AppConfig is imported in blockchain service:
blockchain.service.ts:
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { Wallet, providers, utils, Overrides } from 'ethers';
import { AppConfig } from 'src/config/app.config';
import { OpnCash } from './contract/OpnCash';
import { OpnCashFactory } from './contract/OpnCashFactory';
import { Erc20Factory } from './contract/Erc20Factory';
@Injectable()
export class BlockchainService {
private contract: OpnCash;
private provider: providers.BaseProvider;
constructor() {
this.contract = new OpnCashFactory().attach(AppConfig.blockchain.contract);
this.provider = new providers.JsonRpcProvider(AppConfig.blockchain.rpcUrl, AppConfig.blockchain.chainId);
}
async sendTransaction(from: string, to: string, amount: number, options?: Overrides) {
try {
this.contract = this.contract.connect(new Wallet(from, this.provider));
const tx = await this.contract.transfer(to, utils.parseEther(String(amount)), { ...options, gasPrice: 0 });
const result = await tx.wait();
return result.transactionHash;
} catch (err) {
if (err.code === 'UNPREDICTABLE_GAS_LIMIT') {
throw new HttpException('Unsufficient amount.', HttpStatus.BAD_REQUEST);
}
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
My question is how to resolve this issue so the test case have access to AppConfig