mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the frontend spec in the folders such as `specs/<domain-name>/getters.spec.js` were not executed in Circle CI. This PR fixes the issue, along with the following changes: - Use vitest instead of jest - Remove jest dependancies - Update tests to work with vitest --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import csatReportsAPI from '../csatReports';
 | 
						|
import ApiClient from '../ApiClient';
 | 
						|
 | 
						|
describe('#Reports API', () => {
 | 
						|
  it('creates correct instance', () => {
 | 
						|
    expect(csatReportsAPI).toBeInstanceOf(ApiClient);
 | 
						|
    expect(csatReportsAPI.apiVersion).toBe('/api/v1');
 | 
						|
    expect(csatReportsAPI).toHaveProperty('get');
 | 
						|
    expect(csatReportsAPI).toHaveProperty('getMetrics');
 | 
						|
  });
 | 
						|
  describe('API calls', () => {
 | 
						|
    const originalAxios = window.axios;
 | 
						|
    const axiosMock = {
 | 
						|
      post: vi.fn(() => Promise.resolve()),
 | 
						|
      get: vi.fn(() => Promise.resolve()),
 | 
						|
      patch: vi.fn(() => Promise.resolve()),
 | 
						|
      delete: vi.fn(() => Promise.resolve()),
 | 
						|
    };
 | 
						|
 | 
						|
    beforeEach(() => {
 | 
						|
      window.axios = axiosMock;
 | 
						|
    });
 | 
						|
 | 
						|
    afterEach(() => {
 | 
						|
      window.axios = originalAxios;
 | 
						|
    });
 | 
						|
 | 
						|
    it('#get', () => {
 | 
						|
      csatReportsAPI.get({ page: 1, from: 1622485800, to: 1623695400 });
 | 
						|
      expect(axiosMock.get).toHaveBeenCalledWith(
 | 
						|
        '/api/v1/csat_survey_responses',
 | 
						|
        {
 | 
						|
          params: {
 | 
						|
            page: 1,
 | 
						|
            since: 1622485800,
 | 
						|
            until: 1623695400,
 | 
						|
            sort: '-created_at',
 | 
						|
          },
 | 
						|
        }
 | 
						|
      );
 | 
						|
    });
 | 
						|
    it('#getMetrics', () => {
 | 
						|
      csatReportsAPI.getMetrics({ from: 1622485800, to: 1623695400 });
 | 
						|
      expect(axiosMock.get).toHaveBeenCalledWith(
 | 
						|
        '/api/v1/csat_survey_responses/metrics',
 | 
						|
        {
 | 
						|
          params: { since: 1622485800, until: 1623695400 },
 | 
						|
        }
 | 
						|
      );
 | 
						|
    });
 | 
						|
    it('#download', () => {
 | 
						|
      csatReportsAPI.download({
 | 
						|
        from: 1622485800,
 | 
						|
        to: 1623695400,
 | 
						|
        user_ids: 1,
 | 
						|
      });
 | 
						|
      expect(axiosMock.get).toHaveBeenCalledWith(
 | 
						|
        '/api/v1/csat_survey_responses/download',
 | 
						|
        {
 | 
						|
          params: {
 | 
						|
            since: 1622485800,
 | 
						|
            until: 1623695400,
 | 
						|
            user_ids: 1,
 | 
						|
            sort: '-created_at',
 | 
						|
          },
 | 
						|
        }
 | 
						|
      );
 | 
						|
    });
 | 
						|
  });
 | 
						|
});
 |