Skip to content

Commit

Permalink
* try fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed May 27, 2022
1 parent 244cf02 commit c5f13dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ function pushHelper(_id, state) {
history[_id].list.push(state);

const _settings = history[_id][adapter.namespace] || {};
if (_settings && history[_id].list.length > _settings.maxLength) {
const maxLength = _settings.maxLength !== undefined ? _settings.maxLength : parseInt(adapter.config.maxLength, 10) || 960;
if (_settings && history[_id].list.length > maxLength) {
_settings.enableDebugLogs && adapter.log.debug(`moving ${history[_id].list.length} entries from ${_id} to file`);
appendFile(_id, history[_id].list);
}
Expand Down Expand Up @@ -1808,7 +1809,7 @@ function storeStatePushData(id, state, applyRules) {
adapter.log.warn(`storeState: history not enabled for ${id}, so can not apply the rules as requested`);
throw new Error(`history not enabled for ${id}, so can not apply the rules as requested`);
}
history[id] = {};
history[id] = history[id] || {};
}
pushFunc(id, state);
}
Expand Down
20 changes: 20 additions & 0 deletions test/lib/testcases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ function register(it, expect, sendTo, adapterShortName, writeNulls, assumeExisti
sendTo(instanceName, 'getHistory', {
id: `my.own.unknown.value-${customNow}`,
options: {
start: customNow - 10000,
count: 500,
aggregate: 'none'
}
Expand All @@ -1087,6 +1088,25 @@ function register(it, expect, sendTo, adapterShortName, writeNulls, assumeExisti
});
});

it(`Test ${adapterShortName}: storeState error for unknown Id with rules parameter`, function (done) {
this.timeout(25000);

const customNow2 = Date.now();
sendTo(instanceName, 'storeState', {
id: `my.own.unknown.value-${customNow2}`,
rules: true,
state: [
{val: 1, ack: true, ts: customNow2 - 5000},
{val: 2, ack: true, ts: customNow2 - 4000},
{val: 3, ack: true, ts: customNow2 - 3000}
]
}, function (result) {
expect(result.success).to.be.not.ok;
expect(result.error).to.be.equal(`history not enabled for my.own.unknown.value-${customNow2}, so can not apply the rules as requested`);

done();
});
});
}

module.exports.register = register;
Expand Down

0 comments on commit c5f13dd

Please sign in to comment.