forked from heiko-braun/redhat_access_angular_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest-mock-server.js
49 lines (41 loc) · 1.36 KB
/
rest-mock-server.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//See http://expressjs.com/3x/api.html
express = require('express');
var app = express();
app.use(express.bodyParser());
//Case attachment mocks
app.get('/attachments', function (req, res) {
res.send('Main Server SOS Report?checked=true\n/Database Log?checked=true\n/Debug/katello-debug.log\n/Debug/Level3/foreman.debug\nFail-409\nFail-500');
});
app.post('/attachments', function (req, res) {
console.log(req.body.attachment);
if (req.body.attachment === 'Fail-500') {
res.status(500);
}
if (req.body.attachment === 'Fail-409') {
res.status(409);
}
var respond = function () {
res.json({
'foo': 'myMockJSON'
});
}
setTimeout(respond, 1000);
});
//Log Viewer mocks
app.get('/machines', function (req, res) {
res.send("[ \"RHEV Manager\", \"Hypervisor 1\", \"Hypervisor 2\"]");
});
app.get('/logs', function (req, res) {
var path = req.query.path;
if (path == null) {
res.send('/root/sub1/sub2\n/root2/sub21/sub22\n/root3/sub31/sub32\n/root3/sub31/sub34\n/Fail\n');
} else {
if (path.indexOf("Fail") > -1) {
res.status(401);
res.send("Not authorized");
} else {
res.send('Mock file text fdsafdsafjklsdjfkldsjfkldsjfkldsjfkldsjklfjdsklafjkldsajfkldsajfkl;dsajfkl;dsjaklfjasdklfjdsklfjkldsajfkdasjfkljsdaklfjasdklfjkldsajfkdlsajfkldsjfkldsajfkldsajfklasdfjkl;asdfjkldsa');
}
}
});
module.exports = app