Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/frontend/284 pruebas de interfaz #318

Merged
merged 8 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,583 changes: 8,582 additions & 1 deletion .nyc_output/b755a280-3904-4861-918c-2476ca49ae4e.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{"parent":null,"pid":17204,"argv":["C:\\Program Files\\nodejs\\node.exe","C:\\ISPP\\ISPP-G1-Talent\\node_modules\\mocha\\bin\\mocha.js","--timeout","60000","api/v1/tests/**/*.js"],"execArgv":[],"cwd":"C:\\ISPP\\ISPP-G1-Talent","time":1712858561193,"ppid":27232,"coverageFilename":"C:\\ISPP\\ISPP-G1-Talent\\.nyc_output\\b755a280-3904-4861-918c-2476ca49ae4e.json","externalId":"","uuid":"b755a280-3904-4861-918c-2476ca49ae4e","files":["C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\api\\CallingApiTest.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\services\\GitHubService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\e2e\\UserControllerTest.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\controllers\\UserController.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\services\\UserService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleJWT.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\models\\user.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\models\\analysis.model.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\professional-experience\\models\\professional-experience.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleRoles.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\services\\AnalysisService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\notification\\services\\NotificationService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\notification\\models\\notification.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\history\\models\\history.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\history\\services\\HistoryService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\subscriptions\\services\\SubscriptionsService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\subscriptions\\models\\subscription.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\utils\\ApiResponse.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\middlewares\\UserMiddleware.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleBcrypt.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\unit\\TeamCreatorServiceTest.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\professional-experience\\services\\ProfessionalExperienceService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\team-creator\\services\\TeamCreatorService.js","C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\team-creator\\models\\TeamCreatorModel.js"]}
{
"parent": null,
"pid": 17204,
"argv": [
"C:\\Program Files\\nodejs\\node.exe",
"C:\\ISPP\\ISPP-G1-Talent\\node_modules\\mocha\\bin\\mocha.js",
"--timeout",
"60000",
"api/v1/tests/**/*.js"
],
"execArgv": [],
"cwd": "C:\\ISPP\\ISPP-G1-Talent",
"time": 1712858561193,
"ppid": 27232,
"coverageFilename": "C:\\ISPP\\ISPP-G1-Talent\\.nyc_output\\b755a280-3904-4861-918c-2476ca49ae4e.json",
"externalId": "",
"uuid": "b755a280-3904-4861-918c-2476ca49ae4e",
"files": [
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\api\\CallingApiTest.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\services\\GitHubService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\e2e\\UserControllerTest.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\controllers\\UserController.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\services\\UserService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleJWT.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\models\\user.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\models\\analysis.model.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\professional-experience\\models\\professional-experience.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleRoles.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\analysis\\services\\AnalysisService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\notification\\services\\NotificationService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\notification\\models\\notification.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\history\\models\\history.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\history\\services\\HistoryService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\subscriptions\\services\\SubscriptionsService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\subscriptions\\models\\subscription.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\utils\\ApiResponse.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\middlewares\\UserMiddleware.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\user\\helpers\\handleBcrypt.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\tests\\unit\\TeamCreatorServiceTest.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\professional-experience\\services\\ProfessionalExperienceService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\team-creator\\services\\TeamCreatorService.js",
"C:\\ISPP\\ISPP-G1-Talent\\api\\v1\\modules\\team-creator\\models\\TeamCreatorModel.js"
]
}
56 changes: 34 additions & 22 deletions api/v1/modules/team-creator/routes.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import express from 'express';
import express from 'express'
import {
// getAllTeamCreator,
getTeamCreatorById,
createTeamCreator,
getAllTeamCreatorOfRepresentative,
//updateTeamCreator,
deleteTeamCreator
} from './controllers/TeamCreatorController';
// getAllTeamCreator,
getTeamCreatorById,
createTeamCreator,
getAllTeamCreatorOfRepresentative,
//updateTeamCreator,
deleteTeamCreator,
} from './controllers/TeamCreatorController'
import {
checkIsRepresentative,
checkValidToken,
checkDataCreateTeam,
checkAuthorization,
checkSubscriptionState

} from './validators/TeamCreatorMiddleware';
const router = express.Router();
router.use(express.json());
checkIsRepresentative,
checkValidToken,
checkDataCreateTeam,
checkAuthorization,
checkSubscriptionState,
} from './validators/TeamCreatorMiddleware'
const router = express.Router()
router.use(express.json())
// Define routes for the TeamCreator module
//router.get('/', getAllTeamCreator);
router.get('/:id',checkValidToken,checkIsRepresentative, getTeamCreatorById);
router.get('/representative-user/:id',checkValidToken,checkIsRepresentative,checkAuthorization,getAllTeamCreatorOfRepresentative)
router.post('/',checkValidToken,checkIsRepresentative,checkDataCreateTeam,checkSubscriptionState, createTeamCreator);
router.get('/:id', checkValidToken, checkIsRepresentative, getTeamCreatorById)
router.get(
'/representative-user/:id',
checkValidToken,
checkIsRepresentative,
checkAuthorization,
getAllTeamCreatorOfRepresentative
)
router.post(
'/',
checkValidToken,
checkIsRepresentative,
checkDataCreateTeam,
checkSubscriptionState,
createTeamCreator
)
//router.patch('/:id', updateTeamCreator);
router.delete('/:id',checkValidToken,checkIsRepresentative, deleteTeamCreator);
router.delete('/:id', checkValidToken, checkIsRepresentative, deleteTeamCreator)

export default router;
export default router
17 changes: 10 additions & 7 deletions api/v1/modules/team-creator/validators/TeamCreatorMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,18 @@ export const checkDataCreateTeam: any = async (req: Request, res: Response, next
}
}

export const checkSubscriptionState: any = async (req: Request, res: Response, next: NextFunction) => {
export const checkSubscriptionState: any = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const profiles=req.body
const profiles = req.body
const token = req.headers.authorization ?? ''
const decodedToken = verifyJWT(token)
const representativeUser = await Representative.findById(decodedToken.sub)
const subscription= await Subscription.findById((representativeUser as any).subscriptionId)
if(subscription===null){
const subscription = await Subscription.findById((representativeUser as any).subscriptionId)
if (subscription === null) {
const message = 'You arent subscribed'
ApiResponse.sendError(
res,
Expand All @@ -188,7 +192,7 @@ export const checkSubscriptionState: any = async (req: Request, res: Response, n
400
)
return
}else if((subscription as any).remainingSearches<profiles.length){
} else if ((subscription as any).remainingSearches < profiles.length) {
const message = 'You dont have enough tokens to search'
ApiResponse.sendError(
res,
Expand All @@ -201,7 +205,7 @@ export const checkSubscriptionState: any = async (req: Request, res: Response, n
400
)
return
}else if(profiles.length>(subscription as any).teamLimit){
} else if (profiles.length > (subscription as any).teamLimit) {
const message = `You cant make teams higher tha ${(subscription as any).teamLimit}`
ApiResponse.sendError(
res,
Expand All @@ -216,7 +220,6 @@ export const checkSubscriptionState: any = async (req: Request, res: Response, n
return
}
next()

} catch (error: any) {
ApiResponse.sendError(res, [
{
Expand Down
60 changes: 32 additions & 28 deletions api/v1/tests/api/CallingApiTest.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import assert from 'assert';
import { GetUserAnaliseInfo } from '../../modules/analysis/services/GitHubService';

// Estas 3 lineas son necesarias porque al estar el .env fuera de tests, no te lo detecta
import * as dotenv from 'dotenv';
import * as path from 'path';
const githubUsername = 'rwieruch'
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
describe(`Call the API to add a new analysis - ${githubUsername} : `, () => {
it('Should call the API and verify that its the same user', (done: Mocha.Done) => {
// Aquí invocas tu función que hace la llamada a la API GraphQL
GetUserAnaliseInfo(githubUsername, process.env.GH_TOKEN)
.then(data => {
// Asumiendo que data tiene una propiedad llamada 'success' que indica si la llamada fue exitosa
assert.strictEqual(data.githubUsername, githubUsername, 'The API call was not successful');
/*
* Si tienes datos específicos que esperas recibir, puedes hacer aserciones sobre ellos aquí
* Por ejemplo, si esperas que los datos incluyan un usuario con un nombre específico:
* assert(data.user.name === 'Expected Name', 'The received name did not match the expected one');
*/

done(); // Indica que el test ha terminado
})
.catch(err => {
done(err); // Si hay un error, lo pasa a Mocha
});
});
}).timeout(10000);
import assert from 'assert'
import { GetUserAnaliseInfo } from '../../modules/analysis/services/GitHubService'

// Estas 3 lineas son necesarias porque al estar el .env fuera de tests, no te lo detecta
import * as dotenv from 'dotenv'
import * as path from 'path'
const githubUsername = 'rwieruch'
dotenv.config({ path: path.resolve(__dirname, '../../.env') })
describe(`Call the API to add a new analysis - ${githubUsername} : `, () => {
it('Should call the API and verify that its the same user', (done: Mocha.Done) => {
// Aquí invocas tu función que hace la llamada a la API GraphQL
GetUserAnaliseInfo(githubUsername, process.env.GH_TOKEN)
.then((data) => {
// Asumiendo que data tiene una propiedad llamada 'success' que indica si la llamada fue exitosa
assert.strictEqual(
data.githubUsername,
githubUsername,
'The API call was not successful'
)
/*
* Si tienes datos específicos que esperas recibir, puedes hacer aserciones sobre ellos aquí
* Por ejemplo, si esperas que los datos incluyan un usuario con un nombre específico:
* assert(data.user.name === 'Expected Name', 'The received name did not match the expected one');
*/

done() // Indica que el test ha terminado
})
.catch((err) => {
done(err) // Si hay un error, lo pasa a Mocha
})
})
}).timeout(10000)
Loading