From e66799a0330f776a66aee5c9d36ef70026eb7578 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Thu, 28 Mar 2024 10:50:57 -0300 Subject: [PATCH] test: add integration test for newly added methods --- Sources/Storage/SupabaseStorage.swift | 3 +++ .../StorageClientIntegrationTests.swift | 14 +++++++++++++- .../StorageTests/SupabaseStorageClient+Test.swift | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Sources/Storage/SupabaseStorage.swift b/Sources/Storage/SupabaseStorage.swift index b7615ec6..3429520a 100644 --- a/Sources/Storage/SupabaseStorage.swift +++ b/Sources/Storage/SupabaseStorage.swift @@ -1,6 +1,9 @@ import _Helpers import Foundation +public typealias SupabaseLogger = _Helpers.SupabaseLogger +public typealias SupabaseLogMessage = _Helpers.SupabaseLogMessage + public struct StorageClientConfiguration { public let url: URL public var headers: [String: String] diff --git a/Tests/StorageTests/StorageClientIntegrationTests.swift b/Tests/StorageTests/StorageClientIntegrationTests.swift index d3d69193..3f120190 100644 --- a/Tests/StorageTests/StorageClientIntegrationTests.swift +++ b/Tests/StorageTests/StorageClientIntegrationTests.swift @@ -10,7 +10,7 @@ import XCTest final class StorageClientIntegrationTests: XCTestCase { static var apiKey: String { - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU" } static var supabaseURL: String { @@ -148,6 +148,18 @@ final class StorageClientIntegrationTests: XCTestCase { ) } + func testCreateAndUploadToSignedUploadURL() async throws { + let path = "README-\(UUID().uuidString).md" + let url = try await storage.from(bucketId).createSignedUploadURL(path: path) + let key = try await storage.from(bucketId).uploadToSignedURL( + path: url.path, + token: url.token, + file: uploadData ?? Data() + ) + + XCTAssertEqual(key, "\(bucketId)/\(path)") + } + private func uploadTestData() async throws { _ = try await storage.from(bucketId).upload( path: "README.md", file: uploadData ?? Data(), options: FileOptions(cacheControl: "3600") diff --git a/Tests/StorageTests/SupabaseStorageClient+Test.swift b/Tests/StorageTests/SupabaseStorageClient+Test.swift index 79352763..44581fb4 100644 --- a/Tests/StorageTests/SupabaseStorageClient+Test.swift +++ b/Tests/StorageTests/SupabaseStorageClient+Test.swift @@ -22,8 +22,14 @@ extension SupabaseStorageClient { "Apikey": apiKey, ], session: session, - logger: nil + logger: ConsoleLogger() ) ) } } + +struct ConsoleLogger: SupabaseLogger { + func log(message: SupabaseLogMessage) { + print(message.description) + } +}