Skip to content

Commit

Permalink
Merge pull request Sunbird-RC#419 from Sreejit-K/main
Browse files Browse the repository at this point in the history
Added randomMockProfileGeneration logic and neccessary changes for es…
  • Loading branch information
srprasanna authored Mar 6, 2024
2 parents 2ffad32 + 250f493 commit 9c3435a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/mock-donor-service/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const REDIS_URL = process.env.REDIS_URL;
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
module.exports = {
REDIS_URL
}
5 changes: 3 additions & 2 deletions backend/mock-donor-service/config/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const HOST = process.env.HOST || 'localhost'
const PROTOCOL = process.env.PROTOCOL || 'http'
const PORT = process.env.PORT || 5001
const DOMAIN_URL = process.env.DOMAIN_URL || 'http://localhost:5001'

module.exports = {
PROTOCOL, HOST, PORT
}
PROTOCOL, HOST, PORT, DOMAIN_URL
}
6 changes: 3 additions & 3 deletions backend/mock-donor-service/src/routers/abha.router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const express = require('express');
const abhaRouter = express.Router()
const {v4: uuidv4} = require('uuid');
const {getRandomMockProfile, isMockProfilePresent} = require('../services/mock-profile.service');
const {getRandomMockProfile, isMockProfilePresent, generateRandomABHA} = require('../services/mock-profile.service');

let uuidAbhaMap = new Map();
let userTokenTxnIdMap = new Map();
Expand Down Expand Up @@ -60,7 +60,7 @@ abhaRouter.post('/v1/auth/confirmWithMobileOTP', (req, res) => {

abhaRouter.get('/v1/account/profile', (req, res) => {
const abha = uuidAbhaMap.get(userTokenTxnIdMap.get(req.headers['x-token'].substring(7)));
const profile = getRandomMockProfile(abha);
const profile = getRandomMockProfile();
res.send(profile);
});

Expand All @@ -74,7 +74,7 @@ abhaRouter.post('/v2/registration/mobile/login/verifyOtp', (req, res) => {
res.send({
"mobileLinkedHid": [
{
"healthIdNumber": "91-3075-5157-3552",
"healthIdNumber": generateRandomABHA(),
"healthId": "",
"name": "John Doe",
"profilePhoto": null,
Expand Down
22 changes: 12 additions & 10 deletions backend/mock-donor-service/src/routers/esign.router.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
const express = require('express');
const {v4: uuidv4} = require('uuid');
const redis = require('../services/redis.service');
const { PROTOCOL, HOST, PORT } = require('../../config/constants');
const { PROTOCOL, HOST, PORT, DOMAIN_URL } = require('../../config/constants');

const esignRouter = express.Router();
esignRouter.post('/digiSign/genEspRequest', (req, res) => {
const transactionId = uuidv4();
res.send({
espUrl: `${PROTOCOL}://${HOST}:${PORT}/mock/esign/${transactionId}`,
espUrl: `${DOMAIN_URL}/mock/esign/${transactionId}`,
aspTxnId: transactionId
});
return;
});

esignRouter.post('/mock/esign/:transactionId', (req, res) => {
const html = `<html><head><title>Mock ESign</title></head><body><h3>This is Mock ESIGN Portal</h3><a href="${PROTOCOL}://${HOST}:${PORT}/mock/esign/submit/${req.params.transactionId}">Submit</a></body></html>`
const html = `<html><head><title>Mock ESign</title></head><body><h3>This is Mock ESIGN Portal</h3><a href="${DOMAIN_URL}/mock/esign/submit/${req.params.transactionId}">Submit</a></body></html>`
res.send(html);
})

esignRouter.get('/mock/esign/:transactionId', (req, res) => {
const html = `<html><head><title>Mock ESign</title></head><body><h3>This is Mock ESIGN Portal</h3><a href="${DOMAIN_URL}/mock/esign/submit/${req.params.transactionId}">Submit</a></body></html>`
res.send(html);
})

Expand All @@ -24,12 +29,9 @@ esignRouter.get('/mock/esign/submit/:transactionId', async(req, res) => {
});

esignRouter.get('/digiSign/pdf/:transactionId', async(req, res) => {
const isSigned = await redis.getKey(req.params.transactionId) === "true";
if(isSigned) {
res.status(200).json({});
return;
}
res.sendStatus(404)
// const isSigned = await redis.getKey(req.params.transactionId) === "true";
res.status(200).json({});
return;
});

esignRouter.post('/api/v1/Pledge/:pledgeOsid/esign/documents', (req, res) => {
Expand All @@ -38,4 +40,4 @@ esignRouter.post('/api/v1/Pledge/:pledgeOsid/esign/documents', (req, res) => {
})
module.exports = {
esignRouter
}
}
28 changes: 27 additions & 1 deletion backend/mock-donor-service/src/services/mock-profile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@ const getRandomMockProfile = (abha = null) => {
if(abha === null) {
const range = randomProfiles.length;
const index = Math.floor(Math.random() * range);
randomProfiles[index]["healthIdNumber"] = generateRandomABHA();
randomProfiles[index]["mobile"] = generateRandomMobileNumber();
return randomProfiles[index];
} else if(randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha).length > 0) {
return randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha)[0]
}
return null;
}


function generateRandomABHA() {
let result = '';
// Generate random prefix in the range of 10-99
const prefix = Math.floor(Math.random() * 90) + 10;
result += prefix + '-';
// Generate random numbers in the format xxxx-xxxx-xxxx
for (let i = 0; i < 3; i++) {
result += Math.floor(Math.random() * 10000).toString().padStart(4, '0');
if (i < 2) result += '-';
}
return result;
}

function generateRandomMobileNumber() {
let phoneNumber = '9'; // Start with 9 to ensure it's a valid mobile number
for (let i = 1; i < 10; i++) {
phoneNumber += Math.floor(Math.random() * 10);
}
return phoneNumber;
}


const isMockProfilePresent = (abha) => {
return randomProfiles.filter(profile => profile.healthIdNumber.replace(/-/g, '') === abha).length > 0
}
Expand All @@ -19,5 +44,6 @@ const isMockProfilePresent = (abha) => {

module.exports = {
getRandomMockProfile,
isMockProfilePresent
isMockProfilePresent,
generateRandomABHA
}

0 comments on commit 9c3435a

Please sign in to comment.