Я относительно новичок в узле и пытаюсь написать модульные тесты для следующего репозитория, который считывает данные из CosmosDb:
import { CosmosClient } from '@azure/cosmos';
export class Repository {
private client: CosmosClient;
constructor() {
this.client = new CosmosClient({ ... })
}
public getData(...someArgs) {
const querySpec = ... //build query here
return this.client.database("databaseId")
.container("containerId")
.items // property returns object of type: Items
.query(querySpec) // method returns object of type: QueryIterator<T>
.fetchAll(); // method returns Promise<FeedResponse<any>>
}
}
В моем модульном тесте я хотел бы чтобы проверить сгенерированное значение querySpe c, переданное методу .query (). До сих пор я пробовал такие вещи, как:
import { Items, QueryIterator, FeedResponse } from '@azure/cosmos';
(...)
//prepare stubs:
const feedResponseStub = new FeedResponse(...);
const qiMock = mock(QueryIterator.prototype);
qiMock.expects("fetchAll").resolves(feedResponseStub);
stub(Items.prototype, "query").returns(qiMock);
// call repository method:
const repository = new Repository();
const result = await repository.getData(...);
Однако я получаю следующую ошибку:
this.client.database(...).container(...).items.query(...).fetchAll is not a function
Также я не уверен, как проверить значение сгенерированного querySpe c.