Skip to content

Commit

Permalink
Refactor tests to make better use of dev-env (#1690)
Browse files Browse the repository at this point in the history
* refactor pds tests to use dev env

* refactor bsky tests

* fix pds test

* tidy bsky tests
  • Loading branch information
dholms authored Sep 29, 2023
1 parent 1134fd8 commit 5b2f4d1
Show file tree
Hide file tree
Showing 120 changed files with 747 additions and 1,492 deletions.
36 changes: 15 additions & 21 deletions packages/api/tests/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { defaultFetchHandler } from '@atproto/xrpc'
import {
CloseFn,
runTestServer,
TestServerInfo,
} from '@atproto/pds/tests/_util'
import {
AtpAgent,
AtpAgentFetchHandlerResponse,
AtpSessionEvent,
AtpSessionData,
} from '..'
import { TestNetworkNoAppView } from '@atproto/dev-env'

describe('agent', () => {
let server: TestServerInfo
let close: CloseFn
let network: TestNetworkNoAppView

beforeAll(async () => {
server = await runTestServer({
network = await TestNetworkNoAppView.create({
dbPostgresSchema: 'api_agent',
})
close = server.close
})

afterAll(async () => {
await close()
await network.close()
})

it('creates a new session on account creation.', async () => {
Expand All @@ -34,7 +28,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

const res = await agent.createAccount({
handle: 'user1.test',
Expand Down Expand Up @@ -74,7 +68,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent1 = new AtpAgent({ service: server.url, persistSession })
const agent1 = new AtpAgent({ service: network.pds.url, persistSession })

const email = '[email protected]'
await agent1.createAccount({
Expand All @@ -83,7 +77,7 @@ describe('agent', () => {
password: 'password',
})

const agent2 = new AtpAgent({ service: server.url, persistSession })
const agent2 = new AtpAgent({ service: network.pds.url, persistSession })
const res1 = await agent2.login({
identifier: 'user2.test',
password: 'password',
Expand Down Expand Up @@ -122,7 +116,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent1 = new AtpAgent({ service: server.url, persistSession })
const agent1 = new AtpAgent({ service: network.pds.url, persistSession })

await agent1.createAccount({
handle: 'user3.test',
Expand All @@ -133,7 +127,7 @@ describe('agent', () => {
throw new Error('No session created')
}

const agent2 = new AtpAgent({ service: server.url, persistSession })
const agent2 = new AtpAgent({ service: network.pds.url, persistSession })
const res1 = await agent2.resumeSession(agent1.session)

expect(agent2.hasSession).toEqual(true)
Expand Down Expand Up @@ -165,7 +159,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

// create an account and a session with it
await agent.createAccount({
Expand Down Expand Up @@ -230,7 +224,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

// create an account and a session with it
await agent.createAccount({
Expand Down Expand Up @@ -309,7 +303,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

try {
await agent.login({
Expand Down Expand Up @@ -349,7 +343,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

// create an account and a session with it
await agent.createAccount({
Expand Down Expand Up @@ -420,7 +414,7 @@ describe('agent', () => {
newHandlerCallCount++
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

await agent.createAccount({
handle: 'user7.test',
Expand Down Expand Up @@ -452,7 +446,7 @@ describe('agent', () => {
sessions.push(sess)
}

const agent = new AtpAgent({ service: server.url, persistSession })
const agent = new AtpAgent({ service: network.pds.url, persistSession })

await expect(
agent.createAccount({
Expand Down
16 changes: 5 additions & 11 deletions packages/api/tests/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import {
CloseFn,
runTestServer,
TestServerInfo,
} from '@atproto/pds/tests/_util'
import { AtpAgent, ComAtprotoServerCreateAccount } from '..'
import { TestNetworkNoAppView } from '@atproto/dev-env'

describe('errors', () => {
let server: TestServerInfo
let network: TestNetworkNoAppView
let client: AtpAgent
let close: CloseFn

beforeAll(async () => {
server = await runTestServer({
network = await TestNetworkNoAppView.create({
dbPostgresSchema: 'known_errors',
})
client = new AtpAgent({ service: server.url })
close = server.close
client = network.pds.getClient()
})

afterAll(async () => {
await close()
await network.close()
})

it('constructs the correct error instance', async () => {
Expand Down
24 changes: 12 additions & 12 deletions packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ Array [
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(5)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(5)@jpeg",
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(6)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(6)@jpeg",
},
Expand Down Expand Up @@ -475,7 +475,7 @@ Array [
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand All @@ -486,7 +486,7 @@ Array [
},
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand Down Expand Up @@ -679,12 +679,12 @@ Array [
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(5)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(5)@jpeg",
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(6)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(6)@jpeg",
},
Expand Down Expand Up @@ -735,7 +735,7 @@ Array [
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand All @@ -746,7 +746,7 @@ Array [
},
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand Down Expand Up @@ -906,12 +906,12 @@ Array [
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(4)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(4)@jpeg",
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(5)/cids(5)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(5)/cids(5)@jpeg",
},
Expand Down Expand Up @@ -962,7 +962,7 @@ Array [
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand All @@ -973,7 +973,7 @@ Array [
},
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand Down
8 changes: 4 additions & 4 deletions packages/bsky/tests/__snapshots__/indexing.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Array [
"$type": "app.bsky.embed.images#view",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(2)/cids(5)@jpeg",
"thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(2)/cids(5)@jpeg",
},
Expand Down Expand Up @@ -134,7 +134,7 @@ Array [
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand Down Expand Up @@ -245,7 +245,7 @@ Array [
"$type": "app.bsky.embed.images",
"images": Array [
Object {
"alt": "tests/image/fixtures/key-landscape-small.jpg",
"alt": "tests/sample-img/key-landscape-small.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand All @@ -256,7 +256,7 @@ Array [
},
},
Object {
"alt": "tests/image/fixtures/key-alt.jpg",
"alt": "tests/sample-img/key-alt.jpg",
"image": Object {
"$type": "blob",
"mimeType": "image/jpeg",
Expand Down
8 changes: 3 additions & 5 deletions packages/bsky/tests/algos/hot-classic.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import AtpAgent, { AtUri } from '@atproto/api'
import { SeedClient } from '../seeds/client'
import { TestNetwork, SeedClient } from '@atproto/dev-env'
import basicSeed from '../seeds/basic'
import { makeAlgos } from '../../src'
import { TestNetwork } from '@atproto/dev-env'

describe('algo hot-classic', () => {
let network: TestNetwork
Expand All @@ -26,8 +25,7 @@ describe('algo hot-classic', () => {
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
const pdsAgent = new AtpAgent({ service: network.pds.url })
sc = new SeedClient(pdsAgent)
sc = network.getSeedClient()
await basicSeed(sc)

alice = sc.dids.alice
Expand All @@ -43,7 +41,7 @@ describe('algo hot-classic', () => {
it('returns well liked posts', async () => {
const img = await sc.uploadFile(
alice,
'tests/image/fixtures/key-landscape-small.jpg',
'tests/sample-img/key-landscape-small.jpg',
'image/jpeg',
)
const one = await sc.post(alice, 'first post', undefined, [img])
Expand Down
8 changes: 3 additions & 5 deletions packages/bsky/tests/algos/whats-hot.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HOUR } from '@atproto/common'
import AtpAgent, { AtUri } from '@atproto/api'
import { SeedClient } from '../seeds/client'
import { TestNetwork, SeedClient } from '@atproto/dev-env'
import basicSeed from '../seeds/basic'
import { makeAlgos } from '../../src'
import { TestNetwork } from '@atproto/dev-env'

describe.skip('algo whats-hot', () => {
let network: TestNetwork
Expand All @@ -28,8 +27,7 @@ describe.skip('algo whats-hot', () => {
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
const pdsAgent = new AtpAgent({ service: network.pds.url })
sc = new SeedClient(pdsAgent)
sc = network.getSeedClient()
await basicSeed(sc)

alice = sc.dids.alice
Expand All @@ -46,7 +44,7 @@ describe.skip('algo whats-hot', () => {
it('returns well liked posts', async () => {
const img = await sc.uploadFile(
alice,
'tests/image/fixtures/key-landscape-small.jpg',
'tests/sample-img/key-landscape-small.jpg',
'image/jpeg',
)
const one = await sc.post(carol, 'carol is in the chat')
Expand Down
6 changes: 2 additions & 4 deletions packages/bsky/tests/algos/with-friends.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import AtpAgent, { AtUri } from '@atproto/api'
import { RecordRef, SeedClient } from '../seeds/client'
import userSeed from '../seeds/users'
import { makeAlgos } from '../../src'
import { TestNetwork } from '@atproto/dev-env'
import { TestNetwork, SeedClient, RecordRef } from '@atproto/dev-env'

describe.skip('algo with friends', () => {
let network: TestNetwork
Expand All @@ -28,8 +27,7 @@ describe.skip('algo with friends', () => {
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
const pdsAgent = new AtpAgent({ service: network.pds.url })
sc = new SeedClient(pdsAgent)
sc = network.getSeedClient()
await userSeed(sc)

alice = sc.dids.alice
Expand Down
5 changes: 2 additions & 3 deletions packages/bsky/tests/auto-moderator/fuzzy-matcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TestNetwork, SeedClient } from '@atproto/dev-env'
import { FuzzyMatcher, encode } from '../../src/auto-moderator/fuzzy-matcher'
import { TestNetwork } from '@atproto/dev-env'
import { SeedClient } from '../seeds/client'
import basicSeed from '../seeds/basic'
import { AtpAgent } from '@atproto/api'
import { ImageInvalidator } from '../../src/image/invalidator'
Expand All @@ -25,7 +24,7 @@ describe('fuzzy matcher', () => {
})
fuzzyMatcher = new FuzzyMatcher(['evil', 'mean', 'bad'], ['baddie'])
agent = network.pds.getClient()
sc = new SeedClient(agent)
sc = network.getSeedClient()
await basicSeed(sc)
await network.processAll()
alice = sc.dids.alice
Expand Down
Loading

0 comments on commit 5b2f4d1

Please sign in to comment.