nails-boilerplate 2.0.8 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sequelize_connector.js +3 -0
- package/package.json +1 -1
- package/spec/sequelize_connector.spec.js +54 -2
- package/templates/bin/start.sh +8 -1
- package/templates/config/routes.js +4 -2
- package/templates/package-lock.json +1458 -1036
- package/templates/package.json +19 -19
- package/templates/spec/User.test.js +19 -0
- package/templates/spec/home_controller.test.js +27 -0
- package/templates/spec/setupTests.js +0 -0
- package/templates/vite.config.ts +4 -3
- package/templates/spec/home_controller.spec.js +0 -19
- /package/templates/server/models/{user.js → User.js} +0 -0
|
@@ -16,6 +16,9 @@ export default class SequelizeConnector extends DbConnector {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
generateModelSuperclass(name, options) {
|
|
19
|
+
if (options.schema) {
|
|
20
|
+
return this.sequelize.define(name, options.schema, options.options);
|
|
21
|
+
}
|
|
19
22
|
return this.sequelize.define(name, options);
|
|
20
23
|
}
|
|
21
24
|
|
package/package.json
CHANGED
|
@@ -14,6 +14,22 @@ const TEST_SCHEMA = {
|
|
|
14
14
|
cash: DataTypes.INTEGER,
|
|
15
15
|
}
|
|
16
16
|
let TestSequelizeModel = null;
|
|
17
|
+
let TestSequelizeIndexedModel = null;
|
|
18
|
+
|
|
19
|
+
const TEST_OPTIONS = {
|
|
20
|
+
schema: {
|
|
21
|
+
label: DataTypes.STRING,
|
|
22
|
+
value: DataTypes.STRING,
|
|
23
|
+
},
|
|
24
|
+
options: {
|
|
25
|
+
indexes: [
|
|
26
|
+
{
|
|
27
|
+
unique: true,
|
|
28
|
+
fields: ['label', 'value'],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
17
33
|
|
|
18
34
|
describe('ModelV2 using SequelizeConnector', function() {
|
|
19
35
|
let util;
|
|
@@ -22,8 +38,9 @@ describe('ModelV2 using SequelizeConnector', function() {
|
|
|
22
38
|
const connector = await util.getTestConnector();
|
|
23
39
|
Model.setConnector(connector);
|
|
24
40
|
TestSequelizeModel =
|
|
25
|
-
class TestSequelizeModel extends new Model("TestSequelizeModel", TEST_SCHEMA) {
|
|
26
|
-
|
|
41
|
+
class TestSequelizeModel extends new Model("TestSequelizeModel", TEST_SCHEMA) {};
|
|
42
|
+
TestSequelizeIndexedModel =
|
|
43
|
+
class TestSequelizeIndexedModel extends new Model("TestSequelizeIndexedModel", TEST_OPTIONS) {};
|
|
27
44
|
await connector.sequelize.sync({ force: true });
|
|
28
45
|
});
|
|
29
46
|
|
|
@@ -36,4 +53,39 @@ describe('ModelV2 using SequelizeConnector', function() {
|
|
|
36
53
|
assert(models[0].name == MODEL_NAME, "Name should be consistent");
|
|
37
54
|
assert(models[0] instanceof TestSequelizeModel);
|
|
38
55
|
});
|
|
56
|
+
|
|
57
|
+
it("Should be able to create, save, and retrieve a complex model", async function() {
|
|
58
|
+
const MODEL_LABEL = "First test model LABEL";
|
|
59
|
+
const MODEL_VALUE = "First test model VALUE";
|
|
60
|
+
const testModel = await TestSequelizeIndexedModel.create({label: MODEL_LABEL, value: MODEL_VALUE});
|
|
61
|
+
const models = await TestSequelizeIndexedModel.findAll();
|
|
62
|
+
assert(models.length == 1, "Should have one model");
|
|
63
|
+
assert(models[0].label == MODEL_LABEL, "label should be persisted");
|
|
64
|
+
assert(models[0].value == MODEL_VALUE, "value should be persisted");
|
|
65
|
+
assert(models[0] instanceof TestSequelizeIndexedModel);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("Should be able to respect unique indexes", async function() {
|
|
69
|
+
const MODEL_LABEL_0 = "MODEL_LABEL_0";
|
|
70
|
+
const MODEL_VALUE_0 = "MODEL_VALUE_0";
|
|
71
|
+
const MODEL_LABEL_1 = "MODEL_LABEL_1";
|
|
72
|
+
const MODEL_VALUE_1 = "MODEL_VALUE_1";
|
|
73
|
+
const testModels = await TestSequelizeIndexedModel.bulkCreate(
|
|
74
|
+
[
|
|
75
|
+
{label: MODEL_LABEL_0, value: MODEL_VALUE_0},
|
|
76
|
+
{label: MODEL_LABEL_0, value: MODEL_VALUE_1},
|
|
77
|
+
{label: MODEL_LABEL_1, value: MODEL_VALUE_0},
|
|
78
|
+
{label: MODEL_LABEL_1, value: MODEL_VALUE_1},
|
|
79
|
+
]
|
|
80
|
+
);
|
|
81
|
+
assert(testModels.length == 4, "Should creaete 4 models");
|
|
82
|
+
let indexWasRespected = true;
|
|
83
|
+
try {
|
|
84
|
+
await TestSequelizeIndexedModel.create({label: MODEL_LABEL_0, value: MODEL_VALUE_0});
|
|
85
|
+
indexWasRespected = false;
|
|
86
|
+
} catch(e) {
|
|
87
|
+
console.log("Error was thrown as expected");
|
|
88
|
+
}
|
|
89
|
+
assert(indexWasRespected, "Should have thrown an error")
|
|
90
|
+
});
|
|
39
91
|
});
|
package/templates/bin/start.sh
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
SCRIPT_DIR=$(dirname "$0")
|
|
2
2
|
echo "Script directory (relative): $SCRIPT_DIR"
|
|
3
3
|
|
|
4
|
+
COMMAND=$1
|
|
5
|
+
if [[ -z "${COMMAND}" ]]; then
|
|
6
|
+
COMMAND=start
|
|
7
|
+
else
|
|
8
|
+
echo "COMMAND is NOT empty."
|
|
9
|
+
fi
|
|
10
|
+
|
|
4
11
|
|
|
5
12
|
SCRIPT_PATH=$(readlink -f "$0")
|
|
6
13
|
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
|
7
14
|
echo "Script directory (absolute, resolved): $SCRIPT_DIR"
|
|
8
15
|
|
|
9
|
-
npm --prefix=$SCRIPT_DIR/..
|
|
16
|
+
npm --prefix=$SCRIPT_DIR/.. run $COMMAND
|
|
@@ -22,10 +22,12 @@ export default [
|
|
|
22
22
|
['get', "/", {controller: 'home'}],
|
|
23
23
|
// Routes all requests starting with /public as static requests to the public folder.
|
|
24
24
|
['get', '/public', {public: true}],
|
|
25
|
+
|
|
25
26
|
// A test route which routes the first part of pathname to controller and the second to the action
|
|
26
|
-
['get', /^\/(\w+)\/(\w+)$/i, {0: 'controller', 1: 'action'}],
|
|
27
|
+
// ['get', /^\/(\w+)\/(\w+)$/i, {0: 'controller', 1: 'action'}],
|
|
28
|
+
|
|
27
29
|
// Maps the first two parts of the path to controller and action, and the third to the id parameter
|
|
28
|
-
['get', "/:controller/:action/:id"],
|
|
30
|
+
// ['get', "/:controller/:action/:id"],
|
|
29
31
|
|
|
30
32
|
// For all other GET requests, render HomeController#index
|
|
31
33
|
['get', '/:catchall', {controller: 'home'}],
|