mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Reduce paginated client page size to 50
By coder.
This commit is contained in:
@@ -91,7 +91,7 @@ test('load forwards limit and offset to the memo db client', async () => {
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 10, offset: 20 } }])
|
||||
})
|
||||
|
||||
test('load defaults limit to 100 and offset to 0', async () => {
|
||||
test('load defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getFollowingFeed (addr, params) {
|
||||
@@ -103,7 +103,7 @@ test('load defaults limit to 100 and offset to 0', async () => {
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 100, offset: 0 } }])
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 50, offset: 0 } }])
|
||||
})
|
||||
|
||||
test('load throws when no memo db client is provided', async () => {
|
||||
|
||||
@@ -79,7 +79,7 @@ test('load forwards limit and offset to the memo db client', async () => {
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 10, offset: 20 } }])
|
||||
})
|
||||
|
||||
test('load defaults limit to 100 and offset to 0', async () => {
|
||||
test('load defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getNotifications (addr, params) {
|
||||
@@ -91,7 +91,7 @@ test('load defaults limit to 100 and offset to 0', async () => {
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 100, offset: 0 } }])
|
||||
assert.deepEqual(calls, [{ addr: MY_ADDRESS, params: { limit: 50, offset: 0 } }])
|
||||
})
|
||||
|
||||
test('load throws when no memo db client is provided', async () => {
|
||||
|
||||
@@ -75,7 +75,7 @@ test('load throws when no address is provided', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('load defaults limit to 100 and offset to 0', async () => {
|
||||
test('load defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const addr = 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d'
|
||||
const memoDb = {
|
||||
@@ -91,7 +91,7 @@ test('load defaults limit to 100 and offset to 0', async () => {
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ a: addr, params: { limit: 100, offset: 0 } }])
|
||||
assert.deepEqual(calls, [{ a: addr, params: { limit: 50, offset: 0 } }])
|
||||
})
|
||||
|
||||
test('load sets pagination to null when the API returns none', async () => {
|
||||
|
||||
@@ -66,7 +66,7 @@ test('load throws when no memo db client is provided', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('load defaults limit to 100 and offset to 0', async () => {
|
||||
test('load defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getRecentPosts (params) {
|
||||
@@ -78,5 +78,5 @@ test('load defaults limit to 100 and offset to 0', async () => {
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ limit: 100, offset: 0 }])
|
||||
assert.deepEqual(calls, [{ limit: 50, offset: 0 }])
|
||||
})
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Unit tests for the recent profiles page controller.
|
||||
|
||||
The recent profiles page is a thin, testable wrapper around the MemoDb client.
|
||||
It loads the paginated list of recent profiles and exposes each profile.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const RecentProfilesPage = require('../../src/services/recent-profiles-page')
|
||||
|
||||
function makeMemoDb (profiles, pagination) {
|
||||
return {
|
||||
async getRecentProfiles ({ limit, offset }) {
|
||||
return { profiles, pagination }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test('load returns profiles and pagination', async () => {
|
||||
const profiles = [
|
||||
{ addr: 'bitcoincash:a', text: 'Alice' },
|
||||
{ addr: 'bitcoincash:b', text: 'Bob' }
|
||||
]
|
||||
const page = new RecentProfilesPage({ memoDb: makeMemoDb(profiles, { total: 2 }) })
|
||||
|
||||
const result = await page.load()
|
||||
|
||||
assert.deepEqual(result.profiles, profiles)
|
||||
assert.equal(result.pagination.total, 2)
|
||||
})
|
||||
|
||||
test('load throws when no memo db client is provided', async () => {
|
||||
const page = new RecentProfilesPage({})
|
||||
|
||||
await assert.rejects(
|
||||
() => page.load(),
|
||||
/requires a memo db client/
|
||||
)
|
||||
})
|
||||
|
||||
test('load forwards limit and offset to the memo db client', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getRecentProfiles (params) {
|
||||
calls.push(params)
|
||||
return { profiles: [], pagination: {} }
|
||||
}
|
||||
}
|
||||
const page = new RecentProfilesPage({ memoDb })
|
||||
|
||||
await page.load({ limit: 10, offset: 20 })
|
||||
|
||||
assert.deepEqual(calls, [{ limit: 10, offset: 20 }])
|
||||
})
|
||||
|
||||
test('load defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getRecentProfiles (params) {
|
||||
calls.push(params)
|
||||
return { profiles: [], pagination: {} }
|
||||
}
|
||||
}
|
||||
const page = new RecentProfilesPage({ memoDb })
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ limit: 50, offset: 0 }])
|
||||
})
|
||||
|
||||
test('canLoadMore reflects pagination.hasMore', async () => {
|
||||
const pageMore = new RecentProfilesPage({
|
||||
memoDb: makeMemoDb([], { hasMore: true })
|
||||
})
|
||||
await pageMore.load()
|
||||
assert.equal(pageMore.canLoadMore(), true)
|
||||
|
||||
const pageDone = new RecentProfilesPage({
|
||||
memoDb: makeMemoDb([], { hasMore: false })
|
||||
})
|
||||
await pageDone.load()
|
||||
assert.equal(pageDone.canLoadMore(), false)
|
||||
})
|
||||
|
||||
test('getProfile returns a loaded profile by address', async () => {
|
||||
const profiles = [{ addr: 'bitcoincash:a', text: 'Alice' }]
|
||||
const page = new RecentProfilesPage({ memoDb: makeMemoDb(profiles, {}) })
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.equal(page.getProfile('bitcoincash:a').text, 'Alice')
|
||||
})
|
||||
|
||||
test('exposes the recent profiles path', () => {
|
||||
assert.equal(RecentProfilesPage.RECENT_PROFILES_PATH, '/profile/recent')
|
||||
})
|
||||
@@ -49,7 +49,7 @@ test('submit forwards query, limit and offset to the memo db client', async () =
|
||||
assert.deepEqual(calls, [{ q: 'alice', params: { limit: 10, offset: 20 } }])
|
||||
})
|
||||
|
||||
test('submit defaults limit to 100 and offset to 0', async () => {
|
||||
test('submit defaults limit to 50 and offset to 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async search (q, params) {
|
||||
@@ -62,7 +62,7 @@ test('submit defaults limit to 100 and offset to 0', async () => {
|
||||
page.setQuery('memo')
|
||||
await page.submit()
|
||||
|
||||
assert.deepEqual(calls, [{ q: 'memo', params: { limit: 100, offset: 0 } }])
|
||||
assert.deepEqual(calls, [{ q: 'memo', params: { limit: 50, offset: 0 } }])
|
||||
})
|
||||
|
||||
test('submit throws when no memo db client is provided', async () => {
|
||||
|
||||
@@ -71,7 +71,7 @@ test('load forwards limit and offset to the memo db client', async () => {
|
||||
assert.deepEqual(calls, [{ room: 'bitcoin', params: { limit: 10, offset: 20 } }])
|
||||
})
|
||||
|
||||
test('load defaults limit and offset', async () => {
|
||||
test('load defaults limit and offset to 50 and 0', async () => {
|
||||
const calls = []
|
||||
const memoDb = {
|
||||
async getTopicPosts (room, params) {
|
||||
@@ -89,7 +89,7 @@ test('load defaults limit and offset', async () => {
|
||||
|
||||
await page.load()
|
||||
|
||||
assert.deepEqual(calls, [{ limit: 100, offset: 0 }])
|
||||
assert.deepEqual(calls, [{ limit: 50, offset: 0 }])
|
||||
})
|
||||
|
||||
test('stores the pagination returned by the memo db client', async () => {
|
||||
|
||||
Reference in New Issue
Block a user