mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 21:21:21 -03:30
Refactor api.js into an api module where endpoint specific models can be imported and used in components.
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import Organizations from '../../src/api/models/Organizations';
|
|
|
|
describe('OrganizationsAPI', () => {
|
|
const orgId = 1;
|
|
const searchParams = { foo: 'bar' };
|
|
const createPromise = () => Promise.resolve();
|
|
const mockHttp = ({ get: jest.fn(createPromise) });
|
|
|
|
const OrganizationsAPI = new Organizations(mockHttp);
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
test('read access list calls get with expected params', async (done) => {
|
|
await OrganizationsAPI.readAccessList(orgId);
|
|
await OrganizationsAPI.readAccessList(orgId, searchParams);
|
|
|
|
expect(mockHttp.get).toHaveBeenCalledTimes(2);
|
|
expect(mockHttp.get.mock.calls[0]).toContainEqual(`/api/v2/organizations/${orgId}/access_list/`, { params: {} });
|
|
expect(mockHttp.get.mock.calls[1]).toContainEqual(`/api/v2/organizations/${orgId}/access_list/`, { params: searchParams });
|
|
|
|
done();
|
|
});
|
|
|
|
test('read teams calls get with expected params', async (done) => {
|
|
await OrganizationsAPI.readTeams(orgId);
|
|
await OrganizationsAPI.readTeams(orgId, searchParams);
|
|
|
|
expect(mockHttp.get).toHaveBeenCalledTimes(2);
|
|
expect(mockHttp.get.mock.calls[0]).toContainEqual(`/api/v2/organizations/${orgId}/teams/`, { params: {} });
|
|
expect(mockHttp.get.mock.calls[1]).toContainEqual(`/api/v2/organizations/${orgId}/teams/`, { params: searchParams });
|
|
|
|
done();
|
|
});
|
|
});
|