Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
import companyAPI, {
|
|
buildCompanyParams,
|
|
buildSearchParams,
|
|
} from '../companies';
|
|
import ApiClient from '../ApiClient';
|
|
|
|
describe('#CompanyAPI', () => {
|
|
it('creates correct instance', () => {
|
|
expect(companyAPI).toBeInstanceOf(ApiClient);
|
|
expect(companyAPI).toHaveProperty('get');
|
|
expect(companyAPI).toHaveProperty('show');
|
|
expect(companyAPI).toHaveProperty('create');
|
|
expect(companyAPI).toHaveProperty('update');
|
|
expect(companyAPI).toHaveProperty('delete');
|
|
expect(companyAPI).toHaveProperty('search');
|
|
});
|
|
|
|
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 with default params', () => {
|
|
companyAPI.get({});
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies?page=1&sort=name'
|
|
);
|
|
});
|
|
|
|
it('#get with page and sort params', () => {
|
|
companyAPI.get({ page: 2, sort: 'domain' });
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies?page=2&sort=domain'
|
|
);
|
|
});
|
|
|
|
it('#get with descending sort', () => {
|
|
companyAPI.get({ page: 1, sort: '-created_at' });
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies?page=1&sort=-created_at'
|
|
);
|
|
});
|
|
|
|
it('#search with query', () => {
|
|
companyAPI.search('acme', 1, 'name');
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies/search?q=acme&page=1&sort=name'
|
|
);
|
|
});
|
|
|
|
it('#search with special characters in query', () => {
|
|
companyAPI.search('acme & co', 2, 'domain');
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies/search?q=acme%20%26%20co&page=2&sort=domain'
|
|
);
|
|
});
|
|
|
|
it('#search with descending sort', () => {
|
|
companyAPI.search('test', 1, '-created_at');
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies/search?q=test&page=1&sort=-created_at'
|
|
);
|
|
});
|
|
|
|
it('#search with empty query', () => {
|
|
companyAPI.search('', 1, 'name');
|
|
expect(axiosMock.get).toHaveBeenCalledWith(
|
|
'/api/v1/companies/search?q=&page=1&sort=name'
|
|
);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#buildCompanyParams', () => {
|
|
it('returns correct string with page only', () => {
|
|
expect(buildCompanyParams(1)).toBe('page=1');
|
|
});
|
|
|
|
it('returns correct string with page and sort', () => {
|
|
expect(buildCompanyParams(1, 'name')).toBe('page=1&sort=name');
|
|
});
|
|
|
|
it('returns correct string with different page', () => {
|
|
expect(buildCompanyParams(3, 'domain')).toBe('page=3&sort=domain');
|
|
});
|
|
|
|
it('returns correct string with descending sort', () => {
|
|
expect(buildCompanyParams(1, '-created_at')).toBe(
|
|
'page=1&sort=-created_at'
|
|
);
|
|
});
|
|
|
|
it('returns correct string without sort parameter', () => {
|
|
expect(buildCompanyParams(2, '')).toBe('page=2');
|
|
});
|
|
});
|
|
|
|
describe('#buildSearchParams', () => {
|
|
it('returns correct string with all parameters', () => {
|
|
expect(buildSearchParams('acme', 1, 'name')).toBe(
|
|
'q=acme&page=1&sort=name'
|
|
);
|
|
});
|
|
|
|
it('returns correct string with special characters', () => {
|
|
expect(buildSearchParams('acme & co', 2, 'domain')).toBe(
|
|
'q=acme%20%26%20co&page=2&sort=domain'
|
|
);
|
|
});
|
|
|
|
it('returns correct string with empty query', () => {
|
|
expect(buildSearchParams('', 1, 'name')).toBe('q=&page=1&sort=name');
|
|
});
|
|
|
|
it('returns correct string without sort parameter', () => {
|
|
expect(buildSearchParams('test', 1, '')).toBe('q=test&page=1');
|
|
});
|
|
|
|
it('returns correct string with descending sort', () => {
|
|
expect(buildSearchParams('company', 3, '-created_at')).toBe(
|
|
'q=company&page=3&sort=-created_at'
|
|
);
|
|
});
|
|
|
|
it('encodes special characters correctly', () => {
|
|
expect(buildSearchParams('test@example.com', 1, 'name')).toBe(
|
|
'q=test%40example.com&page=1&sort=name'
|
|
);
|
|
});
|
|
});
|