Files
X-Financial/web/tests/notification-states-service.test.mjs

21 lines
733 B
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import test from 'node:test'
import {
NOTIFICATION_STATE_BATCH_SIZE,
chunkNotificationStatePatches
} from '../src/services/notificationStates.js'
test('notification state patches are split before posting to backend', () => {
const patches = Array.from({ length: 205 }, (_, index) => ({
notification_id: `document:owned:DOC-${index + 1}`,
read: true
}))
const chunks = chunkNotificationStatePatches(patches)
assert.equal(NOTIFICATION_STATE_BATCH_SIZE, 100)
assert.deepEqual(chunks.map((chunk) => chunk.length), [100, 100, 5])
assert.equal(chunks[0][0].notification_id, 'document:owned:DOC-1')
assert.equal(chunks[2][4].notification_id, 'document:owned:DOC-205')
})