Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
Cómo inyectar una función de código auxiliar cuando se usa server.inject de Hapi.js

Tengo un proyecto hapijs que usa el complemento hapi-mongodb.

En el controlador, estoy usando el complemento hapi-mongodb para hacer llamadas a db. Vea abajo

 internals.getById = async (request, h) => { try { const db = request.mongo.db; const ObjectId = request.mongo.ObjectID; const query = { _id: ObjectId(request.params.id) }; const record = await db.collection(internals.collectionName).findOne(query); //etc.....

Quiero poder probar esto usando server.inject(), pero no estoy seguro de cómo agregar el request.mongo.db y el request.mongo.ObjectID

 it('should return a 200 HTTP status code', async () => { const server = new Hapi.Server(); server.route(Routes); //This comes from a required file const options = { method: 'GET', url: `/testData/1` }; //stub request.mongo.db and request.mongo.ObjectID const response = await server.inject(options); expect(response.statusCode).to.equal(200); });

¿Algunas ideas?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Resolví esto y me di cuenta de que el complemento mongo decora el objeto del servidor que se puede bloquear.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!