const mongoose = require('mongoose');
const { describe, it } = require('mocha');
const { assert, expect } = require('chai');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const proxyGetAIDriver = proxyquire('../../src/lib/cognitive-driver-sdk', {
getAIDriver: sinon.stub(),
});
const AgentSchema = require('../../src/model/mongoose/Agent');
//del const cognitiveDriverSdk = require('../../src/lib/cognitive-driver-sdk');
describe('test', () => {
const agentModel = mongoose.model('Agent', AgentSchema);
it('test-it', async () => {
// -
const fakeSource = {
source: {
getAzureApi() {
console.log('-> getAzureApi()'); //del
},
},
};
const fakeAzureApi = {
getCognitiveServiceSubscriptionData() {
console.log('-> getCognitiveServiceSubscriptionData()'); //del
},
};
const stub1 = sinon.stub(agentModel, 'findByIdOrThrow').returns(Promise.resolve({}));
const stub2 = sinon.stub(agentModel, 'getLuisResource').returns(Promise.resolve(fakeSource));
const stub3 = sinon.stub(fakeSource.source, 'getAzureApi').returns(
Promise.resolve(fakeAzureApi)
);
const stub4 = sinon.stub(fakeAzureApi, 'getCognitiveServiceSubscriptionData').returns(
Promise.resolve({ infoSubscriptionData: {} })
);
const stub5 = sinon.stub(agentModel, 'getAiApiKey').returns(
Promise.resolve({ infoApiKey: {} })
);
const stub6 = sinon.stub(proxyGetAIDriver, 'getAIDriver').returns({ xx: 1 });
// --- test
//del const { queryKey, endpoint } =
await agentModel.assignSubscription(1, {});
// ---
expect(stub1.calledOnce);
expect(stub2.calledOnce);
expect(stub3.calledOnce);
expect(stub4.calledOnce);
expect(stub5.calledOnce);
expect(stub6.calledOnce);
// ---
stub1.restore();
stub2.restore();
stub3.restore();
stub4.restore();
stub5.restore();
stub6.restore();
});
});