-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from andela/ft-book-accommodation-169258604
#169258604 a user should be able to book an accommodation facility
- Loading branch information
Showing
23 changed files
with
806 additions
and
94 deletions.
There are no files selected for viewing
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
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
100 changes: 100 additions & 0 deletions
100
src/__tests__/actions/bookings/bookAccommodationActions.js
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,100 @@ | ||
import moxios from 'moxios'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { | ||
updateBookAccommodationInput, | ||
bookAccommodationAction, | ||
} from '../../../redux/actions/bookings/bookAnAccommodation'; | ||
import { | ||
BOOK_ACCOMMODATION_SUCCESS, | ||
BOOK_ACCOMMODATION_ERROR, | ||
UPDATE_INPUT, | ||
} from '../../../redux/actionTypes/bookingActionTypes'; | ||
import apiCall from '../../../helpers/apiCall'; | ||
import { | ||
errorTypeResponse, | ||
errorResponse, | ||
errorRequest, | ||
} from '../../../__mocks__/auth/authMock'; | ||
|
||
let store; | ||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
describe('Signup Tests ', () => { | ||
beforeEach(() => { | ||
moxios.install(apiCall); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(apiCall); | ||
}); | ||
|
||
it('it Should dispatch book accommodation Errror', async () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 400, | ||
response: { | ||
message: 'first name should be valid', | ||
}, | ||
}); | ||
}); | ||
|
||
store = mockStore({}); | ||
const { dispatch } = store; | ||
await dispatch(bookAccommodationAction({ tripId: 90 })).then(async () => { | ||
const calledActions = store.getActions(); | ||
|
||
expect(calledActions).toEqual([ | ||
{ | ||
type: 'BOOK_ACCOMMODATION_ERROR', | ||
payload: { | ||
message: 'first name should be valid', | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); | ||
it('it Should dispatch book accommodation success', async () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: { | ||
message: 'first name should be valid', | ||
}, | ||
}); | ||
}); | ||
|
||
store = mockStore({}); | ||
const { dispatch } = store; | ||
await dispatch(bookAccommodationAction({ tripId: 90 })).then(async () => { | ||
const calledActions = store.getActions(); | ||
|
||
expect(calledActions).toEqual([ | ||
{ | ||
type: 'BOOK_ACCOMMODATION_SUCCESS', | ||
payload: { | ||
message: 'first name should be valid', | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); | ||
it('it Should dispatchupdate inputs success', async () => { | ||
store = mockStore({}); | ||
const { dispatch } = store; | ||
dispatch(updateBookAccommodationInput({ paginationEnd: 5, paginationStart: 0 })); | ||
const calledActions = store.getActions(); | ||
expect(calledActions).toEqual([ | ||
{ | ||
payload: { | ||
paginationEnd: 5, | ||
paginationStart: 0, | ||
}, | ||
type: UPDATE_INPUT, | ||
}, | ||
]); | ||
}); | ||
}); |
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
5 changes: 5 additions & 0 deletions
5
src/__tests__/containers/bookings/__snapshots__/bookAccommodation.test.js.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Common Single Request page it Should dispatch reject button successfully 1`] = `ReactWrapper {}`; | ||
|
||
exports[`Common Single Request page it Should dispatch reject button successfully 2`] = `ReactWrapper {}`; |
70 changes: 70 additions & 0 deletions
70
src/__tests__/containers/bookings/bookAccommodation.test.js
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,70 @@ | ||
import React from 'react'; | ||
import dotenv from 'dotenv'; | ||
import { mount, shallow } from 'enzyme'; | ||
import configureStore from 'redux-mock-store'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import BookAccommodation from '../../../views/accommodation/BookAccommodation'; | ||
import initialState from '../../../redux/store/initialState'; | ||
import { | ||
init, | ||
} from '../../../__mocks__/trips/requests'; | ||
import 'jest-localstorage-mock'; | ||
|
||
dotenv.config(); | ||
const mockStore = configureStore([]); | ||
let wrapper; | ||
let store; | ||
|
||
describe('Common Single Request page ', () => { | ||
it('it Should dispatch reject button successfully', async () => { | ||
store = mockStore(init); | ||
localStorage.setItem('token', process.env.TESTING_TOKEN); | ||
|
||
wrapper = mount( | ||
<Provider store={store}> | ||
<Router> | ||
<BookAccommodation /> | ||
</Router> | ||
</Provider>, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
const selectRoomType = wrapper.find('#selectRoomType'); | ||
const selectRoomName = wrapper.find('#selectRoomName'); | ||
const checkInDate = wrapper.find('#checkInDate'); | ||
const checkOutDate = wrapper.find('#checkOutDate'); | ||
const save = wrapper.find('#save'); | ||
const cancel = wrapper.find('#cancel'); | ||
selectRoomType.simulate('change'); | ||
selectRoomName.simulate('change'); | ||
checkOutDate.simulate('change'); | ||
checkInDate.simulate('change'); | ||
save.simulate('click'); | ||
cancel.simulate('click'); | ||
expect(jest.fn().mock.calls).toBeDefined(); | ||
}); | ||
it('it Should dispatch reject button successfully', async () => { | ||
store = mockStore({ | ||
popUpsDisplay: { | ||
bookAccommodation: 'none', | ||
deleteComment: 'none', | ||
editTrip: 'none', | ||
currentPopUp: 'editTrip', | ||
}, | ||
viewProfile: { profile: '' }, | ||
trips: { requests: { requestsData: [] }, tripRequests: { getCity: [] } }, | ||
allAccomodation: { accommodations: [] }, | ||
bookings: { bookAccommodation: { bookAccommodationInput: {} } }, | ||
}); | ||
localStorage.setItem('token', process.env.TESTING_TOKEN); | ||
|
||
wrapper = mount( | ||
<Provider store={store}> | ||
<Router> | ||
<BookAccommodation /> | ||
</Router> | ||
</Provider>, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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,48 @@ | ||
import bookAccommodationReducer from '../../../redux/reducers/bookings/bookAccommodationReducer'; | ||
import initialState from '../../../redux/store/initialState'; | ||
import { | ||
signupSuccessAction, signupInputAction, signupErrorAction, spinnerStatusAction, | ||
} from '../../../__mocks__/auth/authMock'; | ||
|
||
|
||
describe('Book accommodation test', () => { | ||
it('Should handle booking success', () => { | ||
const newState = bookAccommodationReducer({}, { | ||
type: 'BOOK_ACCOMMODATION_SUCCESS', | ||
payload: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
expect(newState).toEqual({ | ||
bookAccommodationData: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
}); | ||
it('Should handle booking error', () => { | ||
const newState = bookAccommodationReducer({}, { | ||
type: 'BOOK_ACCOMMODATION_ERROR', | ||
payload: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
expect(newState).toEqual({ | ||
bookAccommodationError: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
}); | ||
it('Should handle updating accommodation input', () => { | ||
const newState = bookAccommodationReducer({}, { | ||
type: 'UPDATE_INPUT', | ||
payload: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
expect(newState).toEqual({ | ||
bookAccommodationInput: { | ||
message: 'Updated your password successful', | ||
}, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.