UNPKG

@humanlayer/sdk

Version:

typescript client for humanlayer.dev

178 lines (177 loc) 4.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const approval_1 = require("./approval"); test('HumanLayer()#humanAsTool()', async () => { const mockBackend = { functions: jest.fn(), contacts: jest.fn(), }; const contacts = { add: jest.fn(), get: jest.fn(), }; mockBackend.contacts.mockReturnValue(contacts); contacts.add.mockReturnValue({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', }, }); const returnValue = { run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', }, status: { response: '5309', }, }; contacts.get.mockReturnValue(returnValue); const hl = new approval_1.HumanLayer({ backend: mockBackend, sleep: (x) => Promise.resolve(), genid: (x) => 'generated-id', }); const tool = hl.humanAsTool(); const resp = await tool({ message: '867' }); expect(resp).toBe('5309'); expect(contacts.add).toHaveBeenCalledWith({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', }, }); expect(contacts.get).toHaveBeenCalledWith('generated-id'); }); test('HumanLayer(ContactChannel)#humanAsTool()', async () => { const mockBackend = { functions: jest.fn(), contacts: jest.fn(), }; const contacts = { add: jest.fn(), get: jest.fn(), }; mockBackend.contacts.mockReturnValue(contacts); contacts.add.mockReturnValue({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, }); const returnValue = { run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, status: { response: '5309', }, }; contacts.get.mockReturnValue(returnValue); const hl = new approval_1.HumanLayer({ backend: mockBackend, sleep: (x) => Promise.resolve(), genid: (x) => 'generated-id', contactChannel: { slack: { channel_or_user_id: 'test-channel', }, }, }); const tool = hl.humanAsTool(); const resp = await tool({ message: '867' }); expect(resp).toBe('5309'); expect(contacts.add).toHaveBeenCalledWith({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, }); expect(contacts.get).toHaveBeenCalledWith('generated-id'); }); test('HumanLayer()#humanAsTool(ContactChannel)', async () => { const mockBackend = { functions: jest.fn(), contacts: jest.fn(), }; const contacts = { add: jest.fn(), get: jest.fn(), }; mockBackend.contacts.mockReturnValue(contacts); contacts.add.mockReturnValue({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, }); const returnValue = { run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, status: { response: '5309', }, }; contacts.get.mockReturnValue(returnValue); const hl = new approval_1.HumanLayer({ backend: mockBackend, sleep: (x) => Promise.resolve(), genid: (x) => 'generated-id', }); const tool = hl.humanAsTool({ slack: { channel_or_user_id: 'test-channel', }, }); const resp = await tool({ message: '867' }); expect(resp).toBe('5309'); expect(contacts.add).toHaveBeenCalledWith({ run_id: 'generated-id', call_id: 'generated-id', spec: { msg: '867', channel: { slack: { channel_or_user_id: 'test-channel', }, }, }, }); expect(contacts.get).toHaveBeenCalledWith('generated-id'); });