macos-ai-menubar-usage/AIMenubarUsageTests/ClaudeProviderTests.swift
Felipe M. 00c4e33171
Initial commit: AI Menubar Usage — macOS menu bar app for Cursor and Claude.
Includes provider integrations, settings, NSStatusItem UI, tests, Makefile, and README with screenshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 20:41:40 +02:00

30 lines
1.2 KiB
Swift

import XCTest
@testable import AIMenubarUsage
final class ClaudeProviderTests: XCTestCase {
func testDecodeOAuthUsageFixture() throws {
let data = try loadFixture(named: "claude-oauth-usage")
let usage = try JSONDecoder().decode(ClaudeOAuthUsageResponse.self, from: data)
XCTAssertEqual(usage.fiveHour?.utilization ?? 0, 0.42, accuracy: 0.001)
XCTAssertEqual(usage.sevenDay?.utilization ?? 0, 0.15, accuracy: 0.001)
}
func testSnapshotMapping() throws {
let data = try loadFixture(named: "claude-oauth-usage")
let usage = try JSONDecoder().decode(ClaudeOAuthUsageResponse.self, from: data)
let snapshot = ClaudeAPI.snapshot(from: usage, fetchedAt: Date(), isStale: false)
XCTAssertEqual(snapshot.providerID, .claude)
XCTAssertEqual(snapshot.formatted(.claudeFiveHourUtilization), "42%")
XCTAssertEqual(snapshot.formatted(.claudeSevenDayUtilization), "15%")
}
private func loadFixture(named name: String) throws -> Data {
let url = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.appendingPathComponent("Fixtures")
.appendingPathComponent("\(name).json")
return try Data(contentsOf: url)
}
}