diff --git a/src/redux/api/github/api.github.test.js b/src/redux/api/github/api.github.test.js index 3e3a33c..a775c3d 100644 --- a/src/redux/api/github/api.github.test.js +++ b/src/redux/api/github/api.github.test.js @@ -15,6 +15,12 @@ describe('Github Rest API', () => { expect(Array.isArray(data.data)).toBe(true); }); + it('should get profile of the authenticated user', async () => { + expect(getProfile).toBeInstanceOf(Function); + const data = await getProfile(); + expect(data).toHaveProperty('data.login', 'artzub'); + }); + it('should get profile of user by login', async () => { expect(getProfile).toBeInstanceOf(Function); const login = 'artzub'; diff --git a/src/redux/api/github/getClient.js b/src/redux/api/github/getClient.js index 49d971e..743dda0 100644 --- a/src/redux/api/github/getClient.js +++ b/src/redux/api/github/getClient.js @@ -1,6 +1,6 @@ import { Octokit } from '@octokit/rest'; -import { appNameVersion } from '@/shared/utils'; +import { appNameVersion } from '@/shared/utils/appNameVersion'; let instance; let lastToken; diff --git a/src/redux/api/github/getProfile.js b/src/redux/api/github/getProfile.js index 05d94e2..b9a5d58 100644 --- a/src/redux/api/github/getProfile.js +++ b/src/redux/api/github/getProfile.js @@ -6,18 +6,26 @@ import { parseRateLimit } from './utils'; /** * Gets profile by owner's login - * @param {String} login - login of a user + * @param {String} [login] - login of a user * @return {Promise<{rateLimit: *, data: object}>} */ export const getProfile = (login) => withCancellation(async (signal) => { const client = getClient(); - const data = await client.users.getByUsername({ - username: login, - request: { - signal, - }, - }); + const request = { + signal, + }; + + const promise = login + ? client.users.getByUsername({ + username: login, + request, + }) + : client.users.getAuthenticated({ + request, + }); + + const data = await promise; return { data: data?.data && profile(data?.data),