ioBroker/testing

Feature Request "setup of native objects for adapter initialization" (#218 proposal not working anymore)

Closed this issue · 3 comments

using the 2.5.4 version makes the tests with configuring the native objects crashing.

I used the following workaround in for setup in iobroker.fritzdect

					harness._objects.getObject('system.adapter.fritzdect.0', async (err, obj) => {
						obj.native.fritz_ip = 'http://localhost:3333';
						obj.native.fritz_user = 'admin';
						obj.native.fritz_pw = encrypt('Zgfr56gFe87jJOM', 'password');
						obj.native.fritz_interval = 300;
						obj.native.fritz_strictssl = true;
						await harness._objects.setObjectAsync(obj._id, obj);

						// Start the adapter and wait until it has started
						await harness.startAdapterAndWait();

or in iobroker.musiccast

					harness._objects.getObject('system.adapter.musiccast.0', async (err, obj) => {
						obj.native.devices = [
							{
								ip: 'localhost:3311',
								type: 'YSP-1600',
								uid: '00112233',
								sid: '00A0FED15025',
								name: 'TestGerät'
							}
						];
						await harness._objects.setObjectAsync(obj._id, obj);

						// Start the adapter and wait until it has started
						await harness.startAdapterAndWait();

when the automatic testing starts, it errors:

     TypeError: Cannot read property 'getObject' of undefined

How to setup my environment now?

maybe #218 is now outdated and needs an update

Hm ... _objects means a private variable name ... so do you think it is a good idea to use that at all? ;-)) So a feature Request would be the way to go :-)

..._objects was exactly the proposal in #218 and now its not working anymore :-(

OK, I will change the title

Old answer

@foxthefox use harness.objects, not harness._objects:

/** Gives direct access to the Objects DB */
public get objects(): any {
if (!this.dbConnection.objectsClient) {
throw new Error("Objects DB is not running");
}
return this.dbConnection.objectsClient;
}
/** Gives direct access to the States DB */
public get states(): any {
if (!this.dbConnection.statesClient) {
throw new Error("States DB is not running");
}
return this.dbConnection.statesClient;
}

Or even better:

Try using changeAdapterConfig, which has been changed to use setObject internally in 2.5.4.