Files
psf-memo/psf-memo-db/test/unit/use-cases/list-followers.unit.js
T
Chris Troutner bb7b5a6cfd Review and harden follow-user: kill mutation survivors
Add unit test pinning FollowQuery._nextString exclusive upper bound and
empty-string/non-string validation-rejection cases for the follow use
cases, killing the remaining mutation survivors. Update mutation manifests
and add the follow-user architectural review report.

By architect.
2026-08-27 11:23:01 -07:00

66 lines
1.9 KiB
JavaScript

/*
Unit tests for the ListFollowers use case.
*/
import { assert } from 'chai'
import ListFollowers from '../../../src/use-cases/list-followers.js'
function makeAdapters (followers) {
return {
followQuery: {
async listFollowers (followeeAddr) {
return followers
}
}
}
}
describe('#ListFollowers', () => {
it('should throw when adapters is missing', () => {
assert.throws(() => new ListFollowers({}), /Adapters required/)
})
it('should throw when followQuery adapter is missing', () => {
assert.throws(() => new ListFollowers({ adapters: {} }), /followQuery adapter required/)
})
it('should return the followers list', async () => {
const useCase = new ListFollowers({ adapters: makeAdapters(['bitcoincash:a', 'bitcoincash:b']) })
const result = await useCase.execute({ followeeAddr: 'bitcoincash:followee' })
assert.deepEqual(result, {
followeeAddr: 'bitcoincash:followee',
followers: ['bitcoincash:a', 'bitcoincash:b']
})
})
it('should reject a missing followeeAddr', async () => {
const useCase = new ListFollowers({ adapters: makeAdapters([]) })
try {
await useCase.execute({})
assert.fail('expected error')
} catch (err) {
assert.match(err.message, /followeeAddr is required/)
}
})
it('should reject an empty-string followeeAddr', async () => {
const useCase = new ListFollowers({ adapters: makeAdapters([]) })
try {
await useCase.execute({ followeeAddr: '' })
assert.fail('expected error')
} catch (err) {
assert.match(err.message, /followeeAddr is required/)
}
})
it('should reject a non-string followeeAddr', async () => {
const useCase = new ListFollowers({ adapters: makeAdapters([]) })
try {
await useCase.execute({ followeeAddr: 42 })
assert.fail('expected error')
} catch (err) {
assert.match(err.message, /followeeAddr is required/)
}
})
})