• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SyTW2526 / Proyecto-E19 / 20313093198

17 Dec 2025 06:23PM UTC coverage: 77.46% (-4.1%) from 81.601%
20313093198

push

github

josesuarez4
Arreglo tests

225 of 315 branches covered (71.43%)

Branch coverage included in aggregate %.

96 of 118 new or added lines in 7 files covered. (81.36%)

56 existing lines in 5 files now uncovered.

452 of 559 relevant lines covered (80.86%)

4.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/server/src/models/User.js
1
import mongoose from "mongoose";
2
const { Schema, model } = mongoose;
7✔
3

4
const UserSchema = new Schema({
7✔
5
  name: { type: String, required: true, trim: true, maxlength: 100 },
6
  fullName: { type: String, trim: true, maxlength: 200 },
7
  email: { type: String, required: true, unique: true, lowercase: true, trim: true },
8
  password: { type: String, required: true },
9
  rol: {
10
    type: String,
11
    enum: ["alumno", "profesor", "desarrollador"],
12
    default: "alumno"
13
  },
14
  telefono: { type: String, trim: true },
15
  avatarUrl: { type: String, trim: true },
16
  biography: { type: String, trim: true, maxlength: 1000 },
17
  activo: { type: Boolean, default: true },
18
  asignaturasCursadas: { type: [String], default: [] },
19
}, {
20
  timestamps: true
21
});
22

23
// Índices para mejorar rendimiento
24
// NOTA: No duplicar email aquí (ya tiene unique: true arriba)
25
UserSchema.index({ rol: 1, activo: 1 });
7✔
26
UserSchema.index({ activo: 1 });
7✔
27

28
// Excluir password por defecto en todas las queries
29
UserSchema.set('toJSON', {
7✔
30
  transform: function(doc, ret) {
31
    delete ret.password;
20✔
32
    delete ret.__v;
20✔
33
    return ret;
20✔
34
  }
35
});
36

37
// Método para buscar usuarios activos por rol (optimizado)
38
UserSchema.statics.findActiveByRole = function(role, limit = 50) {
7!
NEW
39
  return this.find({ rol: role, activo: true })
×
40
    .select('-password')
41
    .limit(limit)
42
    .lean();
43
};
44

45
export default model("User", UserSchema);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc