readme.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { EmbedChainApp } from '../embedchain';
  2. const mockAdd = jest.fn();
  3. const mockAddLocal = jest.fn();
  4. const mockQuery = jest.fn();
  5. jest.mock('../embedchain', () => {
  6. return {
  7. EmbedChainApp: jest.fn().mockImplementation(() => {
  8. return {
  9. add: mockAdd,
  10. addLocal: mockAddLocal,
  11. query: mockQuery,
  12. };
  13. }),
  14. };
  15. });
  16. describe('Test App', () => {
  17. beforeEach(() => {
  18. jest.clearAllMocks();
  19. });
  20. it('tests the App', async () => {
  21. mockQuery.mockResolvedValue(
  22. 'Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.'
  23. );
  24. const navalChatBot = await new EmbedChainApp(undefined, false);
  25. // Embed Online Resources
  26. await navalChatBot.add('web_page', 'https://nav.al/feedback');
  27. await navalChatBot.add('web_page', 'https://nav.al/agi');
  28. await navalChatBot.add(
  29. 'pdf_file',
  30. 'https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf'
  31. );
  32. // Embed Local Resources
  33. await navalChatBot.addLocal('qna_pair', [
  34. 'Who is Naval Ravikant?',
  35. 'Naval Ravikant is an Indian-American entrepreneur and investor.',
  36. ]);
  37. const result = await navalChatBot.query(
  38. 'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
  39. );
  40. expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/feedback');
  41. expect(mockAdd).toHaveBeenCalledWith('web_page', 'https://nav.al/agi');
  42. expect(mockAdd).toHaveBeenCalledWith(
  43. 'pdf_file',
  44. 'https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf'
  45. );
  46. expect(mockAddLocal).toHaveBeenCalledWith('qna_pair', [
  47. 'Who is Naval Ravikant?',
  48. 'Naval Ravikant is an Indian-American entrepreneur and investor.',
  49. ]);
  50. expect(mockQuery).toHaveBeenCalledWith(
  51. 'What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?'
  52. );
  53. expect(result).toBe(
  54. 'Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.'
  55. );
  56. });
  57. });