From e75e9c48180f3a71ce5096fa76b41b1436f2e021 Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Tue, 22 Oct 2024 17:14:51 +0100 Subject: [PATCH] Revert "Send subscription -> salesforce/v1 links to analytics" This reverts commit 52c02138f9ef8141850e2f8ce16f2bab1e7463b0. GitOrigin-RevId: 022e828a8e41cc73c4087b94d51fa75dbe6cfdb5 --- .../Analytics/AccountMappingHelper.mjs | 48 ---- .../Features/Analytics/AnalyticsManager.js | 53 ---- services/web/app/src/infrastructure/Queues.js | 5 - .../Analytics/AccountMappingHelperTests.mjs | 228 ------------------ .../src/Analytics/AnalyticsManagerTests.js | 26 -- 5 files changed, 360 deletions(-) delete mode 100644 services/web/app/src/Features/Analytics/AccountMappingHelper.mjs delete mode 100644 services/web/test/unit/src/Analytics/AccountMappingHelperTests.mjs diff --git a/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs b/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs deleted file mode 100644 index c5525d3053..0000000000 --- a/services/web/app/src/Features/Analytics/AccountMappingHelper.mjs +++ /dev/null @@ -1,48 +0,0 @@ -export function extractAccountMappingsFromSubscription( - subscription, - updatedSubscription -) { - const accountMappings = [] - if ( - updatedSubscription.salesforce_id || - updatedSubscription.salesforce_id === '' - ) { - if (subscription.salesforce_id !== updatedSubscription.salesforce_id) { - accountMappings.push( - generateSubscriptionToSalesforceMapping( - subscription.id, - updatedSubscription.salesforce_id - ) - ) - } - } - if (updatedSubscription.v1_id || updatedSubscription.v1_id === '') { - if (subscription.v1_id !== updatedSubscription.v1_id) { - accountMappings.push( - generateSubscriptionToV1Mapping( - subscription.id, - updatedSubscription.v1_id - ) - ) - } - } - return accountMappings -} -} - - -function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) { - return { - source: 'salesforce', - sourceEntity: 'account', - sourceEntityId: salesforceId, - target: 'v2', - targetEntity: 'subscription', - targetEntityId: subscriptionId, - createdAt: new Date().toISOString(), - } -} - -export default { - extractAccountMappingsFromSubscription, -} diff --git a/services/web/app/src/Features/Analytics/AnalyticsManager.js b/services/web/app/src/Features/Analytics/AnalyticsManager.js index 0a1cd32e55..7ff8a5be01 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsManager.js +++ b/services/web/app/src/Features/Analytics/AnalyticsManager.js @@ -15,9 +15,6 @@ const analyticsEditingSessionsQueue = Queues.getQueue( const analyticsUserPropertiesQueue = Queues.getQueue( 'analytics-user-properties' ) -const analyticsAccountMappingQueue = Queues.getQueue( - 'analytics-account-mapping' -) const ONE_MINUTE_MS = 60 * 1000 @@ -146,55 +143,6 @@ function setUserPropertyForSessionInBackground(session, property, value) { }) } -/** - * Register mapping between two accounts. - * - * @param {object} payload - The event payload to send to Analytics - * @param {string} payload.source - The type of account linked from - * @param {string} payload.sourceId - The ID of the account linked from - * @param {string} payload.target - The type of account linked to - * @param {string} payload.targetId - The ID of the account linked to - * @param {Date} payload.createdAt - The date the mapping was created - * @property - */ -function registerAccountMapping({ - source, - sourceEntity, - sourceEntityId, - target, - targetEntity, - targetEntityId, - createdAt, -}) { - Metrics.analyticsQueue.inc({ - status: 'adding', - event_type: 'account-mapping', - }) - - analyticsAccountMappingQueue - .add('account-mapping', { - source, - sourceEntity, - sourceEntityId, - target, - targetEntity, - targetEntityId, - createdAt: createdAt ?? new Date(), - }) - .then(() => { - Metrics.analyticsQueue.inc({ - status: 'added', - event_type: 'account-mapping', - }) - }) - .catch(() => { - Metrics.analyticsQueue.inc({ - status: 'error', - event_type: 'account-mapping', - }) - }) -} - function updateEditingSession(userId, projectId, countryCode, segmentation) { if (!userId) { return @@ -401,6 +349,5 @@ module.exports = { setUserPropertyForAnalyticsId, updateEditingSession, getIdsFromSession, - registerAccountMapping, analyticsIdMiddleware: expressify(analyticsIdMiddleware), } diff --git a/services/web/app/src/infrastructure/Queues.js b/services/web/app/src/infrastructure/Queues.js index 37842157da..0a03bdf24c 100644 --- a/services/web/app/src/infrastructure/Queues.js +++ b/services/web/app/src/infrastructure/Queues.js @@ -17,9 +17,6 @@ const QUEUES_JOB_OPTIONS = { 'analytics-editing-sessions': { removeOnFail: MAX_FAILED_JOBS_RETAINED_ANALYTICS, }, - 'analytics-account-mapping': { - removeOnFail: MAX_FAILED_JOBS_RETAINED_ANALYTICS, - }, 'analytics-user-properties': { removeOnFail: MAX_FAILED_JOBS_RETAINED_ANALYTICS, }, @@ -41,7 +38,6 @@ const QUEUES_JOB_OPTIONS = { removeOnFail: MAX_FAILED_JOBS_RETAINED, attempts: 3, }, - 'group-sso-reminder': { removeOnFail: MAX_FAILED_JOBS_RETAINED, attempts: 3, @@ -58,7 +54,6 @@ const QUEUE_OPTIONS = { } const ANALYTICS_QUEUES = [ - 'analytics-account-mapping', 'analytics-events', 'analytics-editing-sessions', 'analytics-user-properties', diff --git a/services/web/test/unit/src/Analytics/AccountMappingHelperTests.mjs b/services/web/test/unit/src/Analytics/AccountMappingHelperTests.mjs deleted file mode 100644 index 62dadae849..0000000000 --- a/services/web/test/unit/src/Analytics/AccountMappingHelperTests.mjs +++ /dev/null @@ -1,228 +0,0 @@ -import path from 'node:path' -import esmock from 'esmock' -import { expect } from 'chai' -import mongodb from 'mongodb-legacy' -import { fileURLToPath } from 'node:url' - -const { ObjectId } = mongodb - -const __dirname = fileURLToPath(new URL('.', import.meta.url)) - -const MODULE_PATH = path.join( - __dirname, - '../../../../app/src/Features/Analytics/AccountMappingHelper' -) - -describe('AccountMappingHelper', function () { - beforeEach(async function () { - this.AccountMappingHelper = await esmock.strict(MODULE_PATH) - }) - - describe('extractAccountMappingsFromSubscription', function () { - describe('when the v1 id is the same in the updated subscription and the subscription', function () { - describe('when the salesforce id is the same in the updated subscription and the subscription', function () { - beforeEach(function () { - this.subscription = { - id: new ObjectId('abc123abc123abc123abc123'), - salesforce_id: 'def456def456def456', - } - this.updatedSubscription = { salesforce_id: 'def456def456def456' } - this.result = - this.AccountMappingHelper.extractAccountMappingsFromSubscription( - this.subscription, - this.updatedSubscription - ) - }) - - it('returns an empty array', function () { - expect(this.result).to.be.an('array') - expect(this.result).to.have.length(0) - }) - }) - describe('when the salesforce id has changed between the subscription and the updated subscription', function () { - beforeEach(function () { - this.subscription = { - id: new ObjectId('abc123abc123abc123abc123'), - salesforce_id: 'def456def456def456', - } - this.updatedSubscription = { salesforce_id: 'ghi789ghi789ghi789' } - this.result = - this.AccountMappingHelper.extractAccountMappingsFromSubscription( - this.subscription, - this.updatedSubscription - ) - }) - - it('returns an array with a single item', function () { - expect(this.result).to.be.an('array') - expect(this.result).to.have.length(1) - }) - - it('uses "account" as sourceEntity', function () { - expect(this.result[0]).to.haveOwnProperty('sourceEntity', 'account') - }) - - it('uses the salesforceId from the updated subscription as sourceEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'sourceEntityId', - this.updatedSubscription.salesforce_id - ) - }) - - it('uses "subscription" as targetEntity', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntity', - 'subscription' - ) - }) - - it('uses the subscriptionId as targetEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntityId', - this.subscription.id - ) - }) - }) - describe('when the update subscription has a salesforce id and the subscription has no salesforce_id', function () { - beforeEach(function () { - this.subscription = { id: new ObjectId('abc123abc123abc123abc123') } - this.updatedSubscription = { salesforce_id: 'def456def456def456' } - this.result = - this.AccountMappingHelper.extractAccountMappingsFromSubscription( - this.subscription, - this.updatedSubscription - ) - }) - - it('returns an array with a single item', function () { - expect(this.result).to.be.an('array') - expect(this.result).to.have.length(1) - }) - - it('uses "account" as sourceEntity', function () { - expect(this.result[0]).to.haveOwnProperty('sourceEntity', 'account') - }) - - it('uses the salesforceId from the updated subscription as sourceEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'sourceEntityId', - this.updatedSubscription.salesforce_id - ) - }) - - it('uses "subscription" as targetEntity', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntity', - 'subscription' - ) - }) - - it('uses the subscriptionId as targetEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntityId', - this.subscription.id - ) - }) - }) - }) - }) - - describe('when the v1 id has changed between the subscription and the updated subscription', function () { - describe('when the salesforce id has not changed between the subscription and the updated subscription', function () { - beforeEach(function () { - this.subscription = { - id: new ObjectId('abc123abc123abc123abc123'), - v1_id: '1', - salesforce_id: '', - } - this.updatedSubscription = { v1_id: '2', salesforce_id: '' } - this.result = - this.AccountMappingHelper.extractAccountMappingsFromSubscription( - this.subscription, - this.updatedSubscription - ) - }) - - it('returns an array with a single item', function () { - expect(this.result).to.be.an('array') - expect(this.result).to.have.length(1) - }) - - it('uses "university" as the sourceEntity', function () { - expect(this.result[0]).to.haveOwnProperty('sourceEntity', 'university') - }) - - it('uses the v1_id from the updated subscription as the sourceEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'sourceEntityId', - this.updatedSubscription.v1_id - ) - }) - - it('uses "subscription" as the targetEntity', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntity', - 'subscription' - ) - }) - - it('uses the subscription id as the targetEntityId', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntityId', - this.subscription.id - ) - }) - }) - describe('when the salesforce id has changed between the subscription and the updated subscription', function () { - beforeEach(function () { - this.subscription = { - id: new ObjectId('abc123abc123abc123abc123'), - v1_id: '', - salesforce_id: 'def456def456def456', - } - this.updatedSubscription = { - v1_id: '2', - salesforce_id: '', - } - this.result = - this.AccountMappingHelper.extractAccountMappingsFromSubscription( - this.subscription, - this.updatedSubscription - ) - }) - - it('returns an array with two items', function () { - expect(this.result).to.be.an('array') - expect(this.result).to.have.length(2) - }) - - it('uses the salesforce_id from the updated subscription as the sourceEntityId for the first item', function () { - expect(this.result[0]).to.haveOwnProperty( - 'sourceEntityId', - this.updatedSubscription.salesforce_id - ) - }) - - it('uses the subscription id as the targetEntityId for the first item', function () { - expect(this.result[0]).to.haveOwnProperty( - 'targetEntityId', - this.subscription.id - ) - }) - - it('uses the v1_id from the updated subscription as the sourceEntityId for the second item', function () { - expect(this.result[1]).to.haveOwnProperty( - 'sourceEntityId', - this.updatedSubscription.v1_id - ) - }) - - it('uses the subscription id as the targetEntityId for the second item', function () { - expect(this.result[1]).to.haveOwnProperty( - 'targetEntityId', - this.subscription.id - ) - }) - }) - }) -}) diff --git a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js index 6d8a70afe4..5b027b292b 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js @@ -34,10 +34,6 @@ describe('AnalyticsManager', function () { add: sinon.stub().resolves(), process: sinon.stub().resolves(), } - this.analyticsAccountMappingQueue = { - add: sinon.stub().resolves(), - process: sinon.stub().resolves(), - } const self = this this.Queues = { getQueue: queueName => { @@ -50,8 +46,6 @@ describe('AnalyticsManager', function () { return self.onboardingEmailsQueue case 'analytics-user-properties': return self.analyticsUserPropertiesQueue - case 'analytics-account-mapping': - return self.analyticsAccountMappingQueue default: throw new Error('Unexpected queue name') } @@ -284,24 +278,6 @@ describe('AnalyticsManager', function () { isLoggedIn: true, }) }) - - it('account mapping', async function () { - const message = { - source: 'salesforce', - sourceEntity: 'account', - sourceEntityId: 'abc123abc123abc123', - target: 'v1', - targetEntity: 'university', - targetEntityId: 1, - createdAt: '2021-01-01T00:00:00Z', - } - await this.AnalyticsManager.registerAccountMapping(message) - sinon.assert.calledWithMatch( - this.analyticsAccountMappingQueue.add, - 'account-mapping', - message - ) - }) }) describe('AnalyticsIdMiddleware', function () { @@ -323,8 +299,6 @@ describe('AnalyticsManager', function () { return self.onboardingEmailsQueue case 'analytics-user-properties': return self.analyticsUserPropertiesQueue - case 'analytics-account-mapping': - return self.analyticsAccountMappingQueue default: throw new Error('Unexpected queue name') }