Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

951 B
Raw Blame
import agents from '../agents';
import ApiClient from '../ApiClient';

describe('#AgentAPI', () => {
  it('creates correct instance', () => {
    expect(agents).toBeInstanceOf(ApiClient);
    expect(agents).toHaveProperty('get');
    expect(agents).toHaveProperty('show');
    expect(agents).toHaveProperty('create');
    expect(agents).toHaveProperty('update');
    expect(agents).toHaveProperty('delete');
  });

  describe('API calls', () => {
    const originalAxios = window.axios;
    const axiosMock = {
      post: vi.fn(() => Promise.resolve()),
    };

    beforeEach(() => {
      window.axios = axiosMock;
    });

    afterEach(() => {
      window.axios = originalAxios;
    });

    it('#bulkInvite', () => {
      agents.bulkInvite({ emails: ['[email protected]'] });
      expect(axiosMock.post).toHaveBeenCalledWith(
        '/api/v1/agents/bulk_create',
        {
          emails: ['[email protected]'],
        }
      );
    });
  });
});