Commit c3e382b5 authored by Coung Ngo's avatar Coung Ngo Committed by Kushal Pandya

Use GraphQL for Jira importer user mapping member search

This converts the member search from using REST to GraphQL
since we are GraphQL-first.

https://gitlab.com/gitlab-org/gitlab/-/issues/241746
parent 5ff6c862
...@@ -15,10 +15,11 @@ import { ...@@ -15,10 +15,11 @@ import {
GlTable, GlTable,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import axios from '~/lib/utils/axios_utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import getJiraUserMappingMutation from '../queries/get_jira_user_mapping.mutation.graphql'; import getJiraUserMappingMutation from '../queries/get_jira_user_mapping.mutation.graphql';
import initiateJiraImportMutation from '../queries/initiate_jira_import.mutation.graphql'; import initiateJiraImportMutation from '../queries/initiate_jira_import.mutation.graphql';
import searchProjectMembersQuery from '../queries/search_project_members.query.graphql';
import { addInProgressImportToStore } from '../utils/cache_update'; import { addInProgressImportToStore } from '../utils/cache_update';
import { import {
debounceWait, debounceWait,
...@@ -155,19 +156,23 @@ export default { ...@@ -155,19 +156,23 @@ export default {
}); });
}, },
searchUsers() { searchUsers() {
const params = {
active: true,
project_id: this.projectId,
search: this.searchTerm,
};
this.isFetching = true; this.isFetching = true;
return axios return this.$apollo
.get('/-/autocomplete/users.json', { params }) .query({
query: searchProjectMembersQuery,
variables: {
fullPath: this.projectPath,
search: this.searchTerm,
},
})
.then(({ data }) => { .then(({ data }) => {
this.users = data; this.users =
return data; data?.project?.projectMembers?.nodes?.map(({ user }) => ({
...user,
id: getIdFromGraphQLId(user.id),
})) || [];
return this.users;
}) })
.finally(() => { .finally(() => {
this.isFetching = false; this.isFetching = false;
......
query searchProjectMembers($fullPath: ID!, $search: String) {
project(fullPath: $fullPath) {
projectMembers(search: $search) {
nodes {
user {
id
name
username
}
}
}
}
}
import { GlAlert, GlButton, GlDropdown, GlFormSelect, GlLabel, GlTable } from '@gitlab/ui'; import {
GlAlert,
GlButton,
GlDropdown,
GlDropdownItem,
GlFormSelect,
GlLabel,
GlSearchBoxByType,
GlTable,
} from '@gitlab/ui';
import { getByRole } from '@testing-library/dom'; import { getByRole } from '@testing-library/dom';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import AxiosMockAdapter from 'axios-mock-adapter'; import AxiosMockAdapter from 'axios-mock-adapter';
...@@ -6,6 +15,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -6,6 +15,7 @@ import axios from '~/lib/utils/axios_utils';
import JiraImportForm from '~/jira_import/components/jira_import_form.vue'; import JiraImportForm from '~/jira_import/components/jira_import_form.vue';
import getJiraUserMappingMutation from '~/jira_import/queries/get_jira_user_mapping.mutation.graphql'; import getJiraUserMappingMutation from '~/jira_import/queries/get_jira_user_mapping.mutation.graphql';
import initiateJiraImportMutation from '~/jira_import/queries/initiate_jira_import.mutation.graphql'; import initiateJiraImportMutation from '~/jira_import/queries/initiate_jira_import.mutation.graphql';
import searchProjectMembersQuery from '~/jira_import/queries/search_project_members.query.graphql';
import { import {
imports, imports,
issuesPath, issuesPath,
...@@ -19,6 +29,7 @@ import { ...@@ -19,6 +29,7 @@ import {
describe('JiraImportForm', () => { describe('JiraImportForm', () => {
let axiosMock; let axiosMock;
let mutateSpy; let mutateSpy;
let querySpy;
let wrapper; let wrapper;
const currentUsername = 'mrgitlab'; const currentUsername = 'mrgitlab';
...@@ -72,6 +83,7 @@ describe('JiraImportForm', () => { ...@@ -72,6 +83,7 @@ describe('JiraImportForm', () => {
$apollo: { $apollo: {
loading, loading,
mutate, mutate,
query: querySpy,
}, },
}, },
currentUsername, currentUsername,
...@@ -79,19 +91,21 @@ describe('JiraImportForm', () => { ...@@ -79,19 +91,21 @@ describe('JiraImportForm', () => {
beforeEach(() => { beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios); axiosMock = new AxiosMockAdapter(axios);
mutateSpy = jest.fn(() => mutateSpy = jest.fn().mockResolvedValue({
Promise.resolve({ data: {
data: { jiraImportStart: { errors: [] },
jiraImportStart: { errors: [] }, jiraImportUsers: { jiraUsers: [], errors: [] },
jiraImportUsers: { jiraUsers: [], errors: [] }, },
}, });
}), querySpy = jest.fn().mockResolvedValue({
); data: { project: { projectMembers: { nodes: [] } } },
});
}); });
afterEach(() => { afterEach(() => {
axiosMock.restore(); axiosMock.restore();
mutateSpy.mockRestore(); mutateSpy.mockRestore();
querySpy.mockRestore();
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
}); });
...@@ -236,6 +250,53 @@ describe('JiraImportForm', () => { ...@@ -236,6 +250,53 @@ describe('JiraImportForm', () => {
}); });
}); });
describe('member search', () => {
describe('when searching for a member', () => {
beforeEach(() => {
querySpy = jest.fn().mockResolvedValue({
data: {
project: {
projectMembers: {
nodes: [
{
user: {
id: 7,
name: 'Frederic Chopin',
username: 'fchopin',
},
},
],
},
},
},
});
wrapper = mountComponent({ mountFunction: mount });
wrapper.find(GlSearchBoxByType).vm.$emit('input', 'fred');
});
it('makes a GraphQL call', () => {
const queryArgument = {
query: searchProjectMembersQuery,
variables: {
fullPath: projectPath,
search: 'fred',
},
};
expect(querySpy).toHaveBeenCalledWith(expect.objectContaining(queryArgument));
});
it('updates the user list', () => {
expect(getUserDropdown().findAll(GlDropdownItem)).toHaveLength(1);
expect(getUserDropdown().find(GlDropdownItem).text()).toContain(
'fchopin (Frederic Chopin)',
);
});
});
});
describe('buttons', () => { describe('buttons', () => {
describe('"Continue" button', () => { describe('"Continue" button', () => {
it('is shown', () => { it('is shown', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment