Spots: a corrupt NZB is a result, not a reason to read the listing again
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee898be8c8
commit
1520a8dc35
2 files changed
+32
-8
No files matched your search
@@ -2,7 +2,7 @@ import { test } from '@japa/runner'
|
||||
import { createHash } from 'node:crypto'
|
||||
import db from '@adonisjs/lucid/services/db'
|
||||
import testUtils from '@adonisjs/core/services/test_utils'
|
||||
import SpotService, { isDummyNzb } from '#services/SpotService'
|
||||
import SpotService, { isDummyNzb, NzbUnreadable } from '#services/SpotService'
|
||||
import SearchService from '#services/SearchService'
|
||||
|
||||
test.group('SpotService listings', (group) => {
|
||||
@@ -117,7 +117,7 @@ test.group('SpotService reading listings', (group) => {
|
||||
<segments><segment bytes="${bytes}" number="1">a1@x</segment></segments></file></nzb>`
|
||||
|
||||
/** A listed spot, as worker:spots leaves an old one, with its article and NZB as given. */
|
||||
async function listedSpot(id: string, read: { description?: string; nzb?: string | null; error?: string }) {
|
||||
async function listedSpot(id: string, read: { description?: string; nzb?: string | null; error?: string; nzbError?: Error }) {
|
||||
await db.table('spots').insert({
|
||||
message_id: id, group_name: 'free.pt', article_number: 1, title: `Listed ${id}`, poster: 'Bart', key_id: 7, size: 700_000_000,
|
||||
posted_at: new Date('2019-05-01T12:00:00Z'), verified: true, created_at: new Date(), status: 'pending',
|
||||
@@ -129,7 +129,10 @@ test.group('SpotService reading listings', (group) => {
|
||||
if (read.error) throw new Error(read.error)
|
||||
return { header: { size: 700_000_000 }, xml: { description: read.description ?? '', nzbSegments: ['n@x'] } }
|
||||
}
|
||||
service.readNzb = async () => read.nzb ?? null
|
||||
service.readNzb = async () => {
|
||||
if (read.nzbError) throw read.nzbError
|
||||
return read.nzb ?? null
|
||||
}
|
||||
}
|
||||
|
||||
const restore = () => {
|
||||
@@ -179,5 +182,12 @@ test.group('SpotService reading listings', (group) => {
|
||||
await listedSpot('l6@spot.net', { error: '430 No Such Article' })
|
||||
assert.deepEqual(await SpotService.readListings(10, 1), { gone: 1 })
|
||||
assert.isNotNull((await db.from('spots').where('message_id', 'l6@spot.net').first()).nzb_read_at)
|
||||
|
||||
// A corrupt NZB is a result, not something to read again.
|
||||
await listedSpot('l7@spot.net', { nzbError: new NzbUnreadable('invalid code lengths set') })
|
||||
assert.deepEqual(await SpotService.readListings(10, 1), { 'nzb-unreadable': 1 })
|
||||
const l7 = await db.from('spots').where('message_id', 'l7@spot.net').first()
|
||||
assert.isNotNull(l7.nzb_read_at)
|
||||
assert.equal(l7.error, 'NZB unreadable: invalid code lengths set')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user