forked from smokeball-tests/javascript-developer-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock-http-interface.js
More file actions
34 lines (29 loc) · 836 Bytes
/
mock-http-interface.js
File metadata and controls
34 lines (29 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const urlPrefix = `http://www.smokeballdev.com`;
const urlToResponseLookup = {
[`${urlPrefix}/arnie0`]: 'Get to the chopper',
[`${urlPrefix}/arnie1`]: 'MY NAME IS NOT QUAID',
[`${urlPrefix}/arnie2`]: `What's wrong with Wolfie?`,
};
const httpRequestMockP = (url) => new Promise((resolve, reject) => {
setTimeout(() => {
const responseData = urlToResponseLookup[url];
if (responseData) {
resolve(responseData);
} else {
reject(new Error('Your request has been terminated'));
}
}, 200);
});
const httpGet = async (url) => {
try {
const message = await httpRequestMockP(url);
return { status: 200, body: JSON.stringify({ message }) };
}
catch (err) {
return { status: 500, body: JSON.stringify({ message: err.message }) };
}
};
module.exports = {
httpGet,
};