diff --git a/node/utils/metrics/organization.test.ts b/node/utils/metrics/organization.test.ts index a0f48a7b..7476d869 100644 --- a/node/utils/metrics/organization.test.ts +++ b/node/utils/metrics/organization.test.ts @@ -133,6 +133,58 @@ describe('given an organization to update data', () => { kind: 'update-organization-graphql-event', } + expect(sendMetric).toHaveBeenCalledWith(metricParam) + }) + }) + describe('when just the name, status and tradeName', () => { + const logger = jest.fn() as unknown as Logger + + const currentOrganization: Organization = { + collections: [{ id: '149', name: 'Teste 2 Jay' }], + costCenters: [], + created: '2023-05-26T17:59:51.665Z', + customFields: [], + id: '166d3921-fbef-11ed-83ab-16759f4a0add', + name: 'Antes', + paymentTerms: [], + priceTables: [], + salesChannel: '1', + sellers: [], + status: 'inactive', + tradeName: 'Antes', + } + + const fieldsUpdated = { + collections: [{ id: '149', name: 'Teste 2 Jay' }], + customFields: [], + name: 'Depois', + paymentTerms: [], + priceTables: [], + salesChannel: '1', + sellers: [], + status: 'active', + tradeName: 'Depois', + } + + beforeEach(async () => { + await sendUpdateOrganizationMetric( + logger, + fieldsUpdated, + currentOrganization + ) + }) + + it('should metric just the properties changed', () => { + const metricParam = { + description: 'Update Organization Action - Graphql', + fields: { + update_details: { + properties: ['name', 'status', 'tradeName'], + }, + }, + kind: 'update-organization-graphql-event', + } + expect(sendMetric).toHaveBeenCalledWith(metricParam) }) }) diff --git a/node/utils/metrics/organization.ts b/node/utils/metrics/organization.ts index 261d0daf..edbd4531 100644 --- a/node/utils/metrics/organization.ts +++ b/node/utils/metrics/organization.ts @@ -35,7 +35,12 @@ const getFieldsNamesByFieldsUpdated = ( if (Object.prototype.hasOwnProperty.call(updatedProperties, key)) { const value = updatedProperties[key as keyof typeof updatedProperties] - if (value !== currentOrganizationData[key as keyof Organization]) { + // I tried to compare the objects value !== currentOrganizationData[key as keyof Organization, + // but it was not working, so I use JSON.stringify + if ( + JSON.stringify(value) !== + JSON.stringify(currentOrganizationData[key as keyof Organization]) + ) { updatedPropName.push(key) } }