Это служба, которую я ошарашиваю
class TransactionService {
async getTransactions(
req: RequestContract,
query: TransactionQuery
): Promise<Transaction[]> {
const token = await Auth.headless({ nuban: query.nuban });
const iris = new Iris({ req, token, headless: true, retries: 1 });
return iris.get<Transaction[]>(`${env.proxy_url}/transactions/`, {
params: query
});
}
filterTransaction(req: Request, transactions: Transaction[]): Transaction[] {
const accounts = req.session.accounts.map(account => account.acccount_number);
return transactions.filter(transaction => accounts.includes(transaction.nuban));
}
}
export const TransactionsService = new TransactionService();
Вот мой метод заглушки
export function mockGetTransactions() {
sinon.stub(TransactionsService, 'getTransactions').resolves(mockTransactions('0071326981'))
}
Наконец, вот фиктивные данные
export function mockTransactions(account: string) {
return {
date: faker.date.recent(3),
transaction_type: 'credit',
amount: mockAmount(10000, 1000000, 4),
remark: faker.random.words(10),
reference: faker.random.words(5),
nuban: account,
};
}
Это ошибка, которую я получаю
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
__tests__/mocks/services/transaction.ts:6:65 - error TS2345: Argument of type '{ date: Date; transaction_type: string; amount: number; remark: string; reference: string; nuban: string; }' is not assignable to parameter of type 'Transaction[]'.
Type '{ date: Date; transaction_type: string; amount: number; remark: string; reference: string; nuban: string; }' is missing the following properties from type 'Transaction[]': length, pop, push, concat, and 26 more.
6 sinon.stub(TransactionsService, 'getTransactions').resolves(mockTransactions('0071326981'))
Итак, getTransactions
ожидает транзакцию [] ie массив транзакций, в то время как я передаю объект с mockTransactions