Refactor memo-post for lower complexity

- Extract _throwIfInvalid and _reflectPost helpers from post()
- Consolidate duplicate validation tests into one parameterized test

By refactorer.
This commit is contained in:
Chris Troutner
2026-08-25 16:17:23 -07:00
parent 64a7f78032
commit 8e2693ad08
2 changed files with 31 additions and 30 deletions
+10 -19
View File
@@ -89,26 +89,17 @@ test('posting an empty memo throws a validation error and broadcasts nothing', a
assert.equal(feed.posts.length, 0)
})
test('posting a whitespace-only memo throws a validation error and broadcasts nothing', async () => {
const wallet = fakeWallet()
const memoPost = new MemoPost({ wallet })
test('posting a whitespace-only or non-string memo throws a validation error and broadcasts nothing', async () => {
for (const invalid of [' ', 42]) {
const wallet = fakeWallet()
const memoPost = new MemoPost({ wallet })
await assert.rejects(
memoPost.post(' '),
(err) => err.code === 'memo_validation'
)
assert.equal(wallet.broadcasts.length, 0)
})
test('posting a non-string memo throws a validation error', async () => {
const wallet = fakeWallet()
const memoPost = new MemoPost({ wallet })
await assert.rejects(
memoPost.post(42),
(err) => err.code === 'memo_validation'
)
assert.equal(wallet.broadcasts.length, 0)
await assert.rejects(
memoPost.post(invalid),
(err) => err.code === 'memo_validation'
)
assert.equal(wallet.broadcasts.length, 0)
}
})
test('posting an over-long memo (218) throws a length error and broadcasts nothing', async () => {