Skip to content
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
164 changes: 163 additions & 1 deletion tests/smoke/ramps/onramp-unified-buy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import { Mockttp } from 'mockttp';
import { setupRegionAwareOnRampMocks } from '../../api-mocking/mock-responses/ramps/ramps-region-aware-mock-setup';
import { remoteFeatureFlagRampsUnifiedEnabled } from '../../api-mocking/mock-responses/feature-flags-mocks';
import { setupRemoteFeatureFlagsMock } from '../../api-mocking/helpers/remoteFeatureFlagsHelper';
import {
getEventsPayloads,
EventPayload,
} from '../../helpers/analytics/helpers';
import SoftAssert from '../../framework/SoftAssert';
import { RampsRegion } from '../../framework/types';
import { UnifiedRampRoutingType } from '../../../app/reducers/fiatOrders/types';

const selectedRegion = RampsRegions[RampsRegionsEnum.UNITED_STATES];

Expand All @@ -25,6 +32,20 @@ const unifiedBuyV2Mocks = async (mockServer: Mockttp) => {
await setupRegionAwareOnRampMocks(mockServer, selectedRegion);
};

const tokenToBuy = 'ETH';

const eventsToCheck: EventPayload[] = [];

const expectedEvents = {
RampsButtonClicked: 'Ramps Button Clicked',
RampsTokenSelected: 'Ramps Token Selected',
};

const expectedEventNames = [
expectedEvents.RampsButtonClicked,
expectedEvents.RampsTokenSelected,
];

describe(SmokeRamps('Onramp Unified Buy'), () => {
it('build quote', async () => {
await withFixtures(
Expand All @@ -36,6 +57,13 @@ describe(SmokeRamps('Onramp Unified Buy'), () => {
.build(),
restartDevice: true,
testSpecificMock: unifiedBuyV2Mocks,
endTestfn: async ({ mockServer }) => {
const events = await getEventsPayloads(
mockServer,
expectedEventNames,
);
eventsToCheck.push(...events);
},
},
async () => {
await loginToApp();
Expand All @@ -49,7 +77,7 @@ describe(SmokeRamps('Onramp Unified Buy'), () => {
Once the code is completed, this should be removed and the test shall go past the continue button
*/
await device.disableSynchronization();
await TokenSelectScreen.tapTokenByName('ETH');
await TokenSelectScreen.tapTokenByName(tokenToBuy);
await BuildQuoteView.tapKeypadDeleteButton(1);
await BuildQuoteView.tapKeypadDeleteButton(1);

Expand All @@ -59,4 +87,138 @@ describe(SmokeRamps('Onramp Unified Buy'), () => {
},
);
});

it('validates the segment events from the onramp unified buy test', async () => {
const softAssert = new SoftAssert();
for (const ev of expectedEventNames) {
const event = eventsToCheck.find((event) => event.event === ev);
await softAssert.checkAndCollect(
async () => await Assertions.checkIfValueIsDefined(event),
`${ev}: Should be defined`,
);
}

// Ramps Button Clicked - Property checks
const rampsButtonClicked = eventsToCheck.find(
(event) => event.event === expectedEvents.RampsButtonClicked,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfValueIsDefined(
rampsButtonClicked?.properties.location,
),
`Ramps Button Clicked: location should be defined`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfValueIsDefined(
rampsButtonClicked?.properties.chain_id_destination,
),
`Ramps Button Clicked: chain_id_destination should be defined`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfValueIsDefined(
rampsButtonClicked?.properties.ramp_type,
),
`Ramps Button Clicked: ramp_type should be defined`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfValueIsDefined(
rampsButtonClicked?.properties.region,
),
`Ramps Button Clicked: region should be defined`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfValueIsDefined(
rampsButtonClicked?.properties.ramp_routing,
),
`Ramps Button Clicked: ramp_routing should be defined`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectContains(
rampsButtonClicked?.properties ?? {},
{ location: 'FundActionMenu' },
),
`Ramps Button Clicked: location should be FundActionMenu`,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectContains(
rampsButtonClicked?.properties ?? {},
{ ramp_type: 'UNIFIED_BUY' },
),
`Ramps Button Clicked: ramp_type should be UNIFIED_BUY`,
);
const rampsButtonClickedRegion = JSON.parse(
rampsButtonClicked?.properties?.region as string,
) as RampsRegion;
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectContains(
rampsButtonClickedRegion as unknown as Record<string, unknown>,
{ id: selectedRegion.id, name: selectedRegion.name },
),
`Ramps Button Clicked: region should be ${selectedRegion.name} and ${selectedRegion.id}`,
);

// Ramps Token Selected - Property checks
const rampsTokenSelected = eventsToCheck.find(
(event) => event.event === expectedEvents.RampsTokenSelected,
);
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectHasKeysAndValidValues(
rampsTokenSelected?.properties ?? {},
{
ramp_type: 'string',
region: 'string',
chain_id: 'string',
currency_destination: 'string',
currency_destination_symbol: 'string',
currency_destination_network: 'string',
currency_source: 'string',
is_authenticated: 'boolean',
token_caip19: 'string',
token_symbol: 'string',
ramp_routing: 'string',
},
),
`Ramps Token Selected: Should have the correct properties`,
);

const rampsTokenSelectedRegion = JSON.parse(
rampsTokenSelected?.properties?.region as string,
) as RampsRegion;
await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectContains(
rampsTokenSelectedRegion as unknown as Record<string, unknown>,
{ id: selectedRegion.id, name: selectedRegion.name },
),
`Ramps Token Selected: region should be ${selectedRegion.name} and ${selectedRegion.id}`,
);

await softAssert.checkAndCollect(
async () =>
await Assertions.checkIfObjectContains(
rampsTokenSelected?.properties ?? {},
{
token_symbol: tokenToBuy,
token_caip19: 'eip155:1/slip44:60',
currency_destination: 'eip155:1/slip44:60',
currency_destination_symbol: tokenToBuy,
currency_destination_network:
CustomNetworks.Tenderly.Mainnet.providerConfig.nickname,
ramp_routing: UnifiedRampRoutingType.DEPOSIT,
},
),
`Ramps Token Selected: token_symbol should be ${tokenToBuy}`,
);

softAssert.throwIfErrors();
});
});
Loading