Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from johanngoltz/dev/scenario-detail-page
Browse files Browse the repository at this point in the history
Dev/scenario detail page
  • Loading branch information
johanngoltz authored Jul 5, 2018
2 parents 14be31e + 60b2f2c commit 9bbf1cb
Show file tree
Hide file tree
Showing 74 changed files with 3,490 additions and 530 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ yarn-error.log
testem.log
/typings
debug.log
*.stackdump

# System Files
.DS_Store
Expand Down
138 changes: 138 additions & 0 deletions mock/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,141 @@ scenario.routes.forEach(function (routeDefinition) {
setDefaultHeaders(routeDefinition.handler, req, res);
});
});

// request tokens
Sandbox.define('/oauth/token', 'POST', function (req, res) {
// Login
if (req.query.grant_type === 'password') {
// Check login credentials
if (!(req.query.email === 'tomastepa@web.de' && req.query.password === '123')) {
return res.send(401, 'Invalid username or password');
}

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200);

// Send the response body.
res.json(
{
access_token: "214vg3hg2v123f123f4ghv",
refresh_token: "dfshbfhb367gfvagfasf",
token_type: "bearer",
expires_in: 1234,
scope: "read write",
jti: "",
id: 1,
}
);
return;
}

// get new access_token
if (req.query.grant_type === 'refresh_token') {
// check if refresh_token is valid
if(req.query.refresh_token !== 'dfshbfhb367gfvagfasf') {
return res.send(401, 'Invalid refresh token');
}

res.type('application/json');
res.status(200);
res.json(
{
access_token: "214vg3hg2v123f123f4ghv_",
refresh_token: "dfshbfhb367gfvagfasf",
token_type: "bearer",
expires_in: 1234,
scope: "read write",
jti: "",
id: 1,
}
);
return;
}
})

// Registration
Sandbox.define('/users', 'POST', function (req, res) {
// Check the request, make sure it is a compatible type
if (!req.is('application/json')) {
return res.send(400, 'Invalid content type, expected application/json');
}

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200); //should be 302

res.json(
{

}
);

})

// Resetpassword
Sandbox.define('/users/{id}', 'PUT', function (req, res) {
// Check the request, make sure it is a compatible type
if (!req.is('application/json')) {
return res.send(400, 'Invalid content type, expected application/json');
}

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200);

res.json(
{

}
);

})

// request new password
Sandbox.define('/users/forgot', 'POST', function (req, res) {
// Check the request, make sure it is a compatible type
if (!req.is('application/json')) {
return res.send(400, 'Invalid content type, expected application/json');
}

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200);

res.json(
{

}
);

})

// set new password after requesting a new one
Sandbox.define('/users/reset/token', 'POST', function (req, res) {
// Check the request, make sure it is a compatible type
if (!req.is('application/json')) {
return res.send(400, 'Invalid content type, expected application/json');
}

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200);

res.json(
{

}
);

})
11 changes: 9 additions & 2 deletions mock/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ exports.routes = [{
verb: 'GET',
handler: function (req, res) {
res.json(state.scenarios);

// Interceptor test
if(req.headers.Authorization === undefined || req.headers.Authorization !== 'bearer 214vg3hg2v123f123f4ghv_') {
return res.send(401, 'Invalid token at /scenario');
}
},
},
{
route: '/scenario',
verb: 'POST',
handler: function (req, res) {
req.body.id = Math.round(Math.random()*99999);
state.scenarios.push(req.body)
res.json(req.body);
res.status(201);
Expand All @@ -36,11 +42,12 @@ exports.routes = [{
route: '/scenario/:sId',
verb: 'DELETE',
handler: function (req, res) {
var sId = parseInt(req.params.sId);
state.scenarios.splice(
utils.findIndex(state.scenarios, function (scenario) {
return scenario.id === req.params.sId;
return scenario.id === sId;
}),
0);
1);
res.send(true);
}
}
Expand Down
Loading

0 comments on commit 9bbf1cb

Please sign in to comment.