Skip to content

Commit

Permalink
feat: cross-region storage test
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Feb 26, 2025
1 parent 34d8f85 commit 6a64375
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"new:package": "NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
"prepublish": "pnpm run build",
"test:client": "vitest --project @lens-protocol/client --no-file-parallelism",
"test:cross-region": "vitest --project @lens-protocol/client crossRegion.test.ts",
"test:react": "vitest --project @lens-protocol/react --no-file-parallelism",
"test:storage": "vitest --project @lens-protocol/storage --no-file-parallelism",
"test": "vitest --no-file-parallelism"
Expand Down
56 changes: 56 additions & 0 deletions packages/client/src/crossRegion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { beforeAll, describe, it } from 'vitest';

import * as storage from '@lens-chain/storage-client';
import type { Account } from '@lens-protocol/graphql';
import * as metadata from '@lens-protocol/metadata';
import { assertOk, never, uri } from '@lens-protocol/types';

import { createAccountWithUsername, fetchAccount, setAccountMetadata } from './actions/account';
import type { SessionClient } from './clients';
import { loginAsOnboardingUser, wallet } from './test-utils';
import { handleOperationWith } from './viem';

describe('Given an instance of the StorageClient bound to staging', { timeout: 10000 }, () => {
const storageClient = storage.StorageClient.create(storage.staging);
let newAccount: Account;
let sessionClient: SessionClient;

beforeAll(async () => {
const initialMetadata = metadata.account({
name: 'John Doe',
});
const result = await loginAsOnboardingUser().andThen((sessionClient) =>
createAccountWithUsername(sessionClient, {
username: { localName: `testname${Date.now()}` },
metadataUri: uri(`data:application/json,${JSON.stringify(initialMetadata)}`), // empty at first
})
.andThen(handleOperationWith(wallet))
.andThen(sessionClient.waitForTransaction)
.andThen((txHash) => fetchAccount(sessionClient, { txHash }))
.andThen((account) => {
newAccount = account ?? never('Account not found');
return sessionClient.switchAccount({
account: newAccount.address,
});
}),
);

assertOk(result);

sessionClient = result.value;
});

describe('When I upload a file from one region', () => {
it('Then it should be accessible from the Lens API in another region', async () => {
const updated = metadata.account({
name: 'Bruce Wayne',
});
const resource = await storageClient.uploadAsJson(updated);
const result = await setAccountMetadata(sessionClient, {
metadataUri: resource.uri,
});

assertOk(result);

Check failure on line 53 in packages/client/src/crossRegion.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test

src/crossRegion.test.ts > Given an instance of the StorageClient bound to staging > When I upload a file from one region > Then it should be accessible from the Lens API in another region

InvariantError: Expected result to be Ok: [GraphQL] Bad request - Metadata URI not found ❯ Module.l ../types/src/helpers/assertions.ts:31:11 ❯ src/crossRegion.test.ts:53:7
});
});
});

0 comments on commit 6a64375

Please sign in to comment.