# test_snapshots_and_storage_migrator.py
#
# Project: AutoArchive
# License: GNU GPLv3
#
# Copyright (C) 2003 - 2026 Róbert Čerňanský



__all__ = ["TestSnapshotsAndStorageMigrator"]



import os.path
import unittest
from unittest.mock import call

from mock import MagicMock, ANY

from AutoArchive._update._snapshots_and_storage_migrator import _SnapshotsAndStorageMigrator
from AutoArchive._update.tests._update_test_utils import _UpdateTestUtils



class TestSnapshotsAndStorageMigrator(unittest.TestCase):

    __OLD_DATA_DIR_PATH = "test old user configuration directory path"
    __NEW_DATA_DIR_PATH = "test new user configuration directory path"



    def test_PathsAreDifferent_OldDirExistsAndIsNotCurrent_NewDirNotExists(self):
        storageDir = os.path.join(self.__OLD_DATA_DIR_PATH, "storage")
        snapshotsDir = os.path.join(self.__OLD_DATA_DIR_PATH, "snapshots")
        newStorageDir = os.path.join(self.__NEW_DATA_DIR_PATH, "storage")
        newSnapshotsDir = os.path.join(self.__NEW_DATA_DIR_PATH, "snapshots")

        oldDataDirMock = _UpdateTestUtils.setupAppDirMock(path = self.__OLD_DATA_DIR_PATH, isCurrent = False)
        newDataDirMock = _UpdateTestUtils.setupAppDirMock(path = self.__NEW_DATA_DIR_PATH)
        fileSystemMock = _UpdateTestUtils.setupFileSystemMock(existingPaths = [storageDir, snapshotsDir])

        _SnapshotsAndStorageMigrator(fileSystemMock, oldDataDirMock, newDataDirMock, MagicMock()).migrate()

        fileSystemMock.moveWithBackup.assert_has_calls(
            [call(storageDir, newStorageDir, ANY), call(snapshotsDir, newSnapshotsDir, ANY)], any_order = True)
        oldDataDirMock.setToCurrentVersion.assert_not_called()
        newDataDirMock.setToCurrentVersion.assert_called_once()
