import { test } from '@japa/runner'
import { Patch } from '../../../../src/mocking/lib/Patch.js'
import type { MediaPatchRevision } from '../../../../src/patch/types.js'

test.group('Patch', (group) => {
  let patch: Patch

  group.each.setup(() => {
    patch = new Patch()
  })

  test('mediaPatchRevision() returns a valid object', ({ assert }) => {
    const result = patch.mediaPatchRevision()
    assert.typeOf(result, 'object')
    assert.property(result, 'id')
    assert.property(result, 'timestamp')
    assert.property(result, 'patch')
    assert.property(result, 'version')
  })

  test('mediaPatchRevision(init) allows overriding properties', ({ assert }) => {
    const init: Partial<MediaPatchRevision> = {
      id: 'custom-id',
      version: 99,
    }
    const result = patch.mediaPatchRevision(init)
    assert.equal(result.id, 'custom-id')
    assert.equal(result.version, 99)
  })

  test('mediaPatchRevisions() returns a list', ({ assert }) => {
    const result = patch.mediaPatchRevisions(5)
    assert.isArray(result)
    assert.lengthOf(result, 5)
  })

  test('mediaPatchRevisions(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<MediaPatchRevision> = {
      version: 123,
    }
    const result = patch.mediaPatchRevisions(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.version, 123)
    })
  })
})
