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

u-wave / core / 11085094286

28 Sep 2024 03:39PM UTC coverage: 79.715% (-0.4%) from 80.131%
11085094286

Pull #637

github

web-flow
Merge 11ccf3b06 into 14c162f19
Pull Request #637: Switch to a relational database, closes #549

751 of 918 branches covered (81.81%)

Branch coverage included in aggregate %.

1891 of 2530 new or added lines in 50 files covered. (74.74%)

13 existing lines in 7 files now uncovered.

9191 of 11554 relevant lines covered (79.55%)

68.11 hits per line

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

97.92
/src/models/User.js
1
import mongoose from 'mongoose';
1✔
2
import { slugify } from 'transliteration';
1✔
3

1✔
4
const { Schema } = mongoose;
1✔
5
const { Types } = mongoose.Schema;
1✔
6

1✔
7
/**
1✔
8
 * @typedef {object} LeanBanned
1✔
9
 * @prop {import('mongodb').ObjectId} moderator
1✔
10
 * @prop {number} duration
1✔
11
 * @prop {Date} [expiresAt]
1✔
12
 * @prop {string} reason
1✔
13
 */
1✔
14

1✔
15
/**
1✔
16
 * @typedef {object} LeanUser
1✔
17
 * @prop {import('mongodb').ObjectId} _id
1✔
18
 * @prop {string} username
1✔
19
 * @prop {string} language
1✔
20
 * @prop {string[]} roles
1✔
21
 * @prop {string} avatar
1✔
22
 * @prop {string} slug
1✔
23
 * @prop {import('mongodb').ObjectId|null} activePlaylist
1✔
24
 * @prop {Date} lastSeenAt
1✔
25
 * @prop {LeanBanned|undefined} banned
1✔
26
 * @prop {string|undefined} pendingActivation
1✔
27
 * @prop {Date} createdAt
1✔
28
 * @prop {Date} updatedAt
1✔
29
 * @prop {number} role - Deprecated, do not use
1✔
30
 * @prop {number} level - Deprecated, do not use
1✔
31
 * @prop {boolean} exiled - Deprecated, do not use
1✔
32
 * @typedef {mongoose.Document<LeanUser["_id"], {}, LeanUser> & LeanUser} User
1✔
33
 */
1✔
34

1✔
35
const bannedSchema = new Schema({
1✔
36
  moderator: { type: Types.ObjectId, ref: 'User', index: true },
1✔
37
  duration: { type: Number, required: true },
1✔
38
  expiresAt: { type: Date, required: true, index: true },
1✔
39
  reason: { type: String, default: '' },
1✔
40
});
1✔
41

1✔
42
/**
1✔
43
 * @type {mongoose.Schema<User, mongoose.Model<User, {}, {}>, {}>}
1✔
44
 */
1✔
45
const userSchema = new Schema({
1✔
46
  username: {
1✔
47
    type: String,
1✔
48
    minlength: [3, 'Usernames have to be at least 3 characters long.'],
1✔
49
    maxlength: [32, 'Usernames can be at most 32 characters long.'],
1✔
50
    match: /^[^\s]+$/,
1✔
51
    required: true,
1✔
52
    unique: true,
1✔
53
    index: true,
1✔
54
    /** @type {(name: string) => string} */
1✔
55
    set: (name) => name.normalize('NFKC'),
1✔
56
  },
1✔
57
  language: {
1✔
58
    type: String, min: 2, max: 2, default: 'en',
1✔
59
  },
1✔
60
  roles: [{ type: String, ref: 'AclRole' }],
1✔
61
  // Deprecated, `roles` should be used instead.
1✔
62
  // However some clients (*cough* u-wave-web *cough*) haven't updated to the
1✔
63
  // ACL system so they need this key to exist.
1✔
64
  role: { type: Number, min: 0, default: 0 },
1✔
65
  avatar: {
1✔
66
    type: String, min: 0, max: 256, default: '',
1✔
67
  },
1✔
68
  slug: {
1✔
69
    type: String,
1✔
70
    unique: true,
1✔
71
    required: [true, 'Usernames must not consist of punctuation only.'],
1✔
72
    index: true,
1✔
73
  },
1✔
74
  activePlaylist: {
1✔
75
    type: Types.ObjectId,
1✔
76
    ref: 'Playlist',
1✔
77
  },
1✔
78
  level: {
1✔
79
    type: Number, min: 0, max: 9001, default: 0,
1✔
80
  },
1✔
81
  lastSeenAt: { type: Date, default: () => new Date() },
1✔
82
  exiled: { type: Boolean, default: false },
1✔
83
  banned: bannedSchema,
1✔
84
  pendingActivation: { type: String, required: false },
1✔
85
}, {
1✔
86
  timestamps: true,
1✔
87
  minimize: false,
1✔
88
});
1✔
89

1✔
90
userSchema.pre('validate', function preValidate(next) {
1✔
UNCOV
91
  this.slug = slugify(this.username);
×
UNCOV
92
  next();
×
93
});
1✔
94

1✔
95
export default userSchema;
1✔
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

© 2025 Coveralls, Inc