         configuration.protocolClasses = [MockURLProtocol.self]
         return TUSClient(config: TUSConfig(server: liveDemoPath), sessionIdentifier: "TEST", storageDirectory: relativeStoragePath, session: URLSession.init(configuration: configuration))
     }
-
+    
+    private func prepareNetworkForSuccesfulUploads(data: Data) {
+        MockURLProtocol.prepareResponse(for: "POST") {
+            MockURLProtocol.Response(status: 200, headers: ["Location": "www.somefakelocation.com"], data: nil)
+        }
+        
+        MockURLProtocol.prepareResponse(for: "PATCH") {
+            MockURLProtocol.Response(status: 200, headers: ["Upload-Offset": String(data.count)], data: nil)
+        }
+        
+    }
     
     // MARK: - Adding files and data to upload
     


        otherClientContents = try FileManager.default.contentsOfDirectory(at: otherLocation, includingPropertiesForKeys: nil)
        XCTAssert(!otherClientContents.isEmpty)
    }
    
}

        XCTAssert(contents.isEmpty, "Expected the client to delete the file")
    }

    func testClientDeletesFilesOnCompletion() throws {
        // If a file is done uploading (as said by status), but not yet deleted.
        // Then the file can be deleted right after fetching the status.
        
        let cacheDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
            let data = Data("abcdef".utf8)
        // Store file in cache
        func storeFileInCache() throws -> URL {
            let targetLocation = cacheDir.appendingPathComponent("myfile.txt")
            try data.write(to: targetLocation)
            return targetLocation
        }
        
        prepareNetworkForSuccesfulUploads(data: data)
        
        var contents = try FileManager.default.contentsOfDirectory(at: fullStoragePath, includingPropertiesForKeys: nil)
        XCTAssert(contents.isEmpty)
        
        let uploadCount = 5
        for _ in 0..<uploadCount {
            let url = try storeFileInCache()
            try client.uploadFileAt(filePath: url)
        }
        
        contents = try FileManager.default.contentsOfDirectory(at: fullStoragePath, includingPropertiesForKeys: nil)
        XCTAssertEqual(uploadCount * 2, contents.count) // Every upload has a metadata file
        
        let expectation = expectation(description: "Waiting for upload to finished")
        expectation.expectedFulfillmentCount = uploadCount
        tusDelegate.finishUploadExpectation = expectation
        waitForExpectations(timeout: 3, handler: nil)
        XCTAssertEqual(5, tusDelegate.finishedUploads.count)
        
        contents = try FileManager.default.contentsOfDirectory(at: fullStoragePath, includingPropertiesForKeys: nil)
        XCTAssert(contents.isEmpty)
    }
    
    func testDeleteUploadedFilesOnStartup() {
