diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/api/user_api_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/api/user_api_spec.js')
-rw-r--r-- | spec/frontend/api/user_api_spec.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/frontend/api/user_api_spec.js b/spec/frontend/api/user_api_spec.js new file mode 100644 index 00000000000..ee7194bdf5f --- /dev/null +++ b/spec/frontend/api/user_api_spec.js @@ -0,0 +1,50 @@ +import MockAdapter from 'axios-mock-adapter'; + +import { followUser, unfollowUser } from '~/api/user_api'; +import axios from '~/lib/utils/axios_utils'; + +describe('~/api/user_api', () => { + let axiosMock; + let originalGon; + + beforeEach(() => { + axiosMock = new MockAdapter(axios); + + originalGon = window.gon; + window.gon = { api_version: 'v4' }; + }); + + afterEach(() => { + axiosMock.restore(); + axiosMock.resetHistory(); + window.gon = originalGon; + }); + + describe('followUser', () => { + it('calls correct URL and returns expected response', async () => { + const expectedUrl = '/api/v4/users/1/follow'; + const expectedResponse = { message: 'Success' }; + + axiosMock.onPost(expectedUrl).replyOnce(200, expectedResponse); + + await expect(followUser(1)).resolves.toEqual( + expect.objectContaining({ data: expectedResponse }), + ); + expect(axiosMock.history.post[0].url).toBe(expectedUrl); + }); + }); + + describe('unfollowUser', () => { + it('calls correct URL and returns expected response', async () => { + const expectedUrl = '/api/v4/users/1/unfollow'; + const expectedResponse = { message: 'Success' }; + + axiosMock.onPost(expectedUrl).replyOnce(200, expectedResponse); + + await expect(unfollowUser(1)).resolves.toEqual( + expect.objectContaining({ data: expectedResponse }), + ); + expect(axiosMock.history.post[0].url).toBe(expectedUrl); + }); + }); +}); |