Skip to content

Commit

Permalink
chore[hotfix]:properly define test suits
Browse files Browse the repository at this point in the history
  • Loading branch information
ddouglasz committed Aug 7, 2018
1 parent 89256b5 commit 74eecd6
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 435 deletions.
16 changes: 1 addition & 15 deletions client/src/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,5 @@ export const LoginAction = userProfile => dispatch =>
return response.data.message;
});

// /**
// * Login
// * @param {*} userProfile
// * @returns {object} action to be dispatched
// */
// export const LoginAction = userProfile => dispatch =>
// axios.post('api/v1/auth/login', userProfile)
// .then((response) => {
// const { token } = response.data;
// setAuth(token);
// localStorage.setItem('userToken', token);
// const user = decode(token);
// dispatch(currentUser(user));
// return response.data.message;
// });


4 changes: 2 additions & 2 deletions client/src/actions/businessActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from './types';
import { currentUser } from './authActions';


/**
* AllBusiness
* @param {Object} businesses
Expand All @@ -30,6 +29,7 @@ export function allBusinesses(businesses) {
businesses
};
}

/**
* AllBusiness
* @param {Object} pagination
Expand Down Expand Up @@ -261,7 +261,7 @@ export function getUserProfileFailed(error) {
*/
export const UserDashBoardAction = () => (dispatch) => {
const userId = localStorage.userToken ? jwt.decode(localStorage.getItem('userToken')).id : null;
axios.get(`/api/v1/auth/${userId}/userProfile`)
return axios.get(`/api/v1/auth/${userId}/userProfile`)
.then((response) => {
dispatch(getUserProfileSuccessful(response.data.userdata));
});
Expand Down
48 changes: 10 additions & 38 deletions client/src/test/actions/businessActions.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import moxios from 'moxios';
import thunk from 'redux-thunk';
import decode from 'jwt-decode';
import configureMockStore from 'redux-mock-store';
import { SignUpAction, LoginAction, logout } from '../../actions/authActions';
import { CURRENT_USER, ALL_BUSINESSES, PAGINATION, ONE_BUSINESS, EDIT_SUCCESSFUL, EDIT_FAILED, DELETE_SUCCESSFUL, DELETE_FAILED, GET_USER_PROFILE_SUCCESSFUL } from '../../actions/types';
import { registerBusinessAction, getBusinessAction, getAllBusinessSearchAction, getOneBusinessAction, editBusinessAction, deleteBusinessAction, UserDashBoardAction } from '../../actions/businessActions';
import { ALL_BUSINESSES, PAGINATION, ONE_BUSINESS, EDIT_SUCCESSFUL, EDIT_FAILED, DELETE_SUCCESSFUL, DELETE_FAILED } from '../../actions/types';
import { registerBusinessAction, getBusinessAction, getAllBusinessSearchAction, getOneBusinessAction, editBusinessAction, deleteBusinessAction } from '../../actions/businessActions';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand All @@ -18,7 +16,7 @@ describe('authActions', () => {
moxios.uninstall();
});

it('should dispatch login data for a successful login', (done) => {
it('should dispatch 200 status along with successfully requested businesses', (done) => {
moxios.stubRequest('api/v1/businesses', {
status: 200,
response: {
Expand All @@ -39,7 +37,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch pagination details data for a business catalog page', (done) => {
const page = 1;
moxios.stubRequest(`api/v1/businesses?page=${page || 1}`, {
status: 200,
Expand Down Expand Up @@ -68,7 +66,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch businesses by search action of location or category', (done) => {
const searchType = 'location';
const keyValue = 'sao paulo';
moxios.stubRequest(`api/v1/businesses?${searchType}=${keyValue}`, {
Expand All @@ -93,7 +91,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch get business action for a search for a single business', (done) => {
const id = 1;
moxios.stubRequest(`/api/v1/businesses/${id}`, {
status: 200,
Expand All @@ -117,7 +115,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch an edit business action data for a successful business edit', (done) => {
const business = { id: 1 };
moxios.stubRequest(`/api/v1/businesses/${business.id}`, {
status: 200,
Expand All @@ -141,7 +139,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch not edit business action data for a unsuccessful business edit and return an error message', (done) => {
const business = { id: 1 };
moxios.wait(() => {
const request = moxios.requests.mostRecent();
Expand All @@ -166,7 +164,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch a message for a business that was not successfully deleted', (done) => {
const id = 1;
moxios.wait(() => {
const request = moxios.requests.mostRecent();
Expand All @@ -193,7 +191,7 @@ describe('authActions', () => {
});
});

it('should dispatch signup data for a successful signup', (done) => {
it('should dispatch delete data for a business that was successfully deleted', (done) => {
const id = 1;
moxios.stubRequest(`/api/v1/businesses/${id}`, {
status: 200,
Expand All @@ -216,30 +214,4 @@ describe('authActions', () => {
done();
});
});

it('should dispatch signup data for a successful signup', (done) => {
const userId = 1;
moxios.stubRequest(`/api/v1/auth/${userId}/userProfile`, {
status: 200,
response: {
userdata: {}
}
});
const expectedActions = [
{
type: GET_USER_PROFILE_SUCCESSFUL,
userProfile: {}
}
];

localStorage.setItem('userToken', token);

const store = mockStore({});
return store.dispatch(UserDashBoardAction())
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(store.getActions().length).toBe(1);
done();
});
});
});
4 changes: 2 additions & 2 deletions client/src/test/actions/reviewsActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('authActions', () => {
moxios.uninstall();
});

it('should dispatch login data for a successful login', (done) => {
it('should dispatch review data for getting all reviews for a given business', (done) => {
const id = 1;
moxios.stubRequest(`/api/v1/businesses/${id}/reviews`, {
status: 200,
Expand All @@ -41,7 +41,7 @@ describe('authActions', () => {
});
});

it('should dispatch login data for a successful login', (done) => {
it('should dispatch review data for a successfully added review', (done) => {
const id = 1;
moxios.stubRequest(`/api/v1/businesses/${id}/reviews`, {
status: 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Component: BusinessProfile', () => {
});

describe('Connected BusinessProfile', () => {
it('tests that the comnponent successfully renders', () => {
it('should test that the comnponent successfully renders', () => {
const allBusinesses = {
oneBusiness: {
id: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ const event = {
}
};

describe('Component: RegisterBusinessPage', () => {
describe('Component: EditBusiness', () => {
it('should render the component successfully', () => {
const wrapper = setup();
expect(wrapper.find('div').length).toBe(21);
});
});

describe('Connected RegisterBusinessPage', () => {
describe('Connected EditBusiness', () => {
it('should return oneBusiness from state', () => {
const allBusinesses = {
business: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Adapter from 'enzyme-adapter-react-16';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import React from 'react';
// import { RegisterBusiness } from '../../../../components/businesses/smart/RegisterBusiness.jsx';
import ConnectedRegisterBusiness, { RegisterBusiness } from '../../../../components/businesses/smart/RegisterBusiness.jsx';

const middlewares = [thunk];
Expand Down Expand Up @@ -56,7 +55,7 @@ const event = {
}
};

describe('Component: RegisterBusinessPage', () => {
describe('Component: RegisterBusiness', () => {
it('should render the component successfully', () => {
const wrapper = setup();
expect(wrapper.find('div').length).toBe(21);
Expand Down
121 changes: 56 additions & 65 deletions client/src/test/e2e/ui-features.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@


module.exports = {
// 'User should not be able to signup with invalid email ': (browser) => {
// browser
// .url('http://localhost:8000/signup')
// .waitForElementVisible('body', 3000)
// .assert.visible('h2')
// .assert.containsText('h2', 'Sign Up')
// .setValue('input[name=firstName]', 'steve')
// .setValue('input[name=lastName]', 'steve')
// .setValue('input[name=email]', 'steve')
// .setValue('input[name=password]', 'steve')
// .click('#signup-btn')
// .waitForElementVisible('#signup-errors', 2000)
// .assert.containsText('#signup-errors', 'invalid email format')
// .pause(5000)
// .end();
// },
'User should not be able to signup with invalid email ': (browser) => {
browser
.url('http://localhost:8000/signup')
.waitForElementVisible('body', 3000)
.assert.visible('h2')
.assert.containsText('h2', 'Sign Up')
.setValue('input[name=firstName]', 'steve')
.setValue('input[name=lastName]', 'steve')
.setValue('input[name=email]', 'steve')
.setValue('input[name=password]', 'steve')
.click('#signup-btn')
.waitForElementVisible('#signup-errors', 2000)
.assert.containsText('#signup-errors', 'invalid email format')
.pause(5000)
.end();
},
'User should be able to signup with complete signup details ': (browser) => {
browser
.url('http://localhost:8000/signup')
Expand All @@ -34,45 +34,45 @@ module.exports = {
.assert.containsText('.alert', 'signed up successfully!')
.pause(5000);
},
// 'User should not be able to login with incorrect login details ': (browser) => {
// browser
// .url('http://localhost:8000')
// .waitForElementVisible('body', 3000)
// .assert.visible('h1')
// .assert.containsText('h1', 'WEConnect you to your next business.')
// .setValue('input[name=email]', '[email protected]')
// .setValue('input[name=password]', 'steveqwerty')
// .click('#signin-btn')
// .pause(2000)
// .waitForElementVisible('#signin-errors', 2000)
// .assert.containsText('#signin-errors', 'User Not Found')
// .pause(5000);
// },
// 'User should be able login with correct login details ': (browser) => {
// browser
// .url('http://localhost:8000')
// .waitForElementVisible('body', 3000)
// .assert.visible('h1')
// .assert.containsText('h1', 'WEConnect you to your next business.')
// .setValue('input[name=email]', '[email protected]')
// .setValue('input[name=password]', 'steve')
// .click('#signin-btn')
// .pause(2000)
// .assert.urlEquals('http://localhost:8000/UserProfile')
// .waitForElementVisible('.alert', 2000)
// .assert.containsText('.alert', 'Login successful')
// .pause(5000);
// // browser.end();
// },
// 'Logged in user should be able to see a create business link on the NavBar ': (browser) => {
// browser
// .url('http://localhost:8000/UserProfile')
// .waitForElementVisible('body', 3000)
// .pause(2000)
// .click('.reg')
// .assert.urlEquals('http://localhost:8000/registerBusiness')
// .pause(5000);
// },
'User should not be able to login with incorrect login details ': (browser) => {
browser
.url('http://localhost:8000')
.waitForElementVisible('body', 3000)
.assert.visible('h1')
.assert.containsText('h1', 'WEConnect you to your next business.')
.setValue('input[name=email]', '[email protected]')
.setValue('input[name=password]', 'steveqwerty')
.click('#signin-btn')
.pause(2000)
.waitForElementVisible('#signin-errors', 2000)
.assert.containsText('#signin-errors', 'User Not Found')
.pause(5000);
},
'User should be able login with correct login details ': (browser) => {
browser
.url('http://localhost:8000')
.waitForElementVisible('body', 3000)
.assert.visible('h1')
.assert.containsText('h1', 'WEConnect you to your next business.')
.setValue('input[name=email]', '[email protected]')
.setValue('input[name=password]', 'steve')
.click('#signin-btn')
.pause(2000)
.assert.urlEquals('http://localhost:8000/UserProfile')
.waitForElementVisible('.alert', 2000)
.assert.containsText('.alert', 'Login successful')
.pause(5000);
// browser.end();
},
'Logged in user should be able to see a create business link on the NavBar ': (browser) => {
browser
.url('http://localhost:8000/UserProfile')
.waitForElementVisible('body', 3000)
.pause(2000)
.click('.reg')
.assert.urlEquals('http://localhost:8000/registerBusiness')
.pause(5000);
},
'Logged in user should be able to create a business ': (browser) => {
browser
.url('http://localhost:8000/registerBusiness')
Expand All @@ -89,27 +89,18 @@ module.exports = {
.click('button[name=save]')
.pause(2000)
.assert.urlEquals('http://localhost:8000/UserProfile');
// browser.end();
},
'Logged in user should be able to view business catalog, business profile and edit his/her business ': (browser) => {
browser
.url('http://localhost:8000/businessCatalog')
.waitForElementVisible('body', 3000)
.pause(10000)
// .assert.visible('h1')
// .assert.containsText('h1', 'Business Catalog')
// .setValue('input[name=title]', 'mart.ng')
// .setValue('textarea[name=description]', 'a great business')
// .setValue('input[name=category]', 'technology')
// .setValue('input[name=location]', 'steve')
// .setValue('input[name=email]', '[email protected]')
.pause(3000)
.click('#find-one-business')
.click('#find-one-business1')
// .click('button[name=save]')
.pause(2000)
.assert.urlEquals('http://localhost:8000/businessProfile/1');
// browser.end();
browser.end();
},
'Should re route users to login for protected routes': (browser) => {
browser
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoiYWxhbiIsImVtYWlsIjoiY29AZmtzLmNvbSIsImlhdCI6MTUyNjc3NDY4NX0.-ifQEPBdNquBQylvLQGvEPz1UHJTYzlTJJa3O9r1yVE';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoic3RldmUiLCJlbWFpbCI6InN0ZXZlQHN0ZXZlLmNvbSIsImlhdCI6MTUyNjc3NDY4NX0.1769zEZcgxW6nB951nEV4zEhbVdc76CDI0I0cMdyzGw';

global.token = token;
Loading

0 comments on commit 74eecd6

Please sign in to comment.