mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-04-30 21:52:28 +08:00
feat: migrate profile legacy test, closes #3709
This commit is contained in:
76
tests/specs/profile/profile.spec.ts
Normal file
76
tests/specs/profile/profile.spec.ts
Normal 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'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user