Skip to content

Commit

Permalink
Merge pull request #92 from Rwothoromo/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
Rwothoromo authored Jul 12, 2018
2 parents 356ed17 + 2b86332 commit 97cc3fc
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 14 deletions.
90 changes: 90 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"bootstrap": "^4.1.1",
"i": "^0.3.6",
"jquery": "^3.3.1",
"jsonwebtoken": "^8.3.0",
"jwt-decode": "^2.2.0",
"npm": "^6.1.0",
"popper.js": "^1.14.3",
Expand Down
4 changes: 1 addition & 3 deletions src/components/businesses/DeleteBusiness.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class DeleteBusiness extends Component {
axios.delete(`${apiUrl}/businesses/${this.props.business.id}`).then(response => {
NotificationManager.success(response.data.message);
this.props.showUpdatedBusinesses();
}).catch(error => {
NotificationManager.error(error.response.data.message);
});
}).catch(error => {});
}

render() {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/App.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from '../App';
import { apiUrl } from '../App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
expect(apiUrl).toContain('api/v2');
});
2 changes: 1 addition & 1 deletion src/tests/businesses/BusinessCards.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import BusinessCards from '../../components/businesses/BusinessCards';

describe('<BusinessesList />', () => {
it('it renders correctly', async () => {
it('renders correctly', async () => {
const wrapper = mount(<BusinessCards user={{sub: 1}} businesses_list ={[{business: {id: 1}}]}/>);
expect(wrapper).toHaveLength(1);
})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/businesses/BusinessSearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from 'enzyme';
import BusinessSearch from '../../components/businesses/BusinessSearch';

describe('<BusinessSearch />', () => {
let searchBusinesses = jest.fn(()=>{})
let searchBusinesses = jest.fn(() => {})

const wrapper = mount(<BusinessSearch searchBusinesses={searchBusinesses}/>);

Expand Down
18 changes: 16 additions & 2 deletions src/tests/businesses/BusinessesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ import { apiUrl } from '../../App';
describe('<BusinessesList />', () => {
const wrapper = shallow(<MemoryRouter><BusinessesList /></MemoryRouter>);
const mock = new MockAdapter(Axios);
const jwt = require('jsonwebtoken');
const token = jwt.sign({ sub: 1, iat: Math.floor(Date.now() / 1000) + 30 }, 'shhhhh');
localStorage.setItem("access_token", token);

it('lists businesses', async () => {
mock.onGet(`${apiUrl}/businesses?limit=3`).reply(200, {
businesses: [{},{}],
next_page: 2,
prev_page: null
});
});

it('gets all lists businesses', () => {
jest.spyOn(wrapper.find(BusinessesList).dive().instance(), "getAllBusinesses")
wrapper.find(BusinessesList).dive().instance().getAllBusinesses();
});
it('it shows updated businesses',()=>{
let spyonshow = jest.spyOn(wrapper.find(BusinessesList).dive().instance(), "showUpdatedBusinesses")

it('shows updated businesses', () => {
jest.spyOn(wrapper.find(BusinessesList).dive().instance(), "showUpdatedBusinesses")
wrapper.find(BusinessesList).dive().instance().showUpdatedBusinesses();
});

it('handles page change', () => {
jest.spyOn(wrapper.find(BusinessesList).dive().instance(), "handlePageChange")
wrapper.find(BusinessesList).dive().instance().handlePageChange({ preventDefault: () => {} });
});

});
2 changes: 1 addition & 1 deletion src/tests/businesses/DeleteBusiness.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('<DeleteBusiness />', () => {
message: "Business deleted"
});

const wrapper = mount(<DeleteBusiness showUpdatedBusinesses={()=>{}} business={ {id: 2}} />);
const wrapper = mount(<DeleteBusiness showUpdatedBusinesses={() => {}} business={ {id: 2}} />);


it('deletes a business', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/businesses/RegisterBusiness.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { apiUrl } from '../../App';

describe('<RegisterBusiness />', () => {
const mock = new MockAdapter(Axios);
const wrapper = mount(<RegisterBusiness showUpdatedBusinesses={()=>{}} business={ {id: 2}} />);
const wrapper = mount(<RegisterBusiness showUpdatedBusinesses={() => {}} business={ {id: 2}} />);

it('registers a business', () => {
mock.onPost(`${apiUrl}/businesses`).reply(201, {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/businesses/ReviewBusiness.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('<ReviewBusiness />', () => {
reviews_list:  [{}, {}],
message: "review"
});
const wrapper = mount(<ReviewBusiness showUpdatedBusinesses={()=>{}} business={{id: 2}} />);
const wrapper = mount(<ReviewBusiness showUpdatedBusinesses={() => {}} business={{id: 2}} />);
let form = wrapper.find('form')
form.simulate('submit');
});
Expand Down
2 changes: 1 addition & 1 deletion src/tests/businesses/ReviewCards.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import ReviewCards from '../../components/businesses/ReviewCards';

describe('<BusinessesList />', () => {
it('it renders correctly', async () => {
it('renders correctly', async () => {
const wrapper = mount(<ReviewCards reviews_list ={[{review: {id: 1}}]}/>);
expect(wrapper).toHaveLength(1);
})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/businesses/ShowBusiness.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Axios from 'axios';
import { apiUrl } from '../../App';

describe('<ShowBusiness />', () => {
const wrapper = mount(<ShowBusiness showUpdatedBusinesses={()=>{}} business={{id: 2}} />);
const wrapper = mount(<ShowBusiness showUpdatedBusinesses={() => {}} business={{id: 2}} />);
const mock = new MockAdapter(Axios);

it('shows a businesses', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/shared/Paginator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('<Paginator />', () => {
handlePageChange={jest.fn()}
/>);
let spy = jest.spyOn(wrapper.props(), 'handlePageChange')
wrapper.find('button#prev_page').simulate('click', {preventDefault: ()=>{}})
wrapper.find('button#prev_page').simulate('click', {preventDefault: () => {}})
expect(spy).toHaveBeenCalled();
})

Expand All @@ -21,7 +21,7 @@ describe('<Paginator />', () => {
handlePageChange={jest.fn()}
/>);
let spy = jest.spyOn(wrapper.props(), 'handlePageChange')
wrapper.find('button#next_page').simulate('click', {preventDefault: ()=>{}})
wrapper.find('button#next_page').simulate('click', {preventDefault: () => {}})
expect(spy).toHaveBeenCalled();
});
})
13 changes: 13 additions & 0 deletions src/tests/utils/Helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { isLoggedIn, contains } from '../../utils/Helpers';

describe('Helper - isLoggedIn', () => {
const jwt = require('jsonwebtoken');
it('checks if user not logged in', () => {
localStorage.clear();
expect(isLoggedIn()).toBe(false);
});

it('checks if user logged in', () => {
const token = jwt.sign({ sub: 1, iat: Math.floor(Date.now() / 1000) + 30 }, 'shhhhh');
localStorage.setItem("access_token", token);
expect(isLoggedIn()).toBe(true);
});

it('removes expired token', () => {
const token = jwt.sign({ sub: 1, exp: Math.floor(Date.now() / 1000) - 30 }, 'shhhhh');
localStorage.setItem("access_token", token);
expect(isLoggedIn()).toBe(false);
});
});

describe('Helper - List contains', () => {
Expand Down

0 comments on commit 97cc3fc

Please sign in to comment.