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
4 changes: 1 addition & 3 deletions InterlinedList/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ struct SettingsView: View {
// Guard against spurious saves when syncFromUser sets the initial value on appear.
let serverTheme = authState.user?.theme ?? "system"
guard newValue != serverTheme else { return }
// "system" means no explicit preference — send nil so the server clears it.
// Sending the string "system" is rejected or treated as default (light) by the server.
Task { await save(theme: newValue == "system" ? nil : newValue) }
Task { await save(theme: newValue) }
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions InterlinedListTests/APIClientTests/APIClientProfileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,25 @@ final class APIClientProfileTests: XCTestCase {
let user = try await sut.updateUserSettings(theme: "light")
XCTAssertEqual(user.username, "alice")
}

func test_updateUserSettings_systemTheme_sendsLiteralSystemString() async throws {
session.stub(json: #"{"user":\#(userJSON)}"#)
_ = try await sut.updateUserSettings(theme: "system")
let body = try XCTUnwrap(session.lastRequest?.httpBody)
let json = try XCTUnwrap(try? JSONSerialization.jsonObject(with: body) as? [String: Any])
XCTAssertEqual(json["theme"] as? String, "system", #"Body must be {"theme":"system"}"#)
XCTAssertEqual(json.count, 1, "Only the changed field belongs in the body")
}

func test_updateUserSettings_nilTheme_omitsThemeKey() async throws {
// Synthesized Encodable uses encodeIfPresent, and /api/user/update applies
// `...(theme !== undefined && { theme })` — so a nil theme is a silent no-op,
// never a clear. Callers must send "system" verbatim to select the OS theme.
session.stub(json: #"{"user":\#(userJSON)}"#)
_ = try await sut.updateUserSettings(theme: nil, showAdvancedPostSettings: true)
let body = try XCTUnwrap(session.lastRequest?.httpBody)
let json = try XCTUnwrap(try? JSONSerialization.jsonObject(with: body) as? [String: Any])
XCTAssertNil(json["theme"])
XCTAssertEqual(json.count, 1)
}
}
Loading