Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Sep 28, 2023
1 parent 20b97c2 commit 1134fd8
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"@atproto/lex-cli": "workspace:^",
"@atproto/pds": "workspace:^",
"@atproto/dev-env": "workspace:^",
"common-tags": "^1.8.2"
}
}
44 changes: 19 additions & 25 deletions packages/api/tests/bsky-agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {
CloseFn,
runTestServer,
TestServerInfo,
} from '@atproto/pds/tests/_util'
import { TestNetworkNoAppView } from '@atproto/dev-env'
import { BskyAgent, ComAtprotoRepoPutRecord, AppBskyActorProfile } from '..'

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

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

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

const getProfileDisplayName = async (
Expand All @@ -35,7 +29,7 @@ describe('agent', () => {
}

it('upsertProfile correctly creates and updates profiles.', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user1.test',
Expand Down Expand Up @@ -67,7 +61,7 @@ describe('agent', () => {
})

it('upsertProfile correctly handles CAS failures.', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user2.test',
Expand Down Expand Up @@ -106,7 +100,7 @@ describe('agent', () => {
})

it('upsertProfile wont endlessly retry CAS failures.', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user3.test',
Expand Down Expand Up @@ -135,7 +129,7 @@ describe('agent', () => {
})

it('upsertProfile validates the record.', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user4.test',
Expand All @@ -153,70 +147,70 @@ describe('agent', () => {

describe('app', () => {
it('should retrieve the api app', () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
expect(agent.app).toBe(agent.api.app)
})
})

describe('post', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.post({ text: 'foo' })).rejects.toThrow('Not logged in')
})
})

describe('deletePost', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.deletePost('foo')).rejects.toThrow('Not logged in')
})
})

describe('like', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.like('foo', 'bar')).rejects.toThrow('Not logged in')
})
})

describe('deleteLike', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.deleteLike('foo')).rejects.toThrow('Not logged in')
})
})

describe('repost', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.repost('foo', 'bar')).rejects.toThrow('Not logged in')
})
})

describe('deleteRepost', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.deleteRepost('foo')).rejects.toThrow('Not logged in')
})
})

describe('follow', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.follow('foo')).rejects.toThrow('Not logged in')
})
})

describe('deleteFollow', () => {
it('should throw if no session', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })
await expect(agent.deleteFollow('foo')).rejects.toThrow('Not logged in')
})
})

describe('preferences methods', () => {
it('gets and sets preferences correctly', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user5.test',
Expand Down Expand Up @@ -714,7 +708,7 @@ describe('agent', () => {
})

it('resolves duplicates correctly', async () => {
const agent = new BskyAgent({ service: server.url })
const agent = new BskyAgent({ service: network.pds.url })

await agent.createAccount({
handle: 'user6.test',
Expand Down
2 changes: 2 additions & 0 deletions packages/dev-env/src/pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class TestPds {
jwtSecret: 'jwt-secret',
serviceHandleDomains: ['.test'],
sequencerLeaderLockId: uniqueLockId(),
bskyAppViewUrl: 'https://appview.invalid',
bskyAppViewDid: 'did:example:invalid',
bskyAppViewCdnUrlPattern: 'http://cdn.appview.com/%s/%s/%s',
repoSigningKeyK256PrivateKeyHex: repoSigningPriv,
plcRotationKeyK256PrivateKeyHex: plcRotationPriv,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export async function up(db: Kysely<unknown>, dialect: Dialect): Promise<void> {
.addColumn('emailConfirmedAt', 'varchar')
.execute()

await db.schema.dropIndex('user_account_password_reset_token_idx').execute()

await db.schema
.alterTable('user_account')
.dropColumn('passwordResetToken')
Expand All @@ -41,6 +43,13 @@ export async function down(db: Kysely<unknown>): Promise<void> {
.dropColumn('emailConfirmedAt')
.execute()

await db.schema
.createIndex('user_account_password_reset_token_idx')
.unique()
.on('user_account')
.column('passwordResetToken')
.execute()

await db.schema
.alterTable('user_account')
.addColumn('passwordResetToken', 'varchar')
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/tests/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export const runTestServer = async (
didPlcUrl: plcUrl,
serviceHandleDomains: ['.test'],
sequencerLeaderLockId: uniqueLockId(),
bskyAppViewUrl: 'https://appview.invalid',
bskyAppViewDid: 'did:example:invalid',
repoSigningKeyK256PrivateKeyHex: repoSigningPriv,
plcRotationKeyK256PrivateKeyHex: plcRotationPriv,
adminPassword: ADMIN_PASSWORD,
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1134fd8

Please sign in to comment.