Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/FeedbackKit/Cache/ContentCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Foundation
public struct ContentCache: Sendable {
private let directory: URL

public init(directory: URL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
.appendingPathComponent("FeedbackKit")) {
self.directory = directory
try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)
}
public init(directory: URL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
.appendingPathComponent("FeedbackKit")) {
self.directory = directory
try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)
}

public func save<T: Encodable>(_ value: T, as key: String) throws {
let data = try Self.encoder.encode(value)
Expand Down
16 changes: 16 additions & 0 deletions Tests/FeedbackKitTests/HTTPFeedbackAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ final class HTTPFeedbackAPITests: XCTestCase {
XCTAssertEqual(error as? APIError, .unauthorized)
}
}

// A baseURL with a path prefix (e.g. https://host/feedback) must be preserved
// when building request URLs, not dropped — guards the request(path:) path-join.
func testListPostsPreservesBaseURLPathPrefix() async throws {
let cfg = URLSessionConfiguration.ephemeral
cfg.protocolClasses = [StubURLProtocol.self]
let session = URLSession(configuration: cfg)
let api = HTTPFeedbackAPI(baseURL: URL(string: "https://fb.example.com/feedback")!,
session: session, tokenProvider: { nil })
StubURLProtocol.handler = { req in
XCTAssertEqual(req.url?.path, "/feedback/api/public/v1/posts")
let body = #"{"data":[],"meta":{"pagination":{"cursor":null,"hasMore":false}}}"#
return (HTTPURLResponse(url: req.url!, statusCode: 200, httpVersion: nil, headerFields: nil)!, Data(body.utf8))
}
_ = try await api.listPosts(boardId: nil, sort: .newest, cursor: nil)
}
}
Loading