Commit 1eb4b94e authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'add-user-lists-to-frontend-api' into 'master'

Make Feature Flag User List API Available in FE

See merge request gitlab-org/gitlab!30740
parents c384c077 46608684
......@@ -35,6 +35,8 @@ export default {
paymentMethodPath: '/-/subscriptions/payment_method',
confirmOrderPath: '/-/subscriptions',
vulnerabilitiesActionPath: '/api/:version/vulnerabilities/:id/:action',
featureFlagUserLists: '/api/:version/projects/:id/feature_flags_user_lists',
featureFlagUserList: '/api/:version/projects/:id/feature_flags_user_lists/:list_iid',
userSubscription(namespaceId) {
const url = Api.buildUrl(this.subscriptionPath).replace(':id', encodeURIComponent(namespaceId));
......@@ -298,4 +300,47 @@ export default {
const url = Api.buildUrl(this.geoNodesPath);
return axios.put(`${url}/${node.id}`, node);
},
fetchFeatureFlagUserLists(version, id) {
const url = Api.buildUrl(this.featureFlagUserLists)
.replace(':version', version)
.replace(':id', id);
return axios.get(url);
},
createFeatureFlagUserList(version, id, list) {
const url = Api.buildUrl(this.featureFlagUserLists)
.replace(':version', version)
.replace(':id', id);
return axios.post(url, list);
},
fetchFeatureFlagUserList(version, id, listIid) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':version', version)
.replace(':id', id)
.replace(':list_iid', listIid);
return axios.get(url);
},
updateFeatureFlagUserList(version, id, list) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':version', version)
.replace(':id', id)
.replace(':list_iid', list.iid);
return axios.put(url, list);
},
deleteFeatureFlagUserList(version, id, listIid) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':version', version)
.replace(':id', id)
.replace(':list_iid', listIid);
return axios.delete(url);
},
};
......@@ -740,4 +740,81 @@ describe('Api', () => {
});
});
});
describe('Feature Flag User List', () => {
let expectedUrl;
let projectId;
let mockUserList;
beforeEach(() => {
projectId = 1000;
expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/feature_flags_user_lists`;
mockUserList = {
name: 'mock_user_list',
user_xids: '1,2,3,4',
project_id: 1,
id: 1,
iid: 1,
};
});
describe('fetchFeatureFlagUserLists', () => {
it('GETs the right url', () => {
mock.onGet(expectedUrl).replyOnce(200, []);
return Api.fetchFeatureFlagUserLists(dummyApiVersion, projectId).then(({ data }) => {
expect(data).toEqual([]);
});
});
});
describe('createFeatureFlagUserList', () => {
it('POSTs data to the right url', () => {
const mockUserListData = {
name: 'mock_user_list',
user_xids: '1,2,3,4',
};
mock.onPost(expectedUrl, mockUserListData).replyOnce(200, mockUserList);
return Api.createFeatureFlagUserList(dummyApiVersion, projectId, mockUserListData).then(
({ data }) => {
expect(data).toEqual(mockUserList);
},
);
});
});
describe('fetchFeatureFlagUserList', () => {
it('GETs the right url', () => {
mock.onGet(`${expectedUrl}/1`).replyOnce(200, mockUserList);
return Api.fetchFeatureFlagUserList(dummyApiVersion, projectId, 1).then(({ data }) => {
expect(data).toEqual(mockUserList);
});
});
});
describe('updateFeatureFlagUserList', () => {
it('PUTs the right url', () => {
mock.onPut(`${expectedUrl}/1`).replyOnce(200, { ...mockUserList, user_xids: '5' });
return Api.updateFeatureFlagUserList(dummyApiVersion, projectId, {
...mockUserList,
user_xids: '5',
}).then(({ data }) => {
expect(data).toEqual({ ...mockUserList, user_xids: '5' });
});
});
});
describe('deleteFeatureFlagUserList', () => {
it('DELETEs the right url', () => {
mock.onDelete(`${expectedUrl}/1`).replyOnce(200, 'deleted');
return Api.deleteFeatureFlagUserList(dummyApiVersion, projectId, 1).then(({ data }) => {
expect(data).toBe('deleted');
});
});
});
});
});
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