-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(follow unfollow User) : adds functionality to enable users to…
… 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
1 parent
bcd8904
commit 27e725d
Showing
25 changed files
with
1,548 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.