diff options
Diffstat (limited to 'jest')
-rw-r--r-- | jest/jestSetup.js | 17 | ||||
-rw-r--r-- | jest/test-pds.ts | 32 | ||||
-rw-r--r-- | jest/test-utils.tsx | 10 |
3 files changed, 36 insertions, 23 deletions
diff --git a/jest/jestSetup.js b/jest/jestSetup.js index 35bb1772f..f7d136a8c 100644 --- a/jest/jestSetup.js +++ b/jest/jestSetup.js @@ -1,10 +1,19 @@ /* global jest */ - +import {configure} from '@testing-library/react-native' import 'react-native-gesture-handler/jestSetup' + +configure({asyncUtilTimeout: 20000}) + jest.mock('@react-native-async-storage/async-storage', () => require('@react-native-async-storage/async-storage/jest/async-storage-mock'), ) -jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter') +jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter', () => { + const {EventEmitter} = require('events') + return { + __esModule: true, + default: EventEmitter, + } +}) // Silence the warning: Animated: `useNativeDriver` is not supported jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper') @@ -55,3 +64,7 @@ jest.mock('@segment/analytics-react-native', () => ({ flush: jest.fn(), }), })) + +jest.mock('react-native-permissions', () => + require('react-native-permissions/mock'), +) diff --git a/jest/test-pds.ts b/jest/test-pds.ts index 31dcb3cb8..32f3bc9b0 100644 --- a/jest/test-pds.ts +++ b/jest/test-pds.ts @@ -8,7 +8,7 @@ import PDSServer, { ServerConfig as PDSServerConfig, } from '@atproto/pds' import * as plc from '@atproto/plc' -import AtpApi, {ServiceClient} from '@atproto/api' +import AtpAgent from '@atproto/api' export interface TestUser { email: string @@ -16,7 +16,7 @@ export interface TestUser { declarationCid: string handle: string password: string - api: ServiceClient + agent: AtpAgent } export interface TestUsers { @@ -87,6 +87,8 @@ export async function createServer(): Promise<TestPDS> { dbPostgresUrl: process.env.DB_POSTGRES_URL, blobstoreLocation: `${blobstoreLoc}/blobs`, blobstoreTmp: `${blobstoreLoc}/tmp`, + maxSubscriptionBuffer: 200, + repoBackfillLimitMs: 1e3 * 60 * 60, }) const db = PDSDatabase.memory() @@ -112,11 +114,11 @@ export async function createServer(): Promise<TestPDS> { async function genMockData(pdsUrl: string): Promise<TestUsers> { const date = dateGen() - const clients = { - loggedout: AtpApi.service(pdsUrl), - alice: AtpApi.service(pdsUrl), - bob: AtpApi.service(pdsUrl), - carla: AtpApi.service(pdsUrl), + const agents = { + loggedout: new AtpAgent({service: pdsUrl}), + alice: new AtpAgent({service: pdsUrl}), + bob: new AtpAgent({service: pdsUrl}), + carla: new AtpAgent({service: pdsUrl}), } const users: TestUser[] = [ { @@ -125,7 +127,7 @@ async function genMockData(pdsUrl: string): Promise<TestUsers> { declarationCid: '', handle: 'alice.test', password: 'hunter2', - api: clients.alice, + agent: agents.alice, }, { email: 'bob@test.com', @@ -133,7 +135,7 @@ async function genMockData(pdsUrl: string): Promise<TestUsers> { declarationCid: '', handle: 'bob.test', password: 'hunter2', - api: clients.bob, + agent: agents.bob, }, { email: 'carla@test.com', @@ -141,7 +143,7 @@ async function genMockData(pdsUrl: string): Promise<TestUsers> { declarationCid: '', handle: 'carla.test', password: 'hunter2', - api: clients.carla, + agent: agents.carla, }, ] const alice = users[0] @@ -150,18 +152,18 @@ async function genMockData(pdsUrl: string): Promise<TestUsers> { let _i = 1 for (const user of users) { - const res = await clients.loggedout.com.atproto.account.create({ + const res = await agents.loggedout.api.com.atproto.account.create({ email: user.email, handle: user.handle, password: user.password, }) - user.api.setHeader('Authorization', `Bearer ${res.data.accessJwt}`) - const {data: profile} = await user.api.app.bsky.actor.getProfile({ + user.agent.api.setHeader('Authorization', `Bearer ${res.data.accessJwt}`) + const {data: profile} = await user.agent.api.app.bsky.actor.getProfile({ actor: user.handle, }) user.did = res.data.did user.declarationCid = profile.declaration.cid - await user.api.app.bsky.actor.profile.create( + await user.agent.api.app.bsky.actor.profile.create( {did: user.did}, { displayName: ucfirst(user.handle).slice(0, -5), @@ -172,7 +174,7 @@ async function genMockData(pdsUrl: string): Promise<TestUsers> { // everybody follows everybody const follow = async (author: TestUser, subject: TestUser) => { - await author.api.app.bsky.graph.follow.create( + await author.agent.api.app.bsky.graph.follow.create( {did: author.did}, { subject: { diff --git a/jest/test-utils.tsx b/jest/test-utils.tsx index 5a74a6ef6..0a22d792b 100644 --- a/jest/test-utils.tsx +++ b/jest/test-utils.tsx @@ -3,17 +3,15 @@ import {render} from '@testing-library/react-native' import {GestureHandlerRootView} from 'react-native-gesture-handler' import {RootSiblingParent} from 'react-native-root-siblings' import {SafeAreaProvider} from 'react-native-safe-area-context' -import {RootStoreProvider} from '../src/state' -import {ThemeProvider} from '../src/view/lib/ThemeContext' -import {mockedRootStore} from '../__mocks__/state-mock' +import {RootStoreProvider, RootStoreModel} from '../src/state' +import {ThemeProvider} from '../src/lib/ThemeContext' -const customRender = (ui: any, rootStore?: any) => +const customRender = (ui: any, rootStore: RootStoreModel) => render( // eslint-disable-next-line react-native/no-inline-styles <GestureHandlerRootView style={{flex: 1}}> <RootSiblingParent> - <RootStoreProvider - value={rootStore != null ? rootStore : mockedRootStore}> + <RootStoreProvider value={rootStore}> <ThemeProvider theme="light"> <SafeAreaProvider>{ui}</SafeAreaProvider> </ThemeProvider> |