//
//  ZockerhoehleTests.swift
//  ZockerhoehleTests
//
//  Created by Julian-Steffen Müller on 17.05.21.
//  Copyright © 2021 Julian-Steffen Müller. All rights reserved.
//

import XCTest
@testable import Zockerhoehle

class ZockerhoehleTests: XCTestCase {

    let icloud_drive_seperators : [String] = ["iCloud~Zockerhoehle", "Documents"]
    
    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func test_url_icloud_split() throws {
        // VALID FILES
        let url_valid_file : URL = URL(string: "file:///private/var/mobile/Library/Mobile%20Documents/iCloud~Zockerhoehle/Documents/backup.json")!
        let url_valid_file_in_subfolder : URL = URL(string: "file:///private/var/mobile/Library/Mobile%20Documents/iCloud~Zockerhoehle/Documents/consoles/ps4.png")!
        
        XCTAssertEqual(url_valid_file.relative_path_after(pathComponent: icloud_drive_seperators), "backup.json")
        XCTAssertEqual(url_valid_file_in_subfolder.relative_path_after(pathComponent: icloud_drive_seperators), "consoles/ps4.png")

        //INVALID URL
        let url_unvalid_url_2 : URL = URL(string: "http://mueller.haus")!
        
        XCTAssertEqual(url_unvalid_url_2.relative_path_after(pathComponent: icloud_drive_seperators), .none)
        
        
        // INVALID FILE
        let url_unvalid_file : URL = URL(string: "file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/photo.jpg")!
    
        XCTAssertEqual(url_unvalid_file.relative_path_after(pathComponent: icloud_drive_seperators), .none)
        
    }

}
