BlinkUX / sequelize-mock

A simple mock interface specifically for testing code relying on Sequelize models
https://sequelize-mock.readthedocs.io
MIT License
139 stars 73 forks source link

findOrCreate returns an Array of Instances intead of just one Instance #72

Open ligreman opened 5 years ago

ligreman commented 5 years ago

Sequelize findOrCreate function looks for one element and if it is found, returns an Array that contains [elementFound, created].

Where elementFound is an Instance and created is a boolean. If the conditions of the query match more than one element, it just returns the first one (array index 0), like noted in the comment:

In the example above, the array spread on line 3 divides the array into its 2 parts and passes them as arguments to the callback function defined beginning at line 39, which treats them as "user" and "created" in this case. (So "user" will be the object from index 0 of the returned array and "created" will equal "true".)

http://docs.sequelizejs.com/manual/models-usage.html

In Sequelize-mock docs the findOrCreate reflects that it returns Promise.<Array.<Instance, Boolean>> but it actually returns Promise.<Array.<Array<Instance>, Boolean>>.

That second Array is not supposed to be there. Must return the 0 index of that array.