Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. const mongoose = require('mongoose');
  2. const { describe, it } = require('mocha');
  3. const { assert, expect } = require('chai');
  4. const proxyquire = require('proxyquire');
  5. const sinon = require('sinon');
  6.  
  7.  
  8. const proxyGetAIDriver = proxyquire('../../src/lib/cognitive-driver-sdk', {
  9. getAIDriver: sinon.stub(),
  10. });
  11.  
  12. const AgentSchema = require('../../src/model/mongoose/Agent');
  13. //del const cognitiveDriverSdk = require('../../src/lib/cognitive-driver-sdk');
  14.  
  15. describe('test', () => {
  16. const agentModel = mongoose.model('Agent', AgentSchema);
  17.  
  18. it('test-it', async () => {
  19. // -
  20. const fakeSource = {
  21. source: {
  22. getAzureApi() {
  23. console.log('-> getAzureApi()'); //del
  24. },
  25. },
  26. };
  27. const fakeAzureApi = {
  28. getCognitiveServiceSubscriptionData() {
  29. console.log('-> getCognitiveServiceSubscriptionData()'); //del
  30. },
  31. };
  32.  
  33. const stub1 = sinon.stub(agentModel, 'findByIdOrThrow').returns(Promise.resolve({}));
  34. const stub2 = sinon.stub(agentModel, 'getLuisResource').returns(Promise.resolve(fakeSource));
  35. const stub3 = sinon.stub(fakeSource.source, 'getAzureApi').returns(
  36. Promise.resolve(fakeAzureApi)
  37. );
  38. const stub4 = sinon.stub(fakeAzureApi, 'getCognitiveServiceSubscriptionData').returns(
  39. Promise.resolve({ infoSubscriptionData: {} })
  40. );
  41. const stub5 = sinon.stub(agentModel, 'getAiApiKey').returns(
  42. Promise.resolve({ infoApiKey: {} })
  43. );
  44. const stub6 = sinon.stub(proxyGetAIDriver, 'getAIDriver').returns({ xx: 1 });
  45.  
  46.  
  47. // --- test
  48.  
  49. //del const { queryKey, endpoint } =
  50. await agentModel.assignSubscription(1, {});
  51.  
  52. // ---
  53.  
  54. expect(stub1.calledOnce);
  55. expect(stub2.calledOnce);
  56. expect(stub3.calledOnce);
  57. expect(stub4.calledOnce);
  58. expect(stub5.calledOnce);
  59. expect(stub6.calledOnce);
  60.  
  61. // ---
  62.  
  63. stub1.restore();
  64. stub2.restore();
  65. stub3.restore();
  66. stub4.restore();
  67. stub5.restore();
  68. stub6.restore();
  69. });
  70.  
  71. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement