Actualmente me estoy comunicando con la API de Facebook para enviar datos a través de una llamada axios:
if (req.body.event === 'PageView') { try { await axios .post(facebookURL, { data: [ { event_name: req.body.event, event_time: eventTime, action_source: 'website', event_source_url: `${req.body.serverAndPort}${req.body.url}`, user_data: { em: [email], fn: [firstName], ln: [lastName], }, custom_data: { content_type: req.body.content_type, }, }, ], }) .then(() => { return res.status(200).send(); }) .catch(error => { return res .status(500) .send('Error sending data to Facebook: ', error); }); } catch (error) { throw new Error(error); }Agregué la declaración .then() y catch() ya que no estaba recibiendo una respuesta. Cuando vengo a ejecutar mis pruebas, ahora recibo el siguiente error:
Esta es mi prueba actual:
const pageViewRequest = { body: { event: 'PageView', eventTime: 16452051, action_source: 'website', event_id: 'PR10032FF', locale: 'en-GB', content_type: 'PageView', firstName: 'Jesse', lastName: 'Heisenberg', email: 'theRealGusFring@lospoloshermanos.com', serverAndPort: 'localhost:1337', url: '/aPageViewTestUrl/', }, }; describe('submitFacebookEvent', () => { beforeEach(() => { axios.mockClear(); }); it('Should make post to correct url if event type is PageView', async () => { const req = createRequest(pageViewRequest); await submitFacebookEvent(req); expect(axios.post).toHaveBeenCalledWith( 'https://graph.facebook.com/v12.0/PixelUK/events?access_token=accessTokenUK', { data: [ { action_source: 'website', custom_data: { content_type: 'PageView', }, event_name: 'PageView', event_source_url: 'localhost:1337/aPageViewTestUrl/', event_time: jasmine.anything(), user_data: { em: [ '6c1e3f9b78926530cc06958ad80b7d0e986d8fe4a770a8276c1a7d226ddfdbf2', ], fn: [ '1ecb9e6bdf6cc8088693c11e366415fe5c73662ecdf08f3df337924d8ea26adc', ], ln: [ 'fe81e342a460fec7bb935c27903620066d56bd5d09b3c96010ba7619d2020d8b', ], }, }, ], } ); });Cualquier sugerencia sobre cómo corregir esto sería genial. ¡Gracias!