Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "Dapp viewed Event @no-mmi is sent when refreshing da..." flaky test #27381

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions test/e2e/tests/metrics/dapp-viewed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,40 @@ const {
MetaMetricsEventName,
} = require('../../../../shared/constants/metametrics');

async function mockedDappViewedEndpoint(mockServer) {
async function mockedDappViewedEndpointFirstVisit(mockServer) {
return await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [{ type: 'track', event: MetaMetricsEventName.DappViewed }],
batch: [
{
type: 'track',
event: MetaMetricsEventName.DappViewed,
properties: {
is_first_visit: true,
},
},
],
})
.thenCallback(() => {
return {
statusCode: 200,
};
});
}

async function mockedDappViewedEndpointReVisit(mockServer) {
return await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [
{
type: 'track',
event: MetaMetricsEventName.DappViewed,
properties: {
is_first_visit: false,
},
},
],
})
.thenCallback(() => {
return {
Expand Down Expand Up @@ -67,7 +96,7 @@ describe('Dapp viewed Event @no-mmi', function () {
const validFakeMetricsId = 'fake-metrics-fd20';
it('is not sent when metametrics ID is not valid', async function () {
async function mockSegment(mockServer) {
return [await mockedDappViewedEndpoint(mockServer)];
return [await mockedDappViewedEndpointFirstVisit(mockServer)];
}

await withFixtures(
Expand All @@ -93,7 +122,7 @@ describe('Dapp viewed Event @no-mmi', function () {

it('is sent when navigating to dapp with no account connected', async function () {
async function mockSegment(mockServer) {
return [await mockedDappViewedEndpoint(mockServer)];
return [await mockedDappViewedEndpointFirstVisit(mockServer)];
}

await withFixtures(
Expand Down Expand Up @@ -125,8 +154,8 @@ describe('Dapp viewed Event @no-mmi', function () {
it('is sent when opening the dapp in a new tab with one account connected', async function () {
async function mockSegment(mockServer) {
return [
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpointFirstVisit(mockServer),
await mockedDappViewedEndpointReVisit(mockServer),
await mockPermissionApprovedEndpoint(mockServer),
];
}
Expand Down Expand Up @@ -163,8 +192,8 @@ describe('Dapp viewed Event @no-mmi', function () {
it('is sent when refreshing dapp with one account connected', async function () {
async function mockSegment(mockServer) {
return [
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpointFirstVisit(mockServer),
await mockedDappViewedEndpointReVisit(mockServer),
await mockPermissionApprovedEndpoint(mockServer),
];
}
Expand All @@ -189,10 +218,9 @@ describe('Dapp viewed Event @no-mmi', function () {
// refresh dapp
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.refresh();

const events = await getEventPayloads(driver, mockedEndpoints);

// events are original dapp viewed, new dapp viewed when refresh, and permission approved
// events are original dapp viewed, navigate to dapp, new dapp viewed when refresh, new dapp viewed when navigate and permission approved
const dappViewedEventProperties = events[1].properties;
assert.equal(dappViewedEventProperties.is_first_visit, false);
assert.equal(dappViewedEventProperties.number_of_accounts, 1);
Expand All @@ -204,10 +232,10 @@ describe('Dapp viewed Event @no-mmi', function () {
it('is sent when navigating to a connected dapp', async function () {
async function mockSegment(mockServer) {
return [
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpointFirstVisit(mockServer),
await mockedDappViewedEndpointReVisit(mockServer),
await mockedDappViewedEndpointFirstVisit(mockServer),
await mockedDappViewedEndpointReVisit(mockServer),
await mockPermissionApprovedEndpoint(mockServer),
];
}
Expand Down Expand Up @@ -247,7 +275,7 @@ describe('Dapp viewed Event @no-mmi', function () {

it('is sent when connecting dapp with two accounts', async function () {
async function mockSegment(mockServer) {
return [await mockedDappViewedEndpoint(mockServer)];
return [await mockedDappViewedEndpointFirstVisit(mockServer)];
}
await withFixtures(
{
Expand Down Expand Up @@ -299,8 +327,8 @@ describe('Dapp viewed Event @no-mmi', function () {
it('is sent when reconnect to a dapp that has been connected before', async function () {
async function mockSegment(mockServer) {
return [
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpointFirstVisit(mockServer),
await mockedDappViewedEndpointReVisit(mockServer),
];
}

Expand Down
Loading