Skip to content

Commit

Permalink
Merge branch 'main' into xmtp-proto-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas authored Sep 6, 2022
2 parents 8a3f4fa + b8085fd commit 50a2660
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class ApiClient {
for (const envelope of page) {
out.push(envelope)
if (limit && out.length === limit) {
break
return out
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/ApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('Query', () => {
})
})

it('stops when limit is used', async () => {
const apiMock = createQueryMock([createEnvelope()], 3)
const result = await client.query(
{ contentTopics: [CONTENT_TOPIC] },
{ limit: 2 }
)
expect(result).toHaveLength(2)
expect(apiMock).toHaveBeenCalledTimes(2)
})

it('stops when receiving some results and a null cursor', async () => {
const apiMock = createQueryMock([createEnvelope()], 1)
const result = await client.query({ contentTopics: [CONTENT_TOPIC] }, {})
Expand Down
9 changes: 9 additions & 0 deletions test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ describe('Client', () => {
assert.equal(msg.senderAddress, alice.address)
assert.equal(msg.content, 'Hello from Alice')
})

it('handles limiting page size', async () => {
const bobConvo = await alice.conversations.newConversation(bob.address)
for (let i = 0; i < 5; i++) {
await bobConvo.send('hi')
}
const messages = await bobConvo.messages({ limit: 2 })
expect(messages).toHaveLength(2)
})
})
})
})
Expand Down

0 comments on commit 50a2660

Please sign in to comment.