Skip to content

Commit

Permalink
Merge pull request #397 from mStirner/dev
Browse files Browse the repository at this point in the history
 Working on issues
  • Loading branch information
mStirner committed Jan 4, 2024
2 parents 185a480 + 5e32c4f commit 71bdafb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/endpoints/class.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ module.exports = class Command {
//payload: Joi.string().allow(null).default(null),
payload: Joi.alternatives().try(Joi.string(), Joi.binary()).allow(null).default(null),
description: Joi.string().allow(null).default(null),
params: Joi.array().items(Param.schema())
params: Joi.array().items(Param.schema()).default([])
});
}

Expand Down
3 changes: 2 additions & 1 deletion components/scenes/class.scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ module.exports = class Scene extends Item {
name: Joi.string().required(),
makros: Joi.array().items(Makro.schema()).default([]),
triggers: Joi.array().items(Trigger.schema()).default([]),
visible: Joi.boolean().default(true)
visible: Joi.boolean().default(true),
icon: Joi.string().allow(null).default(null)
});
}

Expand Down
8 changes: 5 additions & 3 deletions components/store/class.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ module.exports = class Store extends Item {
_id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => {
return String(new mongodb.ObjectId());
}),
name: Joi.string().required(),
description: Joi.string().allow(null).default(null),
config: Joi.array().min(1).items(Value.schema()).required(),
item: Joi.string().allow(null).default(null),
namespace: Joi.string().default(() => {
//item: Joi.string().allow(null).default(null),
uuid: Joi.string().default(() => {
return uuid.v4();
}),
})
});
}

Expand Down
1 change: 1 addition & 0 deletions components/store/class.value.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Value {
_id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => {
return String(new mongodb.ObjectId());
}),
name: Joi.string().required(),
key: Joi.string().required(),
value: Joi.when("type", {
is: "number",
Expand Down
4 changes: 4 additions & 0 deletions components/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class C_STORE extends COMPONENT {
next(null, new Store(data, this));
});

this.collection.createIndex("uuid", {
unique: true
});

}

}
Expand Down
4 changes: 2 additions & 2 deletions postman.json
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"_id\": \"65818986ca5133d8de2bb4a1\",\n \"config\": [{\n \"_id\": \"6581a14f1c6d01f32129dabc\",\n \"key\": \"pairing\",\n \"type\": \"boolean\",\n \"value\": false,\n \"description\": \"Is the Gateway ready for pairing?\"\n }, {\n \"_id\": \"6581a1520bcb15659d48b207\",\n \"key\": \"interval\",\n \"type\": \"number\",\n \"value\": 3000,\n \"description\": \"Sync intervall for Endpoints\"\n }]\n}",
"raw": "{\n \"name\": \"Store item #1\",\n \"description\": \"Configuration settings for pluginx xyz\",\n \"_id\": \"65818986ca5133d8de2bb4a1\",\n \"config\": [{\n \"_id\": \"6581a14f1c6d01f32129dabc\",\n \"name\": \"Gateway Pairing\",\n \"key\": \"pairing\",\n \"type\": \"boolean\",\n \"value\": false,\n \"description\": \"Is the Gateway ready for pairing?\"\n }, {\n \"_id\": \"6581a1520bcb15659d48b207\",\n \"name\": \"Polling Interval\",\n \"key\": \"interval\",\n \"type\": \"number\",\n \"value\": 3000,\n \"description\": \"Sync intervall for Endpoints\"\n }]\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -2525,7 +2525,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"item\": \"6375343d0b555ccd42460a2e\",\n \"labels\": [\n \"device=65818918d32dad8dab53e433\",\n \"endpoint=658189336fa19198939caa21\"\n ]\n}",
"raw": "{\n \"labels\": [\n \"device=65818918d32dad8dab53e433\",\n \"endpoint=658189336fa19198939caa21\"\n ]\n}",
"options": {
"raw": {
"language": "json"
Expand Down
1 change: 1 addition & 0 deletions system/component/class.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ module.exports = class COMPONENT extends COMMON {

let item = this.items.find((item) => {

// NOTE: rename value to key
return Object.keys(err.keyValue).every((value) => {

// fixing "Duplicate unique key/index in database, but no matching item"
Expand Down
16 changes: 8 additions & 8 deletions tests/components/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ try {
const workflow = require("./test.workflow.js");

let _id = String(new mongodb.ObjectId());
let namespace = String(new mongodb.ObjectId());
let uuid = uuidv4();

workflow(C_COMPONENT, "add", (done, { event }) => {
C_COMPONENT.add({
_id,
name: "Test store",
description: "Test item for unit tests",
config: [{
name: "Test Key",
key: "key",
type: "string",
description: "Test key"
}],
namespace
uuid
}, (err, item) => {

// check event arguments
Expand Down Expand Up @@ -57,16 +60,13 @@ try {

workflow(C_COMPONENT, "update", (done) => {

let uuid = uuidv4();

C_COMPONENT.update(_id, {
item: uuid
name: "Updated Name"
}, (err, item) => {
try {

assert.ok(err === null);
assert.equal(item instanceof Store, true);
assert.equal(item.item, uuid);

done(err);

Expand All @@ -85,12 +85,12 @@ try {

// update call 1
C_COMPONENT.update(_id, {
item: uuidv4()
uuid: uuidv4()
}),

// update call 2
C_COMPONENT.update(_id, {
item: uuidv4()
name: "New config/store name"
})

]).then(() => {
Expand Down

0 comments on commit 71bdafb

Please sign in to comment.