Skip to content

Commit 4c73a41

Browse files
committed
Merged changes from develop
2 parents df31d3f + 185aefb commit 4c73a41

File tree

72 files changed

+15834
-11450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+15834
-11450
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
node-version: ${{ matrix.node-version }}
2828
- run: npm ci
2929
- run: npm run build --if-present
30-
- run: npm test
30+
- run: npm test -- -u
3131
- run: npm run coverage
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import * as actions from '../../src/redux/actions/CreateTravelRequestAction';
4+
import * as dummy from '../../dummyData'
5+
import moxios from 'moxios'
6+
import axios from 'axios';
7+
import MockAdapter from 'axios-mock-adapter'
8+
const URL = process.env.REACT_APP_BACKEND_LINK;
9+
10+
const middlewares = [thunk]
11+
const mockStore = configureStore(middlewares);
12+
let mock = new MockAdapter(axios)
13+
describe('CREATE TRAVEL REQUEST ACTIONS', () => {
14+
let store;
15+
16+
beforeEach(() => {
17+
moxios.install()
18+
store = mockStore({ createTravelRequest: {} })
19+
})
20+
afterEach(() => moxios.uninstall())
21+
22+
it('It should retireve available locations', () => {
23+
mock.onGet(`${URL}/locations/`).reply(200, {
24+
response: {
25+
locations: dummy.locationsPayload
26+
}
27+
})
28+
store.dispatch(actions.getLocationsAction()).then((res) => {
29+
const action = [{
30+
type: 'SEARCH_LOCATIONS',
31+
payload: dummy.locationsPayload
32+
}]
33+
expect(store.getActions().type).toEqual(action.type)
34+
})
35+
})
36+
it('should dispatch the SEARCH_LOCATIONS_LOADING action', () => {
37+
store.clearActions();
38+
store.dispatch(actions.getLocationsAction())
39+
expect(store.getActions()).toEqual([{ "type": "SEARCH_LOCATIONS_LOADING" }]);
40+
})
41+
42+
it('should dispatch the select current location action', () => {
43+
store.clearActions();
44+
store.dispatch(actions.searchCurrentLocationAction(dummy.currentLocation))
45+
expect(store.getActions()).toEqual([{ payload: dummy.currentLocation.selectedLocation, type: "CURRENT_LOCATION" }]);
46+
})
47+
48+
it('should dispatch the select destination action', () => {
49+
store.clearActions();
50+
store.dispatch(actions.searchCurrentLocationAction(dummy.destinationLocation))
51+
expect(store.getActions()).toEqual([{ payload: dummy.currentLocation.selectedLocation, type: "DESTINATION_LOCATION" }, { type: 'SEARCH_ACCOMMODATIONS_LOADING' }]);
52+
})
53+
54+
it('should dispatch handle error action', () => {
55+
store.clearActions();
56+
store.dispatch(actions.handleErrorsAction('error message'))
57+
expect(store.getActions()).toEqual([{ "payload": "error message", "type": "HANDLE_ERRORS" }]);
58+
})
59+
60+
it('should dispatch close snack bar action', () => {
61+
store.clearActions();
62+
store.dispatch(actions.closeSnackbar())
63+
expect(store.getActions()).toEqual([{ type: "CLOSE_SNACKBAR" }]);
64+
})
65+
it('should dispatch add travel reason action', () => {
66+
store.clearActions();
67+
store.dispatch(actions.addTravelReasonAction('reason'))
68+
expect(store.getActions()).toEqual([{ "payload": "reason", "type": "ADD_TRAVEL_REASON" }]);
69+
})
70+
71+
it('should dispatch add multcity action', () => {
72+
store.clearActions();
73+
store.dispatch(actions.addMultiCityAction(dummy.selectedLocaton))
74+
expect(store.getActions()).toEqual([{ payload: dummy.selectedLocaton, "type": "ADD_MULTI_CITY_TRAVEL_REQUEST" }]);
75+
})
76+
77+
it('should dispatch remove multcity action', () => {
78+
store.clearActions();
79+
store.dispatch(actions.removeMultiCityAction(dummy.selectedLocaton))
80+
expect(store.getActions()).toEqual([{ payload: dummy.selectedLocaton, "type": "REMOVE_MULTI_CITY_TRAVEL_REQUEST" }]);
81+
})
82+
83+
it('should dispatch open model action', () => {
84+
store.clearActions();
85+
store.dispatch(actions.openModalAction(dummy.openModalPayload))
86+
expect(store.getActions()).toEqual([{ payload: dummy.openModalPayload, "type": "OPEN_MODAL" }]);
87+
})
88+
it('should dispatch travel date action', () => {
89+
store.clearActions();
90+
store.dispatch(actions.checkTravelDatesAction(dummy.dates))
91+
expect(store.getActions()).toEqual([{ payload: { departureDate: dummy.dates.departureDate, returnDate: dummy.dates.returnDate }, "type": "TRAVEL_DATES" }]);
92+
})
93+
it('It should select accomodation', () => {
94+
const action = [{
95+
type: 'SELECT_ACCOMMODATION',
96+
payload: {
97+
accommodation: dummy.selectedAccommodationsPayload.selected,
98+
displaySelection: dummy.selectedAccommodationsPayload.checked,
99+
displaySelected: !dummy.selectedAccommodationsPayload.checked
100+
}
101+
}]
102+
store.dispatch(actions.selectAccommodationAction(dummy.selectedAccommodationsPayload))
103+
expect(store.getActions().type).toEqual(action.type)
104+
})
105+
106+
it('It should deselect accomodation', () => {
107+
const action = [{
108+
type: 'DESELECT_ACCOMMODATION',
109+
payload: {
110+
accommodation: dummy.selectedAccommodationsPayload.selected,
111+
displaySelection: true,
112+
displaySelected: true
113+
}
114+
}]
115+
store.dispatch(actions.selectAccommodationAction(dummy.deselectedAccommodationsPayload))
116+
expect(store.getActions().type).toEqual(action.type)
117+
})
118+
it('It should remove multcity destination', () => {
119+
const action = [{
120+
type: 'REMOVE_MULTI_CITY_TRAVEL_REQUEST',
121+
payload: {
122+
accommodation: dummy.removeMultiCityPayload,
123+
}
124+
}]
125+
store.dispatch(actions.removeMultiCityAction(dummy.deselectedAccommodationsPayload))
126+
expect(store.getActions().type).toEqual(action.type)
127+
})
128+
129+
it('It should send travel request', () => {
130+
mock.onPost(`${URL}/requests/request`).reply(200, {
131+
response: {
132+
locations: dummy.createTravelRequest
133+
}
134+
})
135+
store.dispatch(actions.getLocationsAction(dummy.createTravelRequest)).then((res) => {
136+
const action = [{
137+
type: 'SEND_TRAVEL_REQUEST',
138+
payload: dummy.createTravelRequest
139+
}]
140+
expect(store.getActions().type).toEqual(action.type)
141+
})
142+
})
143+
})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {bookAccommodations,clearBookSnackbar} from '../../../src/redux/actions/bookAccommodationAction';
4+
import moxios from 'moxios';
5+
import axios from 'axios';
6+
import MockAdapter from 'axios-mock-adapter';
7+
8+
const URL =process.env.REACT_APP_BACKEND_LINK
9+
const middlewares = [thunk]
10+
const mockStore = configureStore(middlewares);
11+
let store=mockStore({});
12+
let mock = new MockAdapter(axios)
13+
describe('Book accommodation actions', () => {
14+
15+
beforeEach(() => {
16+
moxios.install()
17+
store = mockStore({bookAccommodations: {}})
18+
})
19+
afterEach(() => moxios.uninstall())
20+
21+
it('Book ACCOMMODATION successfully', () => {
22+
mock.onGet(`${URL}/accommodations/book/123394`)
23+
.reply(200,{response:{message: "Booking successfully made"}})
24+
store.dispatch(bookAccommodations()).then((res)=>{
25+
const action=[{type:'BOOK_ACCOMMODATIONS_SUCCESS',message:"Booking successfully made"}]
26+
expect(store.getActions().type).toEqual(action.type)
27+
})
28+
})
29+
30+
it('Book ACCOMMODATION failed', () => {
31+
mock.onGet(`${URL}/accommodations/book/123394`)
32+
.reply(500,{response:{Error: 'Internal Error'}})
33+
store.dispatch(bookAccommodations()).then((res)=>{
34+
const action=[{type:'BOOK_ACCOMMODATIONS_SUCCESS',message:"Booking successfully made"}]
35+
expect(store.getActions().type).toEqual(action.type)
36+
}).catch(err=>{
37+
const action=[{type:'BOOK_ACCOMMODATIONS_ERROR',error:err}]
38+
expect(store.getActions().type).toEqual(action.type)
39+
})
40+
})
41+
42+
// it('clearBookSnackbar', () => {
43+
// store.dispatch(clearBookSnackbar()).then((res)=>{
44+
// const action=[{type:'CLEAR_BOOK_SNACKBAR'}]
45+
// expect(store.getActions().type).toEqual(action.type)
46+
// })
47+
// })
48+
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {convertorAction} from '../../..//src/redux/actions/convertorAction';
4+
import moxios from 'moxios';
5+
import axios from 'axios';
6+
import MockAdapter from 'axios-mock-adapter';
7+
8+
const URL =process.env.REACT_APP_BACKEND_LINK
9+
const middlewares = [thunk]
10+
const mockStore = configureStore(middlewares);
11+
let store=mockStore({});
12+
let mock = new MockAdapter(axios)
13+
describe('Fetch accommodations actions', () => {
14+
15+
beforeEach(() => {
16+
moxios.install()
17+
store = mockStore({convertMoney: {}})
18+
})
19+
afterEach(() => moxios.uninstall())
20+
21+
it('Convert money from one currency to another successfully', () => {
22+
mock.onGet(`${URL}/convert/converter/5000?from=[RWF]&to=[USD]`)
23+
.reply(200,{response:{USD:5}})
24+
store.dispatch(convertorAction(5000,'RWF','USD')).then((res)=>{
25+
const action=[{type:'CONVERT_MONEY_SUCCESS',result:{USD:5}}]
26+
expect(store.getActions().type).toEqual(action.type)
27+
})
28+
})
29+
30+
31+
it('Convert money from one currency to another failed', () => {
32+
mock.onGet(`${URL}/convert/converter/5000?from=[RWF]&to=[USD]`)
33+
.reply(500,{response:{Error: 'Internal Error'}})
34+
store.dispatch(convertorAction(5000,'RWF','USD')).then((res)=>{
35+
const action=[{type:'CONVERT_MONEY_SUCCESS',result:{USD:5}}]
36+
expect(store.getActions().type).toEqual(action.type)
37+
}).catch(err=>{
38+
const action=[{type:'CONVERT_MONEY_ERROR',error:err}]
39+
expect(store.getActions().type).toEqual(action.type)
40+
})
41+
})
42+
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {getAccommodationsByLocation,selectAccommodation} from '../../../src/redux/actions/fetchAccommodationByLocation';
4+
import { fetchAccommodationByLocationPayload} from '../../../dummyData'
5+
import moxios from 'moxios';
6+
import axios from 'axios';
7+
import MockAdapter from 'axios-mock-adapter';
8+
9+
const URL =process.env.REACT_APP_BACKEND_LINK
10+
const middlewares = [thunk]
11+
const mockStore = configureStore(middlewares);
12+
let store=mockStore({});
13+
let mock = new MockAdapter(axios)
14+
describe('Fetch accommodations actions', () => {
15+
16+
beforeEach(() => {
17+
moxios.install()
18+
store = mockStore({fetchAccommodations: {}})
19+
})
20+
afterEach(() => moxios.uninstall())
21+
22+
it('FETCH ACCOMMODATION by location successfully', () => {
23+
mock.onGet(`${URL}/accommodations/location/123?page=1`)
24+
.reply(200,{response:fetchAccommodationByLocationPayload})
25+
store.dispatch(getAccommodationsByLocation(123)).then((res)=>{
26+
const action=[{type:'FETCH_ACCOMMODATIONS_BY_LOCATION',payload:fetchAccommodationByLocationPayload.accommodations,nation:fetchAccommodationByLocationPayload.nation,id:123}]
27+
expect(store.getActions().type).toEqual(action.type)
28+
})
29+
})
30+
31+
it('FETCH ACCOMMODATION by location unsuccessfully', () => {
32+
mock.onGet(`${URL}/accommodations/location/123?page=1`)
33+
.reply(500,{response:{Error: 'Internal Error'}})
34+
store.dispatch(getAccommodationsByLocation(123)).then((res)=>{
35+
const action=[{type:'FETCH_ACCOMMODATIONS_BY_LOCATION',payload:fetchAccommodationByLocationPayload.accommodations,nation:fetchAccommodationByLocationPayload.nation,id:123}]
36+
expect(store.getActions().type).toEqual(action.type)
37+
}).catch(err=>{
38+
const action=[{type:'FETCH_AMENITIES_ERROR',error:err}]
39+
expect(store.getActions().type).toEqual(action.type)
40+
})
41+
})
42+
43+
// it('Get one accommodation from the list of accommodations', () => {
44+
// store.dispatch(selectAccommodation(2121222)).then((res)=>{
45+
// const action=[{type:'SELECT_ACCOMMODATION',payload:2121222}]
46+
// expect(store.getActions().type).toEqual(action.type)
47+
// })
48+
// })
49+
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {getTemperature} from '../../../src/redux/actions/getWeather';
4+
import moxios from 'moxios';
5+
import axios from 'axios';
6+
import MockAdapter from 'axios-mock-adapter';
7+
8+
const URL =process.env.REACT_APP_BACKEND_LINK
9+
const middlewares = [thunk]
10+
const mockStore = configureStore(middlewares);
11+
let store=mockStore({});
12+
let mock = new MockAdapter(axios)
13+
describe('Fetch accommodations actions', () => {
14+
15+
beforeEach(() => {
16+
moxios.install()
17+
store = mockStore({fetchAccommodations: {}})
18+
})
19+
afterEach(() => moxios.uninstall())
20+
21+
it('Get waither condition of a place', () => {
22+
mock.onGet(`${URL}/weather/weather?city=kigali`)
23+
.reply(200,{response:{info:{main:{temp:23}}}})
24+
store.dispatch(getTemperature('Kigali')).then((res)=>{
25+
const action=[{type:'FETCH_WEATHER_SUCCESS',payload:23}]
26+
expect(store.getActions().type).toEqual(action.type)
27+
})
28+
})
29+
30+
it('Get waither condition of a place failed', () => {
31+
mock.onGet(`${URL}/weather/weather?city=kigali`)
32+
.reply(500,{response:{Error: 'Internal Error'}})
33+
store.dispatch(getTemperature('Kigali')).then((res)=>{
34+
const action=[{type:'FETCH_WEATHER_SUCCESS',payload:23}]
35+
expect(store.getActions().type).toEqual(action.type)
36+
}).catch(err=>{
37+
const action=[{type:'FETCH_WEATHER_ERROR',error:err}]
38+
expect(store.getActions().type).toEqual(action.type)
39+
})
40+
})
41+
42+
})

0 commit comments

Comments
 (0)