fix(professors, settings): add auto-migration for legacy professors, deep populate user in class/session/course services, and fix SMS bypass number persistence

This commit is contained in:
2026-08-26 05:17:41 +03:30
parent 0a022c0917
commit 43404f2dfc
12 changed files with 337 additions and 57 deletions
@@ -57,4 +57,45 @@ test('Professor Model & User Merge Tests', async (t) => {
assert.deepEqual(formatted.expertise, ['Web', 'Vue']);
assert.equal(formatted.isActive, true);
});
await t.test('formatProfessorDoc handles legacy documents without linked user', () => {
const profId = new mongoose.Types.ObjectId();
const legacyDoc = {
_id: profId,
name: 'رضا',
surname: 'اکبری',
phoneNumber: '09351234567',
nationalIdCode: '1234567890',
email: 'reza@example.com',
cardNumber: '5022291012345678',
shabaNumber: 'IR980000000000000000000000',
bio: 'مدرس پایگاه داده',
isActive: true
};
const formatted = formatProfessorDoc(legacyDoc);
assert.equal(String(formatted._id), String(profId));
assert.equal(formatted.name, 'رضا');
assert.equal(formatted.surname, 'اکبری');
assert.equal(formatted.fullName, 'رضا اکبری');
assert.equal(formatted.phoneNumber, '09351234567');
assert.equal(formatted.nationalIdCode, '1234567890');
assert.equal(formatted.email, 'reza@example.com');
});
await t.test('Professor virtuals fallback correctly on legacy doc', () => {
const prof = new Professor();
prof._doc = {
name: 'مریم احمدی',
surname: 'احمدی',
phoneNumber: '09121112233',
nationalIdCode: '0076543210',
email: 'maryam@example.com'
};
assert.equal(prof.name, 'مریم احمدی');
assert.equal(prof.surname, 'احمدی');
assert.equal(prof.phoneNumber, '09121112233');
assert.equal(prof.nationalIdCode, '0076543210');
});
});