Skip to content

Commit

Permalink
#104 added getting profile of authenticated user.
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed May 30, 2023
1 parent 0bfa6cc commit c104f28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/redux/api/github/api.github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/redux/api/github/getClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest';

import { appNameVersion } from '@/shared/utils';
import { appNameVersion } from '@/shared/utils/appNameVersion';

let instance;
let lastToken;
Expand Down
22 changes: 15 additions & 7 deletions src/redux/api/github/getProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit c104f28

Please sign in to comment.