From 1d87592570822f91dcf995f3f0644b7e0c6e3a8f Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Wed, 13 Mar 2024 16:07:58 -0500 Subject: [PATCH] fix: gaia profile test --- tests/mocks/mock-profile.ts | 61 +++++++++++++++++++++++++++++ tests/specs/profile/profile.spec.ts | 45 ++++++++++++--------- 2 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 tests/mocks/mock-profile.ts diff --git a/tests/mocks/mock-profile.ts b/tests/mocks/mock-profile.ts new file mode 100644 index 00000000000..2297a667a58 --- /dev/null +++ b/tests/mocks/mock-profile.ts @@ -0,0 +1,61 @@ +export const mockGaiaProfileResponse = [ + { + token: + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJqdGkiOiIwYTFkNGVhZC01YmQyLTQzYWYtYmQ5YS0wMWRiNTcxZTA0NmUiLCJpYXQiOiIyMDI0LTAzLTEzVDE4OjI5OjQxLjI1N1oiLCJleHAiOiIyMDI1LTAzLTEzVDE4OjI5OjQxLjI1N1oiLCJzdWJqZWN0Ijp7InB1YmxpY0tleSI6IjAzMjliMDc2YmMyMGY3YjE1OTJiMmExYTVjYjkxZGZlZmU4Yzk2NmU1MGUyNTY0NThlMjNkZDJjNWQ2M2Y4ZjFhZiJ9LCJpc3N1ZXIiOnsicHVibGljS2V5IjoiMDMyOWIwNzZiYzIwZjdiMTU5MmIyYTFhNWNiOTFkZmVmZThjOTY2ZTUwZTI1NjQ1OGUyM2RkMmM1ZDYzZjhmMWFmIn0sImNsYWltIjp7IkB0eXBlIjoiUGVyc29uIiwiQGNvbnRleHQiOiJodHRwOi8vc2NoZW1hLm9yZyIsImFwcHMiOnsiaHR0cDovL2xvY2FsaG9zdDozMDAwIjoiaHR0cHM6Ly9nYWlhLmhpcm8uc28vaHViLzFKdmkxTmlZSGFNdmpVZFRhbTRITHJQU2RVakg1TXFONUYvIn0sImFwcHNNZXRhIjp7Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCI6ey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4BH0uO5hMpWeA', + decodedToken: { + header: { + typ: 'JWT', + alg: 'ES256K', + }, + payload: { + jti: '0a1d4ead-5bd2-43af-bd9a-01db571e046e', + iat: '2024-03-13T18:29:41.257Z', + exp: '2025-03-13T18:29:41.257Z', + subject: { + publicKey: '0329b076bc20f7b1592b2a1a5cb91dfefe8c966e50e256458e23dd2c5d63f8f1af', + }, + issuer: { + publicKey: '0329b076bc20f7b1592b2a1a5cb91dfefe8c966e50e256458e23dd2c5d63f8f1af', + }, + claim: { + '@type': 'Person', + '@context': 'http://schema.org', + apps: { + 'http://localhost:3000': 'https://gaia.hiro.so/hub/1Jvi1NiYHaMvjUdTam4HLrPSdUjH5MqN5F/', + }, + appsMeta: { + 'http://localhost:3000': { + storage: 'https://gaia.hiro.so/hub/1Jvi1NiYHaMvjUdTam4HLrPSdUjH5MqN5F/', + publicKey: '03d4d6806c776051ac42bf8385fbcb6da84ec7169194d6e8d6e1bc74ecb9bc40ce', + }, + }, + name: 'Name 1710351212509', + image: [ + { + '@type': 'ImageObject', + name: 'avatar', + contentUrl: + 'https://byzantion.mypinata.cloud/ipfs/Qmb84UcaMr1MUwNbYBnXWHM3kEaDcYrKuPWwyRLVTNKELC/2256.png', + }, + { + '@type': 'ImageObject', + name: 'background', + contentUrl: + 'https://unsplash.com/photos/h0Vxgz5tyXA/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8Mnx8YmFja2dyb3VuZHxlbnwwfDB8fHwxNjY2NDA0Nzkx&force=true&w=640', + }, + ], + sameAs: ['https://twitter.com/twitterHandle', 'https://instagram.com/instaHandle'], + owns: [ + { + '@type': 'OwnershipInfo', + identifier: + 'bip122:000000000019d6689c085ae165831e93:12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S', + }, + ], + }, + }, + signature: + 'I0qDc2l6iZrRVXAc7GLPxngmRloZfCukugj3GuFHyZHxJtsy3oIs3sroQcXGzkLlxAI35HAra4BH0uO5hMpWeA', + }, + }, +]; diff --git a/tests/specs/profile/profile.spec.ts b/tests/specs/profile/profile.spec.ts index 8aec764d5f5..8f3d719c4d0 100644 --- a/tests/specs/profile/profile.spec.ts +++ b/tests/specs/profile/profile.spec.ts @@ -1,3 +1,4 @@ +import { mockGaiaProfileResponse } from '@tests/mocks/mock-profile'; import { TestAppPage } from '@tests/page-object-models/test-app.page'; import { UpdateProfileRequestPage } from '@tests/page-object-models/update-profile-request.page'; @@ -13,23 +14,17 @@ test.describe('Profile updating', () => { await onboardingPage.signInWithTestAccount(extensionId); testAppPage = await TestAppPage.openDemoPage(context); await testAppPage.signIn(); + }); + + test('should show an error for invalid profile', async ({ context }) => { const accountsPage = await context.waitForEvent('page'); await accountsPage.locator('text="Account 1"').click({ force: true }); await testAppPage.page.bringToFront(); - await testAppPage.page.click('text=Profile'); + await testAppPage.page.click('text=Profile', { + timeout: 30000, + }); await accountsPage.close(); - }); - - test('should show profile details', async ({ context }) => { - await testAppPage.clickUpdateProfileButton(); - const profileUpdatingPage = new UpdateProfileRequestPage(await context.waitForEvent('page')); - const name = profileUpdatingPage.page.getByText('twitter'); - const nameText = await name.innerText(); - test.expect(nameText).toBe('https://twitter.com/twitterHandle'); - await profileUpdatingPage.page.close(); - }); - test('should show an error for invalid profile', async ({ context }) => { await testAppPage.clickUpdateInvalidProfileButton(); const profileUpdatingPage = new UpdateProfileRequestPage(await context.waitForEvent('page')); const error = await profileUpdatingPage.waitForUpdateProfileRequestError( @@ -41,8 +36,7 @@ test.describe('Profile updating', () => { }); }); -// Skipping this for now to see if shard 3 passes -test.describe('Gaia request', () => { +test.describe('Gaia profile request', () => { let testAppPage: TestAppPage; test.beforeEach(async ({ extensionId, globalPage, onboardingPage, context }) => { @@ -50,23 +44,37 @@ test.describe('Gaia request', () => { await onboardingPage.signInWithTestAccount(extensionId); testAppPage = await TestAppPage.openDemoPage(context); await testAppPage.signIn(); + }); + + test('should send a signed profile token to gaia', async ({ context }) => { const accountsPage = await context.waitForEvent('page'); await accountsPage.locator('text="Account 2"').click({ force: true }); await testAppPage.page.bringToFront(); - await testAppPage.page.click('text=Profile'); - await accountsPage.close(); - }); + await testAppPage.page.click('text=Profile', { + timeout: 30000, + }); - test.skip('should send a signed profile token to gaia', async ({ context }) => { await testAppPage.clickUpdateProfileButton(); const profileUpdatingPage = new UpdateProfileRequestPage(await context.waitForEvent('page')); const requestPromise = profileUpdatingPage.page.waitForRequest('https://hub.blockstack.org/*'); + await profileUpdatingPage.page.route('https://gaia.hiro.so/hub/*', async route => { + await route.fulfill({ + status: 200, + contentType: 'application/octet-stream', + body: JSON.stringify(mockGaiaProfileResponse), + }); + }); + await profileUpdatingPage.page.route('https://hub.blockstack.org/*', async route => { await route.abort(); }); + const name = profileUpdatingPage.page.getByText('twitter'); + const nameText = await name.innerText(); + test.expect(nameText).toBe('https://twitter.com/twitterHandle'); + await profileUpdatingPage.clickUpdateProfileButton(); const request = await requestPromise; @@ -74,7 +82,6 @@ test.describe('Gaia request', () => { if (!requestBody) return; const { decodedToken } = JSON.parse(requestBody.toString())[0]; - test.expect(decodedToken).toBeDefined(); test.expect(decodedToken?.header?.alg).toEqual('ES256K');