Skip to content

Commit

Permalink
fix: swiftlint fail
Browse files Browse the repository at this point in the history
  • Loading branch information
duyhungtnn committed Jul 3, 2023
1 parent 1f74627 commit 398eb51
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions BucketeerTests/BKTConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest
@testable import Bucketeer

final class BKTConfigTests: XCTestCase {

func testCreateConfig() {
let logger = MockLogger()
// Not set interval values
Expand All @@ -12,73 +12,73 @@ final class BKTConfigTests: XCTestCase {
.with(featureTag: "featureTag1")
.with(appVersion: "1.2.3")
.with(logger: logger)

let config1 = try? builder.build()
XCTAssertNotNil(config1, "BKTConfig should not be null")

let eventsFlushInterval1 = config1!.eventsFlushInterval
XCTAssertEqual(eventsFlushInterval1,
Constant.MINIMUM_FLUSH_INTERVAL_MILLIS,
"eventsFlushInterval: \(eventsFlushInterval1) must be equal \(Constant.MINIMUM_FLUSH_INTERVAL_MILLIS)")

let backgroundPollingInterval1 = config1!.backgroundPollingInterval
XCTAssertEqual(backgroundPollingInterval1,
Constant.MINIMUM_BACKGROUND_POLLING_INTERVAL_MILLIS,
"backgroundPollingInterval: \(backgroundPollingInterval1) must be equal \(Constant.MINIMUM_BACKGROUND_POLLING_INTERVAL_MILLIS)")

let pollingInterval1 = config1!.pollingInterval
XCTAssertEqual(pollingInterval1,
Constant.MINIMUM_POLLING_INTERVAL_MILLIS,
"pollingInterval: \(pollingInterval1) must be equal \(Constant.MINIMUM_POLLING_INTERVAL_MILLIS)")

// Set interval settings but they are too small
builder = builder.with(eventsFlushInterval: 50)
.with(eventsMaxQueueSize: 3)
.with(pollingInterval: 100)
.with(backgroundPollingInterval: 1000)

let config2 = try? builder.build()
XCTAssertNotNil(config2, "BKTConfig should not be null")

let eventsFlushInterval2 = config2!.eventsFlushInterval
XCTAssertEqual(eventsFlushInterval2,
Constant.MINIMUM_FLUSH_INTERVAL_MILLIS,
"eventsFlushInterval: \(eventsFlushInterval2) is set but must be above \(Constant.MINIMUM_FLUSH_INTERVAL_MILLIS)")

let backgroundPollingInterval2 = config2!.backgroundPollingInterval
XCTAssertEqual(backgroundPollingInterval2,
Constant.MINIMUM_BACKGROUND_POLLING_INTERVAL_MILLIS,
"backgroundPollingInterval: \(backgroundPollingInterval2) is set but must be above \(Constant.MINIMUM_BACKGROUND_POLLING_INTERVAL_MILLIS)")

let pollingInterval2 = config2!.pollingInterval
XCTAssertEqual(pollingInterval2,
Constant.MINIMUM_POLLING_INTERVAL_MILLIS,
"pollingInterval: \(pollingInterval2) is set but must be above \(Constant.MINIMUM_POLLING_INTERVAL_MILLIS)")

// Set interval settings but now they are bigger enough
builder = builder.with(eventsFlushInterval: 60_000)
.with(eventsMaxQueueSize: 3)
.with(pollingInterval: 60_000)
.with(backgroundPollingInterval: 1_200_000)

let config3 = try? builder.build()
XCTAssertNotNil(config3, "BKTConfig should not be null")

let eventsFlushInterval3 = config3!.eventsFlushInterval
XCTAssertEqual(eventsFlushInterval3,
60_000,
"eventsFlushInterval: \(eventsFlushInterval3) must be equal \(60_000)")

let backgroundPollingInterval3 = config3!.backgroundPollingInterval
XCTAssertEqual(backgroundPollingInterval3,
1_200_000,
"backgroundPollingInterval: \(backgroundPollingInterval3) must be equal \(1_200_000)")

let pollingInterval3 = config3!.pollingInterval
XCTAssertEqual(pollingInterval3,
60_000,
"pollingInterval: \(pollingInterval3) must be equal \(60_000)")

// Checking other property should match with the user input
XCTAssertEqual("api_key_value",
config3?.apiKey,
Expand All @@ -97,7 +97,7 @@ final class BKTConfigTests: XCTestCase {
"appVersion does not match")
XCTAssertNotNil(config3?.logger, "logger should not nil")
}

func testAPIKeyRequired() {
let expectation = XCTestExpectation()
expectation.expectedFulfillmentCount = 2
Expand All @@ -111,10 +111,10 @@ final class BKTConfigTests: XCTestCase {
.with(featureTag: "featureTag1")
.with(appVersion: "1.2.3")
]

builders.forEach { builder in
do {
let _ = try builder.build()
_ = try builder.build()
} catch BKTError.illegalArgument(let message) {
XCTAssertEqual("apiKey is required", message)
expectation.fulfill()
Expand All @@ -123,8 +123,9 @@ final class BKTConfigTests: XCTestCase {
XCTFail("Unexpected error: \(error).")
}
}
wait(for: [expectation], timeout: 0.1)
}

func testAPIEndpointRequired() {
let expectation = XCTestExpectation()
expectation.expectedFulfillmentCount = 2
Expand All @@ -144,10 +145,10 @@ final class BKTConfigTests: XCTestCase {
.with(featureTag: "featureTag1")
.with(appVersion: "1.2.3")
]

builders.forEach { builder in
do {
let _ = try builder.build()
_ = try builder.build()
} catch BKTError.illegalArgument(let message) {
XCTAssertEqual("endpoint is required", message)
expectation.fulfill()
Expand All @@ -156,8 +157,9 @@ final class BKTConfigTests: XCTestCase {
XCTFail("Unexpected error: \(error).")
}
}
wait(for: [expectation], timeout: 0.1)
}

func testFeaturedRequired() {
let expectation = XCTestExpectation()
expectation.expectedFulfillmentCount = 2
Expand All @@ -172,10 +174,10 @@ final class BKTConfigTests: XCTestCase {
.with(apiEndpoint: "https://test.bucketeer.io")
.with(appVersion: "1.2.3")
]

builders.forEach { builder in
do {
let _ = try builder.build()
_ = try builder.build()
} catch BKTError.illegalArgument(let message) {
XCTAssertEqual("featureTag is required", message)
expectation.fulfill()
Expand All @@ -184,8 +186,9 @@ final class BKTConfigTests: XCTestCase {
XCTFail("Unexpected error: \(error).")
}
}
wait(for: [expectation], timeout: 0.1)
}

func testAppVersionRequired() {
let expectation = XCTestExpectation()
expectation.expectedFulfillmentCount = 2
Expand All @@ -200,10 +203,10 @@ final class BKTConfigTests: XCTestCase {
.with(apiEndpoint: "https://test.bucketeer.io")
.with(featureTag: "featureTag1")
]

builders.forEach { builder in
do {
let _ = try builder.build()
_ = try builder.build()
} catch BKTError.illegalArgument(let message) {
XCTAssertEqual("appVersion is required", message)
expectation.fulfill()
Expand All @@ -212,5 +215,6 @@ final class BKTConfigTests: XCTestCase {
XCTFail("Unexpected error: \(error).")
}
}
wait(for: [expectation], timeout: 0.1)
}
}

0 comments on commit 398eb51

Please sign in to comment.