feat(professors,sms): merge professor with users, add existing user link, professor portal endpoint, and SMS bypass list
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const mongoose = require('mongoose');
|
||||
const Professor = require('./professorModel');
|
||||
const { formatProfessorDoc } = require('./professorService');
|
||||
|
||||
test('Professor Model & User Merge Tests', async (t) => {
|
||||
await t.test('Professor schema has user reference and virtual getters', () => {
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
const prof = new Professor({
|
||||
user: userId,
|
||||
bio: 'استاد ارشد هوش مصنوعی',
|
||||
expertise: ['Machine Learning', 'Python'],
|
||||
isActive: true
|
||||
});
|
||||
|
||||
assert.equal(String(prof.user), String(userId));
|
||||
assert.equal(prof.bio, 'استاد ارشد هوش مصنوعی');
|
||||
assert.deepEqual(prof.expertise, ['Machine Learning', 'Python']);
|
||||
assert.equal(prof.isActive, true);
|
||||
});
|
||||
|
||||
await t.test('formatProfessorDoc correctly extracts and formats linked user fields', () => {
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
const profId = new mongoose.Types.ObjectId();
|
||||
const mockDoc = {
|
||||
_id: profId,
|
||||
user: {
|
||||
_id: userId,
|
||||
name: 'علی حسینی',
|
||||
nationalIdCode: '0012345678',
|
||||
phoneNumber: '09123456789',
|
||||
email: 'ali@example.com',
|
||||
cardNumber: '6037997112345678',
|
||||
shabaNumber: 'IR120000000000000000000000',
|
||||
isActive: true
|
||||
},
|
||||
bio: 'استاد برنامهنویسی',
|
||||
expertise: ['Web', 'Vue'],
|
||||
courses: [],
|
||||
isActive: true
|
||||
};
|
||||
|
||||
const formatted = formatProfessorDoc(mockDoc);
|
||||
assert.equal(String(formatted._id), String(profId));
|
||||
assert.equal(String(formatted.user), String(userId));
|
||||
assert.equal(formatted.name, 'علی');
|
||||
assert.equal(formatted.surname, 'حسینی');
|
||||
assert.equal(formatted.fullName, 'علی حسینی');
|
||||
assert.equal(formatted.nationalIdCode, '0012345678');
|
||||
assert.equal(formatted.phoneNumber, '09123456789');
|
||||
assert.equal(formatted.email, 'ali@example.com');
|
||||
assert.equal(formatted.cardNumber, '6037997112345678');
|
||||
assert.equal(formatted.shabaNumber, 'IR120000000000000000000000');
|
||||
assert.deepEqual(formatted.expertise, ['Web', 'Vue']);
|
||||
assert.equal(formatted.isActive, true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user