From 7cbc9efbc050c0608577697b7ff3a8222af64fc3 Mon Sep 17 00:00:00 2001 From: jinalviranii Date: Wed, 23 Oct 2024 18:00:42 +0530 Subject: [PATCH] Remove query event details api --- server.js | 40 +--------------------------------------- src/tests/server.test.js | 19 +------------------ 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/server.js b/server.js index 53c074a..33ea599 100644 --- a/server.js +++ b/server.js @@ -148,15 +148,10 @@ app.get('/fp/auth', passport.authenticate('oauth2', { failureRedirect: '/' }), s }); res.header['x-company-id'] = companyId; - // Fetch webhook event configuration for an event - const eventData = await fetchEventConfiguration(token.access_token); - const eventIds = eventData.event_configs.map((event) => event.id); - // Subscribe to a specific event await configureWebhookSubscriber( token.access_token, req.query.company_id, - eventIds ); // Redirect based on company or application ID const redirectUrl = req.query.application_id @@ -215,41 +210,8 @@ function sessionMiddleware(strict) { }; } -// Function to query event details -async function fetchEventConfiguration(accessToken) { - try { - // Extension webhook configuration. Add/Update this configuration as per need. - const webhookConfig = [ - { - event_category: 'company', - event_name: 'product', - event_type: 'delete', - version: '1', - }, - ]; - - const requestOptions = { - method: 'POST', - headers: { - Authorization: `Bearer ${accessToken}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify(webhookConfig), - }; - - const response = await fetch( - `${EXTENSION_CLUSTER_URL}/service/common/webhook/v1.0/events/query-event-details`, - requestOptions - ); - return response.json(); // Return event data - } - catch (error) { - console.error(`Error while fetching webhook events configuration, Reason: ${error.message}`); - } -} - // Function to configure webhook subscriber -async function configureWebhookSubscriber(accessToken, companyId, eventIds) { +async function configureWebhookSubscriber(accessToken, companyId) { try { const requestOptions = { method: 'POST', diff --git a/src/tests/server.test.js b/src/tests/server.test.js index 6801a36..944fd60 100644 --- a/src/tests/server.test.js +++ b/src/tests/server.test.js @@ -57,18 +57,6 @@ describe('Custom Next.js server', () => { }); it('GET /fp/auth: Should return access token and subscribe to webhook event', async () => { - // Mock the fetch request for queryEventDetails - fetch.mockImplementationOnce(async (url) => { - if (url.includes('/query-event-details')) { - return { - json: async () => ({ - event_configs: [{ id: 'mockedEventId1' }], - }), - }; - } - return Promise.reject(new Error('Unknown endpoint')); - }); - // Mock the response for the /subscriber endpoint fetch.mockImplementationOnce(async (url) => { if (url.includes('/subscriber')) { @@ -84,14 +72,9 @@ describe('Custom Next.js server', () => { .get(`/fp/auth?company_id=123`) .set('cookie', `${SESSION_COOKIE_NAME}_123=${cookie}`) .send(); - expect(fetch).toHaveBeenCalledTimes(2); + expect(fetch).toHaveBeenCalledTimes(1); expect(fetch).toHaveBeenNthCalledWith(1, - `${process.env.EXTENSION_CLUSTER_URL}/service/common/webhook/v1.0/events/query-event-details`, - expect.any(Object) - ); - - expect(fetch).toHaveBeenNthCalledWith(2, `${process.env.EXTENSION_CLUSTER_URL}/service/platform/webhook/v2.0/company/123/subscriber`, expect.any(Object) );