/**
 * Template for Node.js tests using Japa
 * Copy this file and rename it to create new test suites.
 */
import { test } from '@japa/runner'

test.group('YourModuleName', (group) => {
  // Setup runs before each test in the group
  group.each.setup(() => {
    // Initialize test data, mocks, etc.
  })

  // Teardown runs after each test in the group
  group.each.teardown(() => {
    // Clean up resources, restore mocks, etc.
  })

  test('should describe what this test does', ({ assert }) => {
    // Arrange
    const input = 'test-input'

    // Act
    const result = input.toUpperCase()

    // Assert
    assert.equal(result, 'TEST-INPUT')
  })

  test('should test async operations', async ({ assert }) => {
    // Arrange
    const promise = Promise.resolve('async-result')

    // Act
    const result = await promise

    // Assert
    assert.equal(result, 'async-result')
  })

  test('should test error cases', async ({ assert }) => {
    // Assert that function throws
    await assert.rejects(() => Promise.reject(new Error('Expected error')), 'Expected error')
  })

  test('should use sinon for mocking', ({ sinon, assert }) => {
    // Arrange
    const mockObject = {
      method: () => 'original',
    }
    const stub = sinon.stub(mockObject, 'method')
    stub.returns('mocked')

    // Act
    const result = mockObject.method()

    // Assert
    assert.equal(result, 'mocked')

    // Cleanup (optional - sinon auto-restores)
    stub.restore()
  })

  test('should test with custom timeout', async ({ assert }) => {
    // This test has a longer timeout
    const start = Date.now()
    await new Promise((resolve) => setTimeout(resolve, 100))
    const elapsed = Date.now() - start
    assert.isAtLeast(elapsed, 90)
  }).timeout(5000) // 5 second timeout

  test('should be skipped', ({ assert }) => {
    // This test is skipped
    assert.fail('This should not run')
  }).skip(true)
})
