Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object does not exists in mock database after test #48

Open
paveltsytovich opened this issue May 2, 2019 · 4 comments
Open

Object does not exists in mock database after test #48

paveltsytovich opened this issue May 2, 2019 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@paveltsytovich
Copy link

Hi,

I want to check my code for correct remove object from iobroker database. I have following preset objects:

predefinedObjects: [
		{
			'_id': 'noolitef.0.testlamp', 
			'type': 'channel',
			// @ts-ignore
			'parent': 'noolitef.0',        
			 'children': [
				'noolitef.0.testlamp.status',
				'noolitef.0.testlamp.channel'
			 ],
			'common': {
				'name':  'testlamp',      
				'role':  'light.switch',         
				'desc':  'fill comment for test purpose'                     
			}
		 },
		 {
			'_id': 'noolitef.0.badlamp', 
			'type': 'channel',
			// @ts-ignore
			'parent': 'noolitef.0',         
			 'children': [
				'noolitef.0.badlamp.status',
				'noolitef.0.baslamp.channel'
			 ],
			'common': {
				'name':  'badlamp',      
				'role':  'light.switch',          
				'desc':  'fill comment for test purpose'                   
			}
		 }
	],
	predefinedStates: {
		'noolitef.0.testlamp.status' : {'val' :false, 'ack':false},
		'noolitef.0.testlamp.channel' : {'val' :1, 'ack' : false}
	}

In main.js I do nothing and then I try to check exits object in database:

const result = database.hasObject('noolitef.0.badlamp');

The 'result' is false. I think that object 'noolitef.0.badlamp' must be exists and 'result' must be 'true'

@AlCalzone
Copy link
Collaborator

I'll check it out. Can you share a permalink to your repo where this fails?

@AlCalzone AlCalzone self-assigned this May 2, 2019
@AlCalzone AlCalzone added the bug Something isn't working label May 2, 2019
@AlCalzone
Copy link
Collaborator

For the tests you define inside defineAdditionalTests, you need to add your own before[Each] handler to populate the DBs, see documentation:

    // Define your own tests inside defineAdditionalTests. 
    // If you need predefined objects etc. here, you need to take care of it yourself
    defineAdditionalTests() {
        // ...
    },

But I think that is not what you want. You want to perform the adapter startup and then assert certain things, correct?
I would need to add another hook to the startup test then. Before I do, I want to make sure that is what you need.

@paveltsytovich
Copy link
Author

Yes. I want sync object from config with iobroker database during adapter is starting. As admin I can remove some object or add in config via index_m.html page, and then I want remove or add objects in iobroker database accoring my config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants