v2: user CRUD + schema автозапуск + router тесты — модуль пользователя готов
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
const { resolveContext } = require('./index');
|
||||
let passed = 0, failed = 0;
|
||||
|
||||
function t(name, session, expected) {
|
||||
const res = { _redirect: undefined, redirect(u) { this._redirect = u; } };
|
||||
const req = { session: session || {} };
|
||||
resolveContext(req, res, () => {});
|
||||
|
||||
if (res._redirect !== (expected._redirect || undefined)) {
|
||||
console.log('❌', name, 'redirect:', res._redirect, '!=', expected._redirect);
|
||||
failed++; return;
|
||||
}
|
||||
|
||||
for (const k of Object.keys(expected).filter(k => k !== '_redirect')) {
|
||||
if (JSON.stringify(req[k]) !== JSON.stringify(expected[k])) {
|
||||
console.log('❌', name, k, ':', JSON.stringify(req[k]), '!=', JSON.stringify(expected[k]));
|
||||
failed++; return;
|
||||
}
|
||||
}
|
||||
console.log('✅', name); passed++;
|
||||
}
|
||||
|
||||
t('нет сессии', {}, { _redirect: '/v2/login' });
|
||||
t('нет v2_user', { v2_user: null }, { _redirect: '/v2/login' });
|
||||
|
||||
t('обычный юзер 1 компания', { v2_user: {
|
||||
email: 'u@t.ru', clientId: 'WZ03709', activeClientId: 'WZ03709',
|
||||
allClientIds: ['WZ03709'], companyName: 'test', isAdmin: false, profiles: []
|
||||
}}, { 'v2_email': 'u@t.ru', 'v2_clientId': 'WZ03709', 'v2_isAdmin': false, 'v2_isImpersonated': false, 'v2_impersonatedBy': null });
|
||||
|
||||
t('юзер 2 компании', { v2_user: {
|
||||
email: 'm@t.ru', clientId: 'WZ88888', activeClientId: 'WZ77777',
|
||||
allClientIds: ['WZ88888','WZ77777'], companyName: 'AB', isAdmin: false, profiles: []
|
||||
}}, { 'v2_email': 'm@t.ru', 'v2_clientId': 'WZ77777', 'v2_allClientIds': ['WZ88888','WZ77777'] });
|
||||
|
||||
t('админ adminMode', { v2_user: {
|
||||
email: 'a@t.ru', clientId: 'WZ01112', activeClientId: 'WZ01112',
|
||||
allClientIds: ['WZ01112'], isAdmin: true, profiles: []
|
||||
}, v2_adminMode: true }, { 'v2_email': 'a@t.ru', 'v2_clientId': 'WZ01112', 'v2_isAdmin': true });
|
||||
|
||||
t('админ без adminMode', { v2_user: {
|
||||
email: 'a@t.ru', clientId: 'WZ01112', activeClientId: 'WZ01112',
|
||||
allClientIds: ['WZ01112'], isAdmin: true, profiles: []
|
||||
} }, { 'v2_email': 'a@t.ru', 'v2_clientId': 'WZ01112', 'v2_isAdmin': false });
|
||||
|
||||
t('имперсонация', { v2_user: {
|
||||
email: 'admin@t.ru', clientId: 'WZ01112', activeClientId: 'WZ01112',
|
||||
allClientIds: ['WZ01112','WZ03709'], isAdmin: true, isImpersonated: true,
|
||||
originalUserEmail: 'real@t.ru', impersonatedCompanyId: 'WZ03709', profiles: []
|
||||
}, v2_adminMode: true }, { 'v2_email': 'real@t.ru', 'v2_clientId': 'WZ03709', 'v2_isImpersonated': true, 'v2_impersonatedBy': 'admin@t.ru' });
|
||||
|
||||
t('имперс. без origEmail', { v2_user: {
|
||||
email: 'x@t.ru', clientId: 'WZ01112', activeClientId: 'WZ01112',
|
||||
allClientIds: ['WZ01112'], isAdmin: true, isImpersonated: true,
|
||||
originalUserEmail: '', impersonatedCompanyId: '', profiles: []
|
||||
} }, { 'v2_email': 'x@t.ru', 'v2_clientId': 'WZ01112', 'v2_impersonatedBy': 'x@t.ru' });
|
||||
|
||||
t('без activeClientId', { v2_user: {
|
||||
email: 'y@t.ru', clientId: 'WZ03709', allClientIds: ['WZ03709'],
|
||||
isAdmin: false, profiles: []
|
||||
} }, { 'v2_email': 'y@t.ru', 'v2_clientId': 'WZ03709' });
|
||||
|
||||
console.log(`\n${passed} passed, ${failed} failed`);
|
||||
if (failed) process.exit(1);
|
||||
Reference in New Issue
Block a user