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

feat(e2e): Migrated e2e tests for metadata providers api errors #16443

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

HajekOndrej
Copy link
Contributor

Description

Migrated tests for metadata provider API errors

Related Issue

Resolve

Screenshots:

@HajekOndrej HajekOndrej requested a review from Vere-Grey January 17, 2025 13:26
@HajekOndrej HajekOndrej force-pushed the migrate-metadata-tests branch 3 times, most recently from 7ba04e9 to 1f0468f Compare January 17, 2025 15:25
@HajekOndrej HajekOndrej force-pushed the migrate-metadata-tests branch from 1f0468f to 7c0e54b Compare January 17, 2025 15:43
@HajekOndrej HajekOndrej enabled auto-merge (squash) January 20, 2025 08:47
Copy link
Contributor

@Vere-Grey Vere-Grey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have suggested few improvements - up to discussion
The original tests missed some key verifications, I know we plan to do bigger refactoring but I would still proposed adding those few expects
And I need help understanding one or two things.

@@ -1,5 +1,6 @@
import { Page } from '@playwright/test';

import * as metadataUtils from '@trezor/suite/src/utils/suite/metadata';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do focus importing

Suggested change
import * as metadataUtils from '@trezor/suite/src/utils/suite/metadata';
import { encrypt } from '@trezor/suite/src/utils/suite/metadata';

@@ -77,11 +78,30 @@ export class MetadataProviderMock {
}

@step()
stop() {
setNextResponse(response: Record<string, any>): void {
if (!this.providerMock) {
throw new Error('Provider mock not initialized');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's DRY this if (!this.providerMock) block by introducing a getter that will do the assertion and throw :)

Comment on lines +35 to +39
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();

await settingsPage.navigateTo('application');
await settingsPage.metadataSwitch.click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential to DRY these steps to before each.
not sure before which steps metadataProviderMock.setFileContent needs to be set tho ...

Comment on lines +59 to +65
await metadataPage.metadataInput.fill('Kvooo');
await page.keyboard.press('Enter');

// Validate the error message in the toast notification
await expect(page.getByTestId('@toast/error')).toHaveText(
'Error: Failed to save labeling data: Error in call to API function "files/upload": The given OAuth 2 access token is malformed.',
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a validation that the label has still the original text?

await expect(metadataPage.accountLabel(AccountLabelId.BitcoinDefault1)).toHaveText('<original name>')

Comment on lines +90 to +117
metadataProviderMock.setNextResponse({
status: 200,
body: {
name: {
given_name: 'dog',
surname: 'cat',
familiar_name: 'kitty-dog',
display_name: 'dog-cat',
abbreviated_name: 'DC',
},
email: 'some@mail.com',
email_verified: true,
profile_photo_url: 'foo',
disabled: false,
country: 'CZ',
locale: 'en',
referral_link: 'foo',
is_paired: false,
},
});

metadataProviderMock.setNextResponse({
status: 429,
body: 'Rate limited!',
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand this part. Can we have a short call so I could get the context
I dont get the order of those two. Responses are served as FIFO
I found similar object in packages/e2e-utils/src/mocks/dropbox.ts:77:

        // https://api.dropboxapi.com/2/users/get_current_account
        app.post('/2/users/get_current_account', (_req, res) => {
            const user = {
                name: {
                    given_name: 'dog',
                    surname: 'cat',
                    familiar_name: 'kitty-dog',
                    display_name: 'dog-cat',
                    abbreviated_name: 'DC',
                },
                email: 'some@mail.com',
                email_verified: true,
                profile_photo_url: 'foo',
                disabled: false,
                country: 'CZ',
                locale: 'en',
                referral_link: 'foo',
                is_paired: false,
            };

Comment on lines +119 to +121
await page.getByTestId('@account-menu/btc/normal/0').click();
await metadataPage.editLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test does not have any verification of success of that the initial try failed and succeded on retry (not sure that info about retring is vibisble)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await expect(metadataPage.accountLabel(AccountLabelId.BitcoinDefault1)).toHaveText('Kvooo')

await metadataPage.editLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
});

test('Incomplete data returned from provider', async ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand the impact of 'incomplete data' on suite and what should happen and what shouldn't.
Like should the rename fail? or is it just that the comunication is retried and does not fall apartt.

Maybe this is a candidate for the later refactoring. I have feeling that we miss some verifications here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding of the original test, the ability to rename the label after the incomplete data is sent is the verification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants