I’m new to backend programming, I’m following a course to test some tests, and I get the following error: Is there a way to identify and resolve this function error? TypeError: user.reserve is not a function
var mongoose = require('mongoose');
var Equinero = require('../../models/equinero');
var Usuario = require('../../models/usuario');
var Reserva = require('../../models/reserva');
describe("Testing Usuarios", function() {
beforeEach(function(done) {
mongoose.connection.close().then(() => {
var mongoDB = 'mongodb://localhost/testdb';
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error: '));
db.once('open', function () {
console.log('We are connected to test database!');
done();
});
});
});
afterEach(function(done) {
Reserva.deleteMany({}, function(err, success) {
if (err) console.log(err);
Usuario.deleteMany({}, function(err, success) {
if (err) console.log(err);
Equinero.deleteMany({}, function(err, success) {
if (err) console.log(err);
done();
});
});
});
});
describe("Cuando un Usuario reserva una bici", () => {
it("Debe existir la reserva", (done) => {
const usuario = new Usuario({nombre: 'Ezequiel'});
usuario.save();
const equinero = new Equinero({code:1, material: 'cemento', profundidad: '1m', dc: '2m'});
equinero.save();
var hoy = new Date();
var maniana = new Date();
maniana.setDate(hoy.getDate()+1);
usuario.reservar(equinero.id, hoy, maniana, function(err, reserva) {
Reserva.find({}).populate('equinero').populate('usuario').exec(function(err, reservas) {
console.log(reservas[0]);
expect(reservas.length).toBe(1);
expect(reservas[0].diasDeReserva()).toBe(2);
expect(reservas[0].equinero.code).toBe(1);
expect(reservas[0].usuario.nombre).toBe(usuario.nombre);
done();
});
});
});
});
});
I am using spec, jasmine, node js, express