test scipt issues rsplved related to dealer login from script for E2E flow
This commit is contained in:
parent
71d9f9dbba
commit
5b501ede6c
@ -3,7 +3,7 @@ import bcrypt from 'bcryptjs';
|
|||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import db from '../../database/models/index.js';
|
import db from '../../database/models/index.js';
|
||||||
const { Role, Permission, RolePermission, User, DealerCode, AuditLog } = db;
|
const { Role, Permission, RolePermission, User, DealerCode, AuditLog } = db;
|
||||||
import { AUDIT_ACTIONS } from '../../common/config/constants.js';
|
import { AUDIT_ACTIONS, ROLES } from '../../common/config/constants.js';
|
||||||
import { AuthRequest } from '../../types/express.types.js';
|
import { AuthRequest } from '../../types/express.types.js';
|
||||||
import { syncLocationManagers, syncRegionManager, syncZoneManager } from '../master/syncHierarchy.service.js';
|
import { syncLocationManagers, syncRegionManager, syncZoneManager } from '../master/syncHierarchy.service.js';
|
||||||
import { resolveManagerCode } from '../../services/userRoleCode.service.js';
|
import { resolveManagerCode } from '../../services/userRoleCode.service.js';
|
||||||
@ -208,7 +208,17 @@ export const getAllUsers = async (req: Request, res: Response) => {
|
|||||||
whereClause.roleCode = { [Op.in]: finalRoleCodes };
|
whereClause.roleCode = { [Op.in]: finalRoleCodes };
|
||||||
}
|
}
|
||||||
|
|
||||||
const nationalRoles = ['NBH', 'DD Head', 'Super Admin'];
|
const nationalRoles = [
|
||||||
|
ROLES.NBH,
|
||||||
|
ROLES.DD_HEAD,
|
||||||
|
ROLES.DD_LEAD,
|
||||||
|
ROLES.DD_ADMIN,
|
||||||
|
ROLES.LEGAL_ADMIN,
|
||||||
|
ROLES.FINANCE,
|
||||||
|
ROLES.SUPER_ADMIN,
|
||||||
|
ROLES.CCO,
|
||||||
|
ROLES.CEO
|
||||||
|
];
|
||||||
const isNationalRole = finalRoleCodes.some(r => nationalRoles.includes(r));
|
const isNationalRole = finalRoleCodes.some(r => nationalRoles.includes(r));
|
||||||
|
|
||||||
if (!isNationalRole && locationId) {
|
if (!isNationalRole && locationId) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import db from '../../database/models/index.js';
|
import db from '../../database/models/index.js';
|
||||||
const { Application, Opportunity, ApplicationStatusHistory, ApplicationProgress, AuditLog, District, State, Region, Zone, SecurityDeposit, FddAssignment, FddReport, OnboardingDocument, Worknote, StageApprovalAction, DealerCode, Dealer, RequestParticipant, QuestionnaireResponse, QuestionnaireQuestion, QuestionnaireOption, Questionnaire, User } = db;
|
const { Application, Opportunity, ApplicationStatusHistory, ApplicationProgress, AuditLog, District, State, Region, Zone, SecurityDeposit, FddAssignment, FddReport, OnboardingDocument, Worknote, StageApprovalAction, DealerCode, Dealer, RequestParticipant, QuestionnaireResponse, QuestionnaireQuestion, QuestionnaireOption, Questionnaire, User } = db;
|
||||||
import { AUDIT_ACTIONS, APPLICATION_STAGES, APPLICATION_STATUS } from '../../common/config/constants.js';
|
import { AUDIT_ACTIONS, APPLICATION_STAGES, APPLICATION_STATUS, ROLES } from '../../common/config/constants.js';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import { AuthRequest } from '../../types/express.types.js';
|
import { AuthRequest } from '../../types/express.types.js';
|
||||||
@ -211,7 +211,18 @@ export const getApplications = async (req: AuthRequest, res: Response) => {
|
|||||||
const whereClause: any = {};
|
const whereClause: any = {};
|
||||||
|
|
||||||
// Determine if user has national-level visibility
|
// Determine if user has national-level visibility
|
||||||
const nationalRoles = ['NBH', 'DD Head', 'DD Lead', 'Finance', 'Admin', 'Super Admin'];
|
const nationalRoles = [
|
||||||
|
ROLES.NBH,
|
||||||
|
ROLES.DD_HEAD,
|
||||||
|
ROLES.DD_LEAD,
|
||||||
|
ROLES.FINANCE,
|
||||||
|
ROLES.DD_ADMIN,
|
||||||
|
ROLES.LEGAL_ADMIN,
|
||||||
|
ROLES.SUPER_ADMIN,
|
||||||
|
ROLES.CCO,
|
||||||
|
ROLES.CEO,
|
||||||
|
'Admin' // Keep legacy support if any
|
||||||
|
];
|
||||||
const isNationalUser = nationalRoles.includes(req.user?.roleCode || '');
|
const isNationalUser = nationalRoles.includes(req.user?.roleCode || '');
|
||||||
const isProspectiveDealer = req.user?.roleCode === 'Prospective Dealer';
|
const isProspectiveDealer = req.user?.roleCode === 'Prospective Dealer';
|
||||||
|
|
||||||
|
|||||||
@ -468,7 +468,17 @@ export const getRequests = async (req: AuthRequest, res: Response) => {
|
|||||||
const userRoleCode = req.user?.roleCode;
|
const userRoleCode = req.user?.roleCode;
|
||||||
|
|
||||||
// National roles see all requests
|
// National roles see all requests
|
||||||
const nationalRoles = ['NBH', 'DD Lead', 'DD Head', 'Legal Admin', 'Super Admin', 'DD Admin'];
|
const nationalRoles = [
|
||||||
|
ROLES.NBH,
|
||||||
|
ROLES.DD_LEAD,
|
||||||
|
ROLES.DD_HEAD,
|
||||||
|
ROLES.LEGAL_ADMIN,
|
||||||
|
ROLES.SUPER_ADMIN,
|
||||||
|
ROLES.DD_ADMIN,
|
||||||
|
ROLES.FINANCE,
|
||||||
|
ROLES.CCO,
|
||||||
|
ROLES.CEO
|
||||||
|
];
|
||||||
if (userRoleCode && nationalRoles.includes(userRoleCode)) {
|
if (userRoleCode && nationalRoles.includes(userRoleCode)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,11 +103,42 @@ async function resolveDealerOutlet(dealerToken) {
|
|||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
console.log("--- STARTING RELOCATION E2E FLOW ---");
|
console.log("--- STARTING RELOCATION E2E FLOW ---");
|
||||||
if (!EMAILS.DEALER) {
|
|
||||||
throw new Error("Missing --dealerEmail. This script requires an existing dealer user email.");
|
|
||||||
}
|
|
||||||
const adminToken = await login(EMAILS.DD_ADMIN);
|
const adminToken = await login(EMAILS.DD_ADMIN);
|
||||||
const dealerToken = await login(EMAILS.DEALER, "Dealer@123");
|
|
||||||
|
// Discover dealer if email is not provided or if the default is stale
|
||||||
|
let dealerEmail = EMAILS.DEALER;
|
||||||
|
let dealerToken = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Attempting login for dealer: ${dealerEmail}...`);
|
||||||
|
dealerToken = await login(dealerEmail, "Dealer@123");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Provided/Default dealer login failed. Searching for an onboarded dealer...`);
|
||||||
|
const appsRes = await apiRequest('/onboarding/applications', 'GET', null, adminToken);
|
||||||
|
const onboardedApps = appsRes.data.filter(a => (a.overallStatus || a.status || '').toLowerCase() === 'onboarded');
|
||||||
|
|
||||||
|
for (const app of onboardedApps) {
|
||||||
|
try {
|
||||||
|
process.stdout.write(`Testing login for ${app.email}... `);
|
||||||
|
const dealerData = await apiRequest('/auth/login', 'POST', {
|
||||||
|
email: app.email,
|
||||||
|
password: 'Dealer@123'
|
||||||
|
});
|
||||||
|
dealerToken = dealerData.token;
|
||||||
|
dealerEmail = app.email;
|
||||||
|
console.log('SUCCESS');
|
||||||
|
break;
|
||||||
|
} catch (err) {
|
||||||
|
console.log('FAILED');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dealerToken) {
|
||||||
|
throw new Error("Could not find or login to any onboarded dealer account.");
|
||||||
|
}
|
||||||
|
|
||||||
|
EMAILS.DEALER = dealerEmail;
|
||||||
|
|
||||||
let requestId = args.requestId;
|
let requestId = args.requestId;
|
||||||
if (!requestId) {
|
if (!requestId) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user