diff options
Diffstat (limited to 'spec/frontend/api')
-rw-r--r-- | spec/frontend/api/groups_api_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/api/harbor_registry_spec.js | 8 | ||||
-rw-r--r-- | spec/frontend/api/packages_api_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/api/tags_api_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/api/user_api_spec.js | 35 |
5 files changed, 43 insertions, 12 deletions
diff --git a/spec/frontend/api/groups_api_spec.js b/spec/frontend/api/groups_api_spec.js index 9de588a02aa..c354d8a9416 100644 --- a/spec/frontend/api/groups_api_spec.js +++ b/spec/frontend/api/groups_api_spec.js @@ -1,6 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import getGroupTransferLocationsResponse from 'test_fixtures/api/groups/transfer_locations.json'; -import httpStatus from '~/lib/utils/http_status'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import axios from '~/lib/utils/axios_utils'; import { DEFAULT_PER_PAGE } from '~/api'; import { updateGroup, getGroupTransferLocations } from '~/api/groups_api'; @@ -35,7 +35,7 @@ describe('GroupsApi', () => { beforeEach(() => { mock.onPut(expectedUrl).reply(({ data }) => { - return [httpStatus.OK, { id: mockGroupId, ...JSON.parse(data) }]; + return [HTTP_STATUS_OK, { id: mockGroupId, ...JSON.parse(data) }]; }); }); diff --git a/spec/frontend/api/harbor_registry_spec.js b/spec/frontend/api/harbor_registry_spec.js index 8a4c377ebd1..db4b189835e 100644 --- a/spec/frontend/api/harbor_registry_spec.js +++ b/spec/frontend/api/harbor_registry_spec.js @@ -1,7 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import * as harborRegistryApi from '~/api/harbor_registry'; import axios from '~/lib/utils/axios_utils'; -import httpStatus from '~/lib/utils/http_status'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; describe('~/api/harbor_registry', () => { let mock; @@ -37,7 +37,7 @@ describe('~/api/harbor_registry', () => { location: 'http://demo.harbor.com/harbor/projects/2/repositories/image-1', }, ]; - mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse); + mock.onGet(expectedUrl).reply(HTTP_STATUS_OK, expectResponse); return harborRegistryApi.getHarborRepositoriesList(expectedParams).then(({ data }) => { expect(data).toEqual(expectResponse); @@ -66,7 +66,7 @@ describe('~/api/harbor_registry', () => { tags: ['v2', 'v1', 'latest'], }, ]; - mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse); + mock.onGet(expectedUrl).reply(HTTP_STATUS_OK, expectResponse); return harborRegistryApi.getHarborArtifacts(expectedParams).then(({ data }) => { expect(data).toEqual(expectResponse); @@ -97,7 +97,7 @@ describe('~/api/harbor_registry', () => { immutable: false, }, ]; - mock.onGet(expectedUrl).reply(httpStatus.OK, expectResponse); + mock.onGet(expectedUrl).reply(HTTP_STATUS_OK, expectResponse); return harborRegistryApi.getHarborTags(expectedParams).then(({ data }) => { expect(data).toEqual(expectResponse); diff --git a/spec/frontend/api/packages_api_spec.js b/spec/frontend/api/packages_api_spec.js index d55d2036dcf..5f517bcf358 100644 --- a/spec/frontend/api/packages_api_spec.js +++ b/spec/frontend/api/packages_api_spec.js @@ -1,7 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import { publishPackage } from '~/api/packages_api'; import axios from '~/lib/utils/axios_utils'; -import httpStatus from '~/lib/utils/http_status'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; describe('Api', () => { const dummyApiVersion = 'v3000'; @@ -35,7 +35,7 @@ describe('Api', () => { const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/packages/generic/${name}/${packageVersion}/${name}`; jest.spyOn(axios, 'put'); - mock.onPut(expectedUrl).replyOnce(httpStatus.OK, apiResponse); + mock.onPut(expectedUrl).replyOnce(HTTP_STATUS_OK, apiResponse); return publishPackage( { diff --git a/spec/frontend/api/tags_api_spec.js b/spec/frontend/api/tags_api_spec.js index a7436bf6a50..af3533f52b7 100644 --- a/spec/frontend/api/tags_api_spec.js +++ b/spec/frontend/api/tags_api_spec.js @@ -1,7 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import * as tagsApi from '~/api/tags_api'; import axios from '~/lib/utils/axios_utils'; -import httpStatus from '~/lib/utils/http_status'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; describe('~/api/tags_api.js', () => { let mock; @@ -25,7 +25,7 @@ describe('~/api/tags_api.js', () => { it('fetches a tag of a given tag name of a particular project', () => { const tagName = 'tag-name'; const expectedUrl = `/api/v7/projects/${projectId}/repository/tags/${tagName}`; - mock.onGet(expectedUrl).reply(httpStatus.OK, { + mock.onGet(expectedUrl).reply(HTTP_STATUS_OK, { name: tagName, }); diff --git a/spec/frontend/api/user_api_spec.js b/spec/frontend/api/user_api_spec.js index ba6b73e8c1a..9e901cf0f71 100644 --- a/spec/frontend/api/user_api_spec.js +++ b/spec/frontend/api/user_api_spec.js @@ -1,8 +1,13 @@ import MockAdapter from 'axios-mock-adapter'; -import { followUser, unfollowUser, associationsCount } from '~/api/user_api'; +import { followUser, unfollowUser, associationsCount, updateUserStatus } from '~/api/user_api'; import axios from '~/lib/utils/axios_utils'; -import { associationsCount as associationsCountData } from 'jest/admin/users/mock_data'; +import { + associationsCount as associationsCountData, + userStatus as mockUserStatus, +} from 'jest/admin/users/mock_data'; +import { AVAILABILITY_STATUS } from '~/set_status_modal/constants'; +import { timeRanges } from '~/vue_shared/constants'; describe('~/api/user_api', () => { let axiosMock; @@ -62,4 +67,30 @@ describe('~/api/user_api', () => { expect(axiosMock.history.get[0].url).toBe(expectedUrl); }); }); + + describe('updateUserStatus', () => { + it('calls correct URL and returns expected response', async () => { + const expectedUrl = '/api/v4/user/status'; + const expectedData = { + emoji: 'basketball', + message: 'test', + availability: AVAILABILITY_STATUS.BUSY, + clear_status_after: timeRanges[0].shortcut, + }; + const expectedResponse = { data: mockUserStatus }; + + axiosMock.onPatch(expectedUrl).replyOnce(200, expectedResponse); + + await expect( + updateUserStatus({ + emoji: 'basketball', + message: 'test', + availability: AVAILABILITY_STATUS.BUSY, + clearStatusAfter: timeRanges[0].shortcut, + }), + ).resolves.toEqual(expect.objectContaining({ data: expectedResponse })); + expect(axiosMock.history.patch[0].url).toBe(expectedUrl); + expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual(expectedData); + }); + }); }); |