Skip to content

Commit 4641590

Browse files
committed
I have merged with changes from develop branch
2 parents 8ca59e4 + 2a0fde7 commit 4641590

File tree

123 files changed

+72989
-694
lines changed

Some content is hidden

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

123 files changed

+72989
-694
lines changed
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import * as actions from '../../src/redux/actions/createAccAction';
4+
import moxios from 'moxios';
5+
import { accomodation } from '../../dummyData'
6+
7+
const middleware = [thunk];
8+
const mockStore = configureStore(middleware);
9+
10+
describe('Create accomodation', () => {
11+
let store;
12+
const accBody= {
13+
country: "Dubai",
14+
city: "Dubai",
15+
state: "Al Hilal",
16+
streetAddress: "St 21, Dub, UAE",
17+
locationID: "0880b2d1-662c-4782-8aed-252fdd0644c4",
18+
propertyType: "Motel",
19+
numberOfRooms: 12,
20+
price: 123000,
21+
typeOfBed: "single",
22+
title: "Dubai rest view hotel",
23+
description: "This the best place for tourists to rest in Dubai",
24+
photos: "https://res.cloudinary.com/nowo-ltd/image/upload/v1616179879/barefoot%20uploads/txmzilh8lxwv4u63mvz3.jpg",
25+
26+
};
27+
const amenities= {
28+
wifi: true,
29+
airConditioner: false,
30+
shampoo: false,
31+
ironing: false,
32+
tv: true,
33+
smokeDetector: false,
34+
fireExtinguisher: false,
35+
lockOnDoor: false,
36+
};
37+
38+
beforeEach(() => {
39+
moxios.install()
40+
store = mockStore({ createAcc: {} })
41+
});
42+
43+
afterEach(() => moxios.uninstall());
44+
45+
46+
it('Creates accomodation successfully', () => {
47+
48+
49+
moxios.wait(() => {
50+
const request = moxios.requests.at(0)
51+
request.respondWith({
52+
status: 200,
53+
response: {accommodation: accomodation }
54+
});
55+
moxios.wait(() => {
56+
const request = moxios.requests.at(1)
57+
request.respondWith({
58+
status: 200,
59+
response: amenities
60+
});
61+
});
62+
});
63+
64+
65+
66+
67+
68+
69+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
70+
const expectedActions = store.getActions();
71+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING');
72+
expect(expectedActions[1].type).toEqual('CREATE_ACC_SUCCESS');
73+
})
74+
75+
});
76+
77+
it('Create Accomodation is unsuccessful with response porperty', () => {
78+
79+
moxios.wait(() => {
80+
const request = moxios.requests.at(0)
81+
request.reject({
82+
status: 500,
83+
response: {
84+
data: 'Internal server error',
85+
}
86+
})
87+
})
88+
89+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
90+
const expectedActions = store.getActions();
91+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
92+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
93+
})
94+
})
95+
96+
it('Create Accomodation is unsuccessful with message porperty', () => {
97+
98+
moxios.wait(() => {
99+
const request = moxios.requests.at(0)
100+
request.reject({
101+
status: 400,
102+
message: 'network error',
103+
})
104+
})
105+
106+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
107+
const expectedActions = store.getActions();
108+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
109+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
110+
})
111+
})
112+
113+
it('Create accomodation is unsuccessful with requeat porperty', () => {
114+
115+
moxios.wait(() => {
116+
const request = moxios.requests.mostRecent()
117+
request.reject({
118+
status: 403,
119+
request: 'Unathorised',
120+
})
121+
})
122+
123+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
124+
const expectedActions = store.getActions();
125+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
126+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
127+
})
128+
})
129+
130+
it('Create accomodation is unsuccessful with error porperty', () => {
131+
132+
moxios.wait(() => {
133+
const request = moxios.requests.mostRecent()
134+
request.reject({
135+
status: 404,
136+
error: 'resource not found',
137+
})
138+
})
139+
140+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
141+
const expectedActions = store.getActions();
142+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
143+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
144+
})
145+
})
146+
147+
it('update amenities is unsuccessful with response porperty', () => {
148+
149+
moxios.wait(() => {
150+
const request = moxios.requests.at(0)
151+
request.respondWith({
152+
status: 200,
153+
response: {accommodation: accomodation }
154+
});
155+
156+
moxios.wait(() => {
157+
const request = moxios.requests.at(1)
158+
request.reject({
159+
status: 500,
160+
response: {
161+
data: 'Internal server error',
162+
}
163+
})
164+
})
165+
});
166+
167+
168+
169+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
170+
const expectedActions = store.getActions();
171+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
172+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
173+
})
174+
})
175+
176+
it('update amenities is unsuccessful with message porperty', () => {
177+
moxios.wait(() => {
178+
const request = moxios.requests.at(0)
179+
request.respondWith({
180+
status: 200,
181+
response: {accommodation: accomodation }
182+
});
183+
184+
moxios.wait(() => {
185+
const request = moxios.requests.at(1)
186+
request.reject({
187+
status: 400,
188+
message: 'network error',
189+
})
190+
})
191+
});
192+
193+
194+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
195+
const expectedActions = store.getActions();
196+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
197+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
198+
})
199+
})
200+
201+
it('update amenities is unsuccessful with requeat porperty', () => {
202+
moxios.wait(() => {
203+
const request = moxios.requests.at(0)
204+
request.respondWith({
205+
status: 200,
206+
response: {accommodation: accomodation }
207+
});
208+
209+
moxios.wait(() => {
210+
const request = moxios.requests.at(1)
211+
request.reject({
212+
status: 403,
213+
request: 'Unathorised',
214+
})
215+
})
216+
217+
});
218+
219+
220+
221+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
222+
const expectedActions = store.getActions();
223+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
224+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
225+
})
226+
})
227+
228+
it('update amenities is unsuccessful with error porperty', () => {
229+
230+
moxios.wait(() => {
231+
const request = moxios.requests.at(0)
232+
request.respondWith({
233+
status: 200,
234+
response: {accommodation: accomodation }
235+
});
236+
237+
moxios.wait(() => {
238+
const request = moxios.requests.at(1)
239+
request.reject({
240+
status: 404,
241+
error: 'resource not found',
242+
})
243+
})
244+
245+
});
246+
247+
248+
249+
return store.dispatch(actions.createAccomodation(accBody,amenities)).then(() => {
250+
const expectedActions = store.getActions();
251+
expect(expectedActions[0].type).toEqual('CREATE_ACC_PENDING')
252+
expect(expectedActions[1].type).toEqual('CREATE_ACC_ERROR')
253+
})
254+
})
255+
256+
257+
})
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import * as actions from '../../src/redux/actions/createLocAction';
4+
import moxios from 'moxios';
5+
import { location } from '../../dummyData'
6+
7+
const middleware = [thunk];
8+
const mockStore = configureStore(middleware);
9+
10+
describe('Create Location', () => {
11+
let store;
12+
13+
beforeEach(() => {
14+
moxios.install()
15+
store = mockStore({ fetchUserProfile: {} })
16+
});
17+
18+
afterEach(() => moxios.uninstall());
19+
20+
21+
it('Creates Location successfully', () => {
22+
moxios.wait(() => {
23+
const request = moxios.requests.mostRecent()
24+
request.respondWith({
25+
status: 200,
26+
response: location
27+
});
28+
});
29+
30+
return store.dispatch(actions.createLocation()).then(() => {
31+
const expectedActions = store.getActions();
32+
expect(expectedActions[0].type).toEqual('CREATE_LOC_PENDING');
33+
expect(expectedActions[1].type).toEqual('CREATE_LOC_SUCCESS');
34+
})
35+
36+
});
37+
38+
it('Create Location is unsuccessful with response porperty', () => {
39+
40+
moxios.wait(() => {
41+
const request = moxios.requests.mostRecent()
42+
request.reject({
43+
status: 500,
44+
response: {
45+
data: 'Internal server error',
46+
}
47+
})
48+
})
49+
50+
return store.dispatch(actions.createLocation()).then(() => {
51+
const expectedActions = store.getActions();
52+
expect(expectedActions[0].type).toEqual('CREATE_LOC_PENDING')
53+
expect(expectedActions[1].type).toEqual('CREATE_LOC_ERROR')
54+
})
55+
})
56+
57+
it('Create Location is unsuccessful with message porperty', () => {
58+
59+
moxios.wait(() => {
60+
const request = moxios.requests.mostRecent()
61+
request.reject({
62+
status: 400,
63+
message: 'network error',
64+
})
65+
})
66+
67+
return store.dispatch(actions.createLocation()).then(() => {
68+
const expectedActions = store.getActions();
69+
expect(expectedActions[0].type).toEqual('CREATE_LOC_PENDING')
70+
expect(expectedActions[1].type).toEqual('CREATE_LOC_ERROR')
71+
})
72+
})
73+
74+
it('Create Location is unsuccessful with requeat porperty', () => {
75+
76+
moxios.wait(() => {
77+
const request = moxios.requests.mostRecent()
78+
request.reject({
79+
status: 403,
80+
request: 'Unathorised',
81+
})
82+
})
83+
84+
return store.dispatch(actions.createLocation()).then(() => {
85+
const expectedActions = store.getActions();
86+
expect(expectedActions[0].type).toEqual('CREATE_LOC_PENDING')
87+
expect(expectedActions[1].type).toEqual('CREATE_LOC_ERROR')
88+
})
89+
})
90+
91+
it('Create Location is unsuccessful with error porperty', () => {
92+
93+
moxios.wait(() => {
94+
const request = moxios.requests.mostRecent()
95+
request.reject({
96+
status: 404,
97+
error: 'resource not found',
98+
})
99+
})
100+
101+
return store.dispatch(actions.createLocation()).then(() => {
102+
const expectedActions = store.getActions();
103+
expect(expectedActions[0].type).toEqual('CREATE_LOC_PENDING')
104+
expect(expectedActions[1].type).toEqual('CREATE_LOC_ERROR')
105+
})
106+
})
107+
108+
109+
})

__tests__/actions/signupAction.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import { user } from '../../dummyData'
66
import moxios from 'moxios'
77
import MockAdapter from 'axios-mock-adapter';
88
import axios from 'axios';
9-
import { request } from 'express';
109

11-
const URL =process.env.REACT_APP_BACKEND_LINK
1210
const middlewares = [thunk]
1311
const mockStore = configureStore(middlewares);
1412
let store=mockStore({});
1513
let mock = new MockAdapter(axios)
1614
const nextStep = jest.fn();
1715

1816
describe('Fetch Signup actions', () => {
19-
17+
let store;
18+
2019
beforeEach(() => {
2120
moxios.install()
22-
store = mockStore({signup: {}})
21+
store = mockStore({fetchLocations: {}})
2322
})
2423
afterEach(() => moxios.uninstall())
2524

0 commit comments

Comments
 (0)