Skip to content

Commit

Permalink
Fix swfitlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
instanceof committed Jul 3, 2023
1 parent e2458f5 commit a547788
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/RateLimit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation
public struct RateLimit: Codable {
/// Rate limit entries
public let entries: [String: Int]

/// The url of the request the rate limit were returned for.
public let requestURL: URL?

init(value: String, requestURL: URL?) {
self.requestURL = requestURL

Expand Down
22 changes: 14 additions & 8 deletions Tests/RateLimitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Mathias Emil Mortensen on 05/04/2023.
//

import XCTest
@testable import AppStoreConnect_Swift_SDK
import XCTest

final class RateLimitTests: XCTestCase {

Expand All @@ -16,29 +16,33 @@ final class RateLimitTests: XCTestCase {
XCTAssertEqual(rateLimit.entries["user-hour-lim"], 3600)
XCTAssertEqual(rateLimit.entries["user-hour-rem"], 3545)
}

func testInvalidValue() {
let rateLimit = RateLimit(value: "user-hour-rem3545", requestURL: nil)
XCTAssertEqual(rateLimit.entries.count, 0)
}

func testPartialInvalidValue() {
let rateLimit = RateLimit(value: "user-hour-rem3545;user-hour-rem:3545;", requestURL: nil)
XCTAssertEqual(rateLimit.entries.count, 1)
XCTAssertEqual(rateLimit.entries["user-hour-rem"], 3545)
}

func testMoreItems() {
let rateLimit = RateLimit(value: "user-hour-lim:3600;user-hour-rem:3598;user-minute-lim:150;user-minute-rem:149;", requestURL: nil)
let rateLimit = RateLimit(
value: "user-hour-lim:3600;user-hour-rem:3598;user-minute-lim:150;user-minute-rem:149;",
requestURL: nil)
XCTAssertEqual(rateLimit.entries.count, 4)
XCTAssertEqual(rateLimit.entries["user-hour-lim"], 3600)
XCTAssertEqual(rateLimit.entries["user-hour-rem"], 3598)
XCTAssertEqual(rateLimit.entries["user-minute-lim"], 150)
XCTAssertEqual(rateLimit.entries["user-minute-rem"], 149)
}

func testMultipleItems() {
let rateLimit = RateLimit(value: "user-hour-lim:3600;user-hour-rem:3598;, user-minute-lim:150;user-minute-rem:149;", requestURL: nil)
func testMultipleHeaders() {
let rateLimit = RateLimit(
value: "user-hour-lim:3600;user-hour-rem:3598;, user-minute-lim:150;user-minute-rem:149;",
requestURL: nil)
XCTAssertEqual(rateLimit.entries.count, 4)
XCTAssertEqual(rateLimit.entries["user-hour-lim"], 3600)
XCTAssertEqual(rateLimit.entries["user-hour-rem"], 3598)
Expand All @@ -47,7 +51,9 @@ final class RateLimitTests: XCTestCase {
}

func testExtractingHeaderField() {
let httpUrlResponse = HTTPURLResponse(url: URL(string: "https://api.appstoreconnect.apple.com/")!, statusCode: 200, httpVersion: nil, headerFields: ["X-ratE-limiT": "user-hour-lim:3600;user-hour-rem:3545;"])
let httpUrlResponse = HTTPURLResponse(url: URL(string: "https://api.appstoreconnect.apple.com/")!,
statusCode: 200, httpVersion: nil,
headerFields: ["X-ratE-limiT": "user-hour-lim:3600;user-hour-rem:3545;"])
let rateLimit = httpUrlResponse?.rateLimit
XCTAssertNotNil(rateLimit)
if let rateLimit {
Expand Down

0 comments on commit a547788

Please sign in to comment.