From 969beaefdbd47b7c034cdd522aaf0c5f8a030892 Mon Sep 17 00:00:00 2001 From: Olusegun Akintayo Date: Thu, 14 Sep 2023 00:06:00 +0100 Subject: [PATCH] Tests for Anon Transaction events. Signed-off-by: Olusegun Akintayo --- app/scripts/controllers/metametrics.test.js | 74 +++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/app/scripts/controllers/metametrics.test.js b/app/scripts/controllers/metametrics.test.js index 09170d4eee8f..0e060bed1e72 100644 --- a/app/scripts/controllers/metametrics.test.js +++ b/app/scripts/controllers/metametrics.test.js @@ -561,6 +561,80 @@ describe('MetaMetricsController', function () { }); }); + describe('Change Transaction XXX anonymous event namnes', function () { + it('should change "Transaction Added" anonymous event names to "Transaction Added Anon"', function () { + const metaMetricsController = getMetaMetricsController(); + const spy = sinon.spy(segment, 'track'); + metaMetricsController.submitEvent({ + event: 'Transaction Added', + category: 'Unit Test', + sensitiveProperties: { foo: 'bar' }, + }); + assert.ok(spy.calledTwice); + assert.ok( + spy.calledWith({ + event: `Transaction Added Anon`, + anonymousId: METAMETRICS_ANONYMOUS_ID, + context: DEFAULT_TEST_CONTEXT, + properties: { + foo: 'bar', + ...DEFAULT_EVENT_PROPERTIES, + }, + messageId: Utils.generateRandomId(), + timestamp: new Date(), + }), + ); + }); + + it('should change "Transaction Submitted" anonymous event names to "Transaction Added Anon"', function () { + const metaMetricsController = getMetaMetricsController(); + const spy = sinon.spy(segment, 'track'); + metaMetricsController.submitEvent({ + event: 'Transaction Submitted', + category: 'Unit Test', + sensitiveProperties: { foo: 'bar' }, + }); + assert.ok(spy.calledTwice); + assert.ok( + spy.calledWith({ + event: `Transaction Submitted Anon`, + anonymousId: METAMETRICS_ANONYMOUS_ID, + context: DEFAULT_TEST_CONTEXT, + properties: { + foo: 'bar', + ...DEFAULT_EVENT_PROPERTIES, + }, + messageId: Utils.generateRandomId(), + timestamp: new Date(), + }), + ); + }); + + it('should change "Transaction Finalized" anonymous event names to "Transaction Added Anon"', function () { + const metaMetricsController = getMetaMetricsController(); + const spy = sinon.spy(segment, 'track'); + metaMetricsController.submitEvent({ + event: 'Transaction Finalized', + category: 'Unit Test', + sensitiveProperties: { foo: 'bar' }, + }); + assert.ok(spy.calledTwice); + assert.ok( + spy.calledWith({ + event: `Transaction Finalized Anon`, + anonymousId: METAMETRICS_ANONYMOUS_ID, + context: DEFAULT_TEST_CONTEXT, + properties: { + foo: 'bar', + ...DEFAULT_EVENT_PROPERTIES, + }, + messageId: Utils.generateRandomId(), + timestamp: new Date(), + }), + ); + }); + }); + describe('trackPage', function () { it('should track a page view', function () { const mock = sinon.mock(segment);