Skip to content

Commit ae3b8b0

Browse files
Merge pull request #26 from marcoaraujojunior/develop
Added stub json headers
2 parents 4d5585a + 014df3b commit ae3b8b0

File tree

12 files changed

+166
-13
lines changed

12 files changed

+166
-13
lines changed

app/constants/Server.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/services/Area.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ const Area = {
77
},
88

99
getConfig() {
10-
return {
10+
let config = {
1111
headers: {
1212
Authorization : window.localStorage.getItem('token')
13-
}
13+
},
14+
data: {}
1415
};
16+
17+
if (jsonStubHeaders != undefined && jsonStubHeaders != '') {
18+
Object.assign(config.headers, JSON.parse(jsonStubHeaders));
19+
}
20+
return config;
1521
},
1622

1723
getAll() {

app/services/Client.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ const Client = {
77
},
88

99
getConfig() {
10-
return {
10+
let config = {
1111
headers: {
1212
Authorization : window.localStorage.getItem('token')
13-
}
13+
},
14+
data: {}
1415
};
16+
17+
if (jsonStubHeaders != undefined && jsonStubHeaders != '') {
18+
Object.assign(config.headers, JSON.parse(jsonStubHeaders));
19+
}
20+
return config;
1521
},
1622

1723
getClients() {

app/services/User.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import axios from 'axios';
22

33
const User = {
4+
5+
getConfig() {
6+
let config = {
7+
headers: {
8+
}
9+
};
10+
11+
if (jsonStubHeaders != undefined && jsonStubHeaders != '') {
12+
Object.assign(config.headers, JSON.parse(jsonStubHeaders));
13+
}
14+
return config;
15+
},
16+
417
login(username, password) {
518
let auth = {
619
username: username,
720
password: password
821
};
9-
return axios.post(`${HOST}/authenticate`, auth);
22+
return axios.post(`${HOST}/authenticate`, auth, this.getConfig());
1023
}
1124
};
1225

app/services/Visit.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ const Visit = {
77
},
88

99
getConfig() {
10-
return {
10+
let config = {
1111
headers: {
1212
Authorization : window.localStorage.getItem('token')
13-
}
13+
},
14+
data: {}
1415
};
16+
17+
if (jsonStubHeaders != undefined && jsonStubHeaders != '') {
18+
Object.assign(config.headers, JSON.parse(jsonStubHeaders));
19+
}
20+
return config;
1521
},
1622

1723
getGroupByArea() {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
],
4949
"collectCoverage": true,
5050
"globals": {
51-
"HOST": "http://localhost:3000"
51+
"HOST": "http://localhost:3000",
52+
"jsonStubHeaders": ""
5253
},
5354
"moduleNameMapper": {
5455
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/__mocks__/fileMock.js",

public/service-worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var CACHE_NAME = 'v1::iClient';
22
var urlsToCache = [
33
'/',
4-
'/index.html',
5-
'/dist/bundle.min.js',
6-
'/favicons/favicon-16x16.png',
4+
'index.html',
5+
'dist/bundle.min.js',
6+
'favicons/favicon-16x16.png',
77
'https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-with-addons.min.js',
88
'https://cdnjs.cloudflare.com/ajax/libs/react-router/2.8.1/ReactRouter.min.js',
99
'https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.min.js',

tests/Area.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,35 @@ describe('Test Area', () => {
8989
}, 0);
9090
});
9191

92+
it('Should show headers to stub json', (done) => {
93+
94+
let response = require('AreasResponseMock').default;
95+
let Area;
96+
let component;
97+
let mockAdapter = new MockAdapter(axios);
98+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
99+
100+
mockAdapter.onGet(HOST + '/api/v1/visit/group/area').reply(200, response);
101+
102+
Area = require('components/Area/Area').default;
103+
104+
component = shallow(
105+
<Area />
106+
);
107+
108+
setTimeout(() => {
109+
expect(
110+
shallow(
111+
component.state().areas[0]
112+
).find('.title').at(0).text()
113+
).toEqual('Center');
114+
expect(
115+
shallow(
116+
component.state().areas[1]
117+
).find('.title').at(0).text()
118+
).toEqual('South');
119+
done();
120+
}, 0);
121+
});
122+
92123
});

tests/List.Area.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,35 @@ describe('Test Area', () => {
101101
}, 0);
102102
});
103103

104+
it('Should show headers to stub json', (done) => {
105+
let response = {
106+
areas: [
107+
{_id: 'South', parent: 'Center', ancestors: 'Center'},
108+
{_id: 'North', parent: 'Center', ancestors: 'Center'},
109+
]
110+
};
111+
let Area;
112+
let component;
113+
let mockAdapter = new MockAdapter(axios);
114+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
115+
116+
mockAdapter.onGet(HOST + '/api/v1/area').reply(200, response);
117+
118+
Area = require('components/Area/List/Area').default;
119+
120+
component = shallow(
121+
<Area />
122+
);
123+
124+
setTimeout(() => {
125+
try {
126+
component.update();
127+
expect(component.find('tbody td').at(0).text()).toEqual('South');
128+
done();
129+
} catch (e) {
130+
console.log(e);
131+
}
132+
}, 0);
133+
});
104134
});
105135

tests/List.Client.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,34 @@ describe('Test Client', () => {
8989
}, 0);
9090
});
9191

92+
it('Should show headers to stub json', (done) => {
93+
94+
let response = {
95+
clients: [
96+
{name: 'Jon Snow', address: '7 Street', city: 'Winterfell'},
97+
{name: 'Cotter Pyke', address: '0 Street', city: 'Castle Black'},
98+
]
99+
};
100+
let Client;
101+
let component;
102+
let mockAdapter = new MockAdapter(axios);
103+
jsonStubHeaders = '{ "JsonStub-User-Key": "user-key", "JsonStub-Project-Key": "project-key" }';
104+
105+
mockAdapter.onGet(HOST + '/api/v1/client').reply(200, response);
106+
107+
Client = require('components/Client/List/Client').default;
108+
109+
component = shallow(
110+
<Client />
111+
);
112+
113+
setTimeout(() => {
114+
component.update();
115+
expect(component.find('tbody td').at(0).text()).toEqual('Jon Snow');
116+
expect(component.find('tbody td').at(1).text()).toEqual('7 Street - Winterfell');
117+
done();
118+
}, 0);
119+
});
120+
92121
});
93122

0 commit comments

Comments
 (0)