-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Describe the bug
When calling the find method, the Herbs2Mongo Repository calls a method of the DataMapper class to convert each line returned into an entity type from @herbsjs/gotu, however, when the function returns, it fills in the fields of the entity that were not returned from the database, with a string containing the word undefined, instead of the javascript type undefined.
This can lead to several failures, since in checker.isEmpty the string "undefined" is not considered empty, while the type undefined is.
To Reproduce
Steps to reproduce the behavior:
- Create a project that uses Herbs2Mongo, configure a User entity with the fields id, nickname, type and password, being the type field of type String.
- Include only id, nickname and password fields.
- Call the find function in the user search usecase.
- The type field will contain a string containing the word undefined
Expected behavior
It is expected that the fields declared in the entity that are not in the database, or are returned as undefined, or that the key is not even included in the return object.
It is up to the user to verify using .isValid() or checking the fields, as well as treating entities that do not have certain fields according to business rules.
Screenshots
Evidence of returning the array of entities containing "undefined" after calling the toEntity method of the DataMapper class.

Location in the DataMapper class where the bug is most likely happening.

Additional context
I found this bug when searching for a list of customers, which had the _id and chat_id fields, but the new version of my product would now have the additional fields: username, group and type.
I would have a business rule to check if type was null or undefined using the herbsjs checker, and then ask those users to update their registration.
As a temporary solution, I changed the check to verify that the resulting string was strictly equal to "undefined"
https://github.com/vitorgamer58/telegram-bot-bovespa-herbs/blob/master/src/domain/usecases/verificaCadastro.js#L60