feat: migrate profile legacy test, closes #3709

This commit is contained in:
alter-eggo
2023-06-20 18:23:25 +04:00
committed by Anastasios
parent 91bc023b88
commit 1c01d544a2
10 changed files with 142 additions and 150 deletions

View File

@@ -0,0 +1,76 @@
import { Page } from '@playwright/test';
import { ProfileUpdatingPage } from '@tests/page-object-models/profile-updating.page';
import { TestAppPage } from '@tests/page-object-models/test-app.page';
import { test } from '../../fixtures/fixtures';
test.describe.configure({ mode: 'serial' });
test.describe('Profile updating', () => {
function interceptGaiaRequest(page: Page): Promise<Buffer> {
return new Promise(resolve => {
page.on('request', request => {
if (request.url().startsWith('https://hub.blockstack.org/store')) {
const requestBody = request.postDataBuffer();
if (request.method() === 'GET') return;
if (requestBody === null) return;
resolve(requestBody);
}
});
});
}
let testAppPage: TestAppPage;
test.beforeEach(async ({ extensionId, globalPage, onboardingPage, context }) => {
await globalPage.setupAndUseApiCalls(extensionId);
await onboardingPage.signInWithTestAccount(extensionId);
testAppPage = await TestAppPage.openDemoPage(context);
await testAppPage.signIn();
const accountsPage = await context.waitForEvent('page');
await accountsPage.locator('text="Account 1"').click();
await testAppPage.page.bringToFront();
await testAppPage.page.click('text=Profile', {
timeout: 30000,
});
await accountsPage.close();
});
test('should show profile details', async ({ context }) => {
await testAppPage.clickUpdateProfileButton();
const profileUpdatingPage = new ProfileUpdatingPage(await context.waitForEvent('page'));
const name = profileUpdatingPage.page.getByText('twitter');
const nameText = await name.innerText();
test.expect(nameText).toBe('https://twitter.com/twitterHandle');
});
test('should show an error for invalid profile', async ({ context }) => {
await testAppPage.clickUpdateInvalidProfileButton();
const profileUpdatingPage = new ProfileUpdatingPage(await context.waitForEvent('page'));
const error = await profileUpdatingPage.waitForError(
'Invalid profile update request (Profile must follow Person schema).'
);
test.expect(error).toBeTruthy();
});
test('should send a signed profile token to gaia', async ({ context }) => {
await testAppPage.clickUpdateProfileButton();
const profileUpdatingPage = new ProfileUpdatingPage(await context.waitForEvent('page'));
const [gaiaRequestBody] = await Promise.all([
interceptGaiaRequest(profileUpdatingPage.page),
profileUpdatingPage.clickUpdateProfileButton(),
]);
const { decodedToken } = JSON.parse(gaiaRequestBody.toString())[0];
test.expect(decodedToken?.header?.alg).toEqual('ES256K');
test.expect(decodedToken?.payload?.claim?.name).toContain('Name ');
test
.expect(decodedToken?.payload?.claim?.image?.[0]?.contentUrl)
.toEqual(
'https://byzantion.mypinata.cloud/ipfs/Qmb84UcaMr1MUwNbYBnXWHM3kEaDcYrKuPWwyRLVTNKELC/2256.png'
);
});
});