Skip to content

Commit

Permalink
feature(follow unfollow User) : adds functionality to enable users to…
Browse files Browse the repository at this point in the history
… follow and unfollow an author (#26)

- adds functionality for viewing all authors on AuthorsHaven
- adds functionality to enable users to follow and to unfollow authors

[Starts #161966580]
  • Loading branch information
verenceLola authored and dotNesh committed Feb 1, 2019
1 parent bcd8904 commit 27e725d
Show file tree
Hide file tree
Showing 25 changed files with 1,548 additions and 110 deletions.
56 changes: 28 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import SearchResultsPageContainer from './components/Search/SearchResultsPage';
import UserSpecificArticlesContainer from './components/Articles/UserSpecificArticlesContainer';
import IsAuthenticated from './common/IsAuthenticated';
import UpdateContainer from './components/Articles/UpdateContainer';


import ProfilesContainer from './containers/ProfilesContainer';
import SingleProfileContainer from './containers/SingleProfileContainer';
import CreateArticleFormContainer from './components/Articles/CreateArticleFormContainer';

class App extends Component {
Expand All @@ -32,6 +32,8 @@ class App extends Component {
<IsAuthenticated exact path="/myarticles" component={UserSpecificArticlesContainer} />
<IsAuthenticated path="/new_article" component={CreateArticleFormContainer} exact />
<Route path="/myarticles/:article_slug" component={UpdateContainer} exact />
<IsAuthenticated exact path="/profiles" component={ProfilesContainer} />
<IsAuthenticated exact path="/profiles/:profile" component={SingleProfileContainer} />
<Route component={Error} />
</Switch>
</BrowserRouter>
Expand Down
231 changes: 231 additions & 0 deletions src/actions/__tests__/profilesActions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/* eslint-disable comma-dangle */
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import expect from 'expect';
import {
FETCH_PROFILES, PROFILES_LOADING,
FETCH_PROFILES_FAILED, FETCH_PROFILE_FOLLOWERS,
FETCH_SINGLE_PROFILE, FETCH_SINGLE_PROFILE_SUCCESS,
FETCH_SINGLE_PROFILE_FAILED, FETCH_PROFILES_SUCCESSFUL
} from '../actionTypes';
import {
fetchUserProfiles, getUserFollowers,
fetchSingleProfile,
} from '../profilesActions';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('fetch profiles actions', () => {
beforeEach(() => {
moxios.install();
});

afterEach(() => {
moxios.uninstall();
});

it('creates FETCHPROFILES action after successfuly fetching profiles details', () => {
const profiles = [
{
avatar: 'https://libertv.com/wp-content/uploads/2018/03/user-avatar-placeholder-1.png',
bio: 'Hello world',
country: 'Kenya',
email: 'verencelola@icloud.com',
phone: '0987654342',
username: 'verencelola',
website: 'google.com',
},
{
avatar: 'https://libertv.com/wp-content/uploads/2018/03/user-avatar-placeholder-1.png',
bio: 'Hello world',
country: 'Kenya',
email: 'kamya@icloud.com',
phone: '0987654342',
username: 'kamya',
website: 'google.com',
},
];
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: profiles,
});
});

const expectedAction = [
{
type: PROFILES_LOADING,
status: true,
},
{
type: FETCH_PROFILES_SUCCESSFUL,
status: true,
},
{
type: FETCH_PROFILES,
profiles,
},
{
type: PROFILES_LOADING,
status: false,
},
];
const store = mockStore({ profileReducer: {} });
const token = 'token';
return store.dispatch(fetchUserProfiles(token)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedAction);
});
});
it('creates FETCH_PROFILE_FAILED after failing to fetch user profiles', () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 403,
response: 'Token Expired',
});
});
const expectedAction = [
{
type: PROFILES_LOADING,
status: true,
},
{
type: FETCH_PROFILES_FAILED,
reason: 'Token Expired'
},
{
type: PROFILES_LOADING,
status: false,
}
];
const store = mockStore({ profileReducer: {} });
const token = 'token';
return store.dispatch(fetchUserProfiles(token)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedAction);
});
});
it('creates FETCH_PROFILE_FOLLOWERS once followers found', () => {
const data = {
following: [
{
avatar: 'https://libertv.com/wp-content/uploads/2018/03/user-avatar-placeholder-1.png',
bio: 'Hello world',
country: 'Kenya',
email: 'verencelola@icloud.com',
phone: '0987654342',
username: 'verencelola',
website: 'google.com',
},
{
avatar: 'https://libertv.com/wp-content/uploads/2018/03/user-avatar-placeholder-1.png',
bio: 'Hello world',
country: 'Kenya',
email: 'kamya@icloud.com',
phone: '0987654342',
username: 'kamya',
website: 'google.com',
},
]
};
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: data
});
});
const expectedAction = [
{
type: FETCH_PROFILE_FOLLOWERS,
followers: data.following
},
];
const store = mockStore({ profileReducer: {} });
const token = 'token';
const currentUser = 'me';
return store.dispatch(getUserFollowers(currentUser, token)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedAction);
});
});
it('should create FETCH_SINGLE_PROFILE action after successfully getting a profile', () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 403,
response: 'Token Expired'
});
});
const expectedAction = [
{
type: PROFILES_LOADING,
status: true
},
{
type: PROFILES_LOADING,
status: false
},
{
type: FETCH_SINGLE_PROFILE_FAILED,
reason: 'Token Expired'
},
];
const store = mockStore({ profileReducer: {} });
const token = 'token';
const profile = 'me';
return store.dispatch(fetchSingleProfile(profile, token)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedAction);
});
});
it('should create FETCH_SINGLE_PROFILE action after successfully getting a profile', () => {
const data = {
profile: {
avatar: 'https://libertv.com/wp-content/uploads/2018/03/user-avatar-placeholder-1.png',
bio: 'Hello world',
country: 'Kenya',
email: 'verencelola@icloud.com',
phone: '0987654342',
username: 'verencelola',
website: 'google.com',
},
};
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: data
});
});
const expectedAction = [
{
type: PROFILES_LOADING,
status: true
},
{
type: PROFILES_LOADING,
status: false
},
{
type: FETCH_SINGLE_PROFILE,
details: data.profile
},
{
type: FETCH_SINGLE_PROFILE_SUCCESS,
status: true
},
];
const store = mockStore({ profileReducer: {} });
const token = 'token';
const profile = 'me';
return store.dispatch(fetchSingleProfile(profile, token)).then(() => {
// return of async actions
expect(store.getActions()).toEqual(expectedAction);
});
});
});
18 changes: 18 additions & 0 deletions src/actions/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ export const LIKE_COUNTFAIL = 'LIKE_COUNTFAIL';
export const DISLIKE_SUCCESSFUL = 'DISLIKE_SUCCESSFUL';
export const DISLIKE_FAILED = 'DISLIKE_FAILED';
export const DISLIKE_ACTION = 'DISLIKE_ACTION';
export const FETCH_PROFILES = 'FETCH USERS PROFILES';
export const FETCH_PROFILES_SUCCESSFUL = 'FETCH USERS PROFILES SUCCESSFULLY';
export const FETCH_PROFILES_FAILED = 'FETCH USERS PROFILES FAILED';
export const FETCHING_PROFILES = 'FETCHING USERS PROFILES ';
export const FETCH_SINGLE_PROFILE = 'FETCH SINGLE USER PROFILE';
export const FETCH_SINGLE_PROFILE_SUCCESS = 'FETCH SINGLE PROFILE SUCCESS';
export const FETCH_SINGLE_PROFILE_FAILED = 'FETCH SINGLE PROFILE FAILED';
export const FETCHING_SINGLE_PROFILE = 'FETCHING SINGLE PROFILE';
export const FOLLOWINGUNFOLLOWING_PROFILE = 'FOLLOWING USER PROFILE ';
export const FOLLOWINGUNFOLLOWING_PROFILE_SUCCESS = 'FOLLOWING UNFOLLOWING SUCCESS';
export const FOLLOWINGUNFOLLOWING_PROFILE_FAILED = 'FOLLOWING UNFOLLOWING FAILED';
export const FOLLOWUNFOLLOW_PROFILE = 'FOLLOW UNFOLLOW PROFILE RESPONSE';
export const FETCH_PROFILE_FOLLOWERS = 'FETCH USER FOLLOWERS';
export const PROFILE_FOLLOWERS = 'FETCH FOLLOWERS OF A GIVEN PROFILE';
export const FETCH_PROFILE_FOLLOWERS_FAILED = 'FETCH PROFILE FOLLOWERS FAILED';
export const PROFILE_FOLLOWING = 'FETCH PROFILE FOLLOWING DATA';
export const FETCH_PROFILE_FOLLOWING_FAILED = 'FETCH PROFILE FOLLOWERS FAILED';
export const PROFILES_LOADING = 'PROFILES LOADING STATUS';
Loading

0 comments on commit 27e725d

Please sign in to comment.