# Copyright © The Debusine Developers
# See the AUTHORS file at the top-level directory of this distribution
#
# This file is part of Debusine. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution. No part of Debusine, including this file, may be copied,
# modified, propagated, or distributed except according to the terms
# contained in the LICENSE file.

"""Unit tests for the Delay task."""

from debusine.server.tasks.wait.delay import Delay
from debusine.server.tasks.wait.models import DelayData
from debusine.server.tasks.wait.tests.helpers import WaitTaskTestCase


class DelayTaskTests(WaitTaskTestCase[Delay]):
    """Test the Delay task."""

    SAMPLE_TASK_DATA = {"delay_until": "2024-01-01T12:00:00+00:00"}

    def test_compute_scheduler_tags(self) -> None:
        self.assertComputesSchedulerTags()

    def test_missing_delay_until(self) -> None:
        """The `delay_until` field is required."""
        self.task_data = {}
        error_msg = r"delay_until\n\s+Field required.*type=missing"
        with self.assertRaisesRegex(ValueError, error_msg):
            DelayData.model_validate(self.task_data)

    def test_no_additional_properties(self) -> None:
        """Assert no additional properties."""
        self.task_data["input"] = {}
        error_msg = "Extra inputs are not permitted"
        with self.assertRaisesRegex(ValueError, error_msg):
            DelayData.model_validate(self.task_data)

    def test_label(self) -> None:
        """Test get_label."""
        self.assertEqual(
            self.task.get_label(), "delay until 2024-01-01 12:00:00+00:00"
        )
