mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 11:00:03 -03:30
Refactor api.js into an api module where endpoint specific models can be imported and used in components.
36 lines
963 B
JavaScript
36 lines
963 B
JavaScript
import Users from '../../src/api/models/Users';
|
|
|
|
describe('UsersAPI', () => {
|
|
const userId = 1;
|
|
const roleId = 7;
|
|
const createPromise = () => Promise.resolve();
|
|
const mockHttp = ({ post: jest.fn(createPromise) });
|
|
|
|
const UsersAPI = new Users(mockHttp);
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
test('associate role calls post with expected params', async (done) => {
|
|
await UsersAPI.associateRole(userId, roleId);
|
|
|
|
expect(mockHttp.post).toHaveBeenCalledTimes(1);
|
|
expect(mockHttp.post.mock.calls[0]).toContainEqual(`/api/v2/users/${userId}/roles/`, { id: roleId });
|
|
|
|
done();
|
|
});
|
|
|
|
test('read users calls post with expected params', async (done) => {
|
|
await UsersAPI.disassociateRole(userId, roleId);
|
|
|
|
expect(mockHttp.post).toHaveBeenCalledTimes(1);
|
|
expect(mockHttp.post.mock.calls[0]).toContainEqual(`/api/v2/users/${userId}/roles/`, {
|
|
id: roleId,
|
|
disassociate: true
|
|
});
|
|
|
|
done();
|
|
});
|
|
});
|