Skip to content

Commit f21ec34

Browse files
committed
fix: add test setup
1 parent 7086f83 commit f21ec34

24 files changed

+5229
-112
lines changed

packages/booter-lb3app/package-lock.json

Lines changed: 4534 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/booter-lb3app/package.json

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,28 @@
2222
"debug": "^4.1.1",
2323
"loopback-swagger": "^5.7.2",
2424
"p-event": "^4.1.0",
25-
"swagger2openapi": "^5.2.5"
25+
"swagger2openapi": "^5.2.5",
26+
"loopback": "^3.25.1",
27+
"loopback-boot": "^2.28.0",
28+
"compression": "^1.7.4",
29+
"helmet": "^3.16.0",
30+
"loopback-component-explorer": "^6.3.1"
2631
},
2732
"peerDependencies": {
28-
"@loopback/boot": "^1.1.2",
29-
"@loopback/core": "^1.2.1",
30-
"@loopback/rest": "^1.9.1"
33+
"@loopback/boot": "^1.1.3",
34+
"@loopback/core": "^1.3.0",
35+
"@loopback/rest": "^1.10.0"
3136
},
3237
"devDependencies": {
33-
"@loopback/boot": "^1.1.2",
34-
"@loopback/core": "^1.2.1",
35-
"@loopback/build": "^1.4.0",
36-
"@loopback/rest": "^1.9.1",
37-
"@loopback/testlab": "^1.2.1",
38-
"@loopback/tslint-config": "^2.0.3",
38+
"@loopback/boot": "^1.1.3",
39+
"@loopback/core": "^1.3.0",
40+
"@loopback/context": "^1.9.0",
41+
"@loopback/build": "^1.4.1",
42+
"@loopback/repository": "^1.3.0",
43+
"@loopback/rest": "^1.10.0",
44+
"@loopback/rest-explorer": "^1.1.14",
45+
"@loopback/testlab": "^1.2.2",
46+
"@loopback/tslint-config": "^2.0.4",
3947
"@types/node": "^10.11.2"
4048
},
4149
"keywords": [
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>booter application</title>
6+
7+
<meta charset="utf-8">
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
9+
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
<link rel="shortcut icon" type="image/x-icon" href="//v4.loopback.io/favicon.ico">
11+
12+
<style>
13+
h3 {
14+
margin-left: 25px;
15+
text-align: center;
16+
}
17+
18+
a, a:visited {
19+
color: #3f5dff;
20+
}
21+
22+
h3 a {
23+
margin-left: 10px;
24+
}
25+
26+
a:hover, a:focus, a:active {
27+
color: #001956;
28+
}
29+
30+
.power {
31+
position: absolute;
32+
bottom: 25px;
33+
left: 50%;
34+
transform: translateX(-50%);
35+
}
36+
37+
.info {
38+
position: absolute;
39+
top: 50%;
40+
left: 50%;
41+
transform: translate(-50%, -50%)
42+
}
43+
44+
.info h1 {
45+
text-align: center;
46+
margin-bottom: 0;
47+
}
48+
49+
.info p {
50+
text-align: center;
51+
margin-bottom: 3em;
52+
margin-top: 1em;
53+
}
54+
</style>
55+
</head>
56+
57+
<body>
58+
<div class="info">
59+
<h1>booter</h1>
60+
<p>Version 1.0.0</p>
61+
62+
<h3>OpenAPI spec: <a href="/openapi.json">/openapi.json</a></h3>
63+
<h3>API Explorer: <a href="/explorer">/explorer</a></h3>
64+
</div>
65+
66+
<footer class="power">
67+
<a href="https://v4.loopback.io" target="_blank">
68+
<img src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png" />
69+
</a>
70+
</footer>
71+
</body>
72+
73+
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
module.exports = function(CoffeeShop) {
4+
CoffeeShop.status = function(cb) {
5+
var currentDate = new Date();
6+
var currentHour = currentDate.getHours();
7+
var OPEN_HOUR = 6;
8+
var CLOSE_HOUR = 20;
9+
console.log('Current hour is %d', currentHour);
10+
var response;
11+
if (currentHour >= OPEN_HOUR && currentHour < CLOSE_HOUR) {
12+
response = 'We are open for business.';
13+
} else {
14+
response = 'Sorry, we are closed. Open daily from 6am to 8pm.';
15+
}
16+
cb(null, response);
17+
};
18+
CoffeeShop.remoteMethod('status', {
19+
http: {
20+
path: '/status',
21+
verb: 'get',
22+
},
23+
returns: {
24+
arg: 'status',
25+
type: 'string',
26+
},
27+
});
28+
CoffeeShop.getName = function(shopId, cb) {
29+
CoffeeShop.findById(shopId, function(err, instance) {
30+
var response = 'Name of coffee shop is ' + instance.name;
31+
cb(null, response);
32+
console.log(response);
33+
});
34+
};
35+
CoffeeShop.remoteMethod('getName', {
36+
http: {path: '/getname', verb: 'get'},
37+
accepts: {
38+
arg: 'id',
39+
type: 'number',
40+
required: true,
41+
http: {source: 'query'},
42+
},
43+
returns: {arg: 'name', type: 'string'},
44+
});
45+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name":"CoffeeShop",
3+
"base":"PersistedModel",
4+
"idInjection":true,
5+
"options":{
6+
"validateUpsert":true
7+
},
8+
"properties":{
9+
"name":{
10+
"type":"string",
11+
"required":true
12+
},
13+
"city":{
14+
"type":"string",
15+
"required":true
16+
}
17+
},
18+
"validations":[],
19+
"relations":{},
20+
"acls":[],
21+
"methods":{}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
module.exports = function enableAuthentication(server) {
4+
// enable authentication
5+
server.enableAuth();
6+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
module.exports = function(app) {
4+
app.dataSources.db.automigrate('CoffeeShop', function(err) {
5+
if (err) throw err;
6+
7+
app.models.CoffeeShop.create(
8+
[
9+
{
10+
name: 'Bel Cafe',
11+
city: 'Vancouver',
12+
},
13+
{
14+
name: 'Three Bees Coffee House',
15+
city: 'San Mateo',
16+
},
17+
{
18+
name: 'Caffe Artigiano',
19+
city: 'Vancouver',
20+
},
21+
],
22+
function(err, coffeeShops) {
23+
if (err) throw err;
24+
},
25+
);
26+
});
27+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(app) {
2+
// Install a "/ping" route that returns "pong"
3+
app.get('/ping', function(req, res) {
4+
res.send('pong');
5+
});
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"loopback-component-explorer": {
3+
"mountPath": "/explorer",
4+
"generateOperationScopedModels": true
5+
}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"restApiRoot":"/api",
3+
"host":"0.0.0.0",
4+
"port":3000,
5+
"remoting":{
6+
"context":false,
7+
"rest":{
8+
"handleErrors":false,
9+
"normalizeHttpPath":false,
10+
"xml":false
11+
},
12+
"json":{
13+
"strict":false,
14+
"limit":"100kb"
15+
},
16+
"urlencoded":{
17+
"extended":true,
18+
"limit":"100kb"
19+
},
20+
"cors":false
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"db":{
3+
"name": "db",
4+
"connector": "memory"
5+
}
6+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"initial:before": {
3+
"loopback#favicon": {}
4+
},
5+
"initial": {
6+
"compression": {},
7+
"cors": {
8+
"params": {
9+
"origin": true,
10+
"credentials": true,
11+
"maxAge": 86400
12+
}
13+
},
14+
"helmet#xssFilter": {},
15+
"helmet#frameguard": {
16+
"params": [
17+
"deny"
18+
]
19+
},
20+
"helmet#hsts": {
21+
"params": {
22+
"maxAge": 0,
23+
"includeSubDomains": true
24+
}
25+
},
26+
"helmet#hidePoweredBy": {},
27+
"helmet#ieNoOpen": {},
28+
"helmet#noSniff": {},
29+
"helmet#noCache": {
30+
"enabled": false
31+
}
32+
},
33+
"session": {},
34+
"auth": {},
35+
"parse": {},
36+
"routes": {
37+
"loopback#rest": {
38+
"paths": [
39+
"${restApiRoot}"
40+
]
41+
}
42+
},
43+
"files": {},
44+
"final": {},
45+
"final:after": {}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"_meta":{
3+
"sources":[
4+
"loopback/common/models",
5+
"loopback/server/models",
6+
"../common/models",
7+
"./models"
8+
],
9+
"mixins":[
10+
"loopback/common/mixins",
11+
"loopback/server/mixins",
12+
"../common/mixins",
13+
"./mixins"
14+
]
15+
},
16+
"User":{
17+
"dataSource":"db"
18+
},
19+
"AccessToken":{
20+
"dataSource":"db",
21+
"public":false
22+
},
23+
"ACL":{
24+
"dataSource":"db",
25+
"public":false
26+
},
27+
"RoleMapping":{
28+
"dataSource":"db",
29+
"public":false,
30+
"options":{
31+
"strictObjectIDCoercion":true
32+
}
33+
},
34+
"Role":{
35+
"dataSource":"db",
36+
"public":false
37+
},
38+
"CoffeeShop":{
39+
"dataSource":"db",
40+
"public":true
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
var loopback = require('loopback');
4+
var boot = require('loopback-boot');
5+
6+
var app = (module.exports = loopback());
7+
8+
app.start = function() {
9+
// start the web server
10+
return app.listen(function() {
11+
app.emit('started');
12+
var baseUrl = app.get('url').replace(/\/$/, '');
13+
console.log('Web server listening at: %s', baseUrl);
14+
if (app.get('loopback-component-explorer')) {
15+
var explorerPath = app.get('loopback-component-explorer').mountPath;
16+
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
17+
}
18+
});
19+
};
20+
21+
// Bootstrap the application, configure models, datasources and middleware.
22+
// Sub-apps like REST API are mounted via boot scripts.
23+
boot(app, __dirname, function(err) {
24+
if (err) throw err;
25+
26+
app.use('/express-status', function(req, res, next) {
27+
res.json({running: true});
28+
});
29+
30+
// start the server if `$ node server.js`
31+
if (require.main === module) app.start();
32+
});

0 commit comments

Comments
 (0)