update tests

This commit is contained in:
Justin Mazzocchi 2020-09-12 17:02:56 -07:00
parent 3c46c6185d
commit 5fa4fb1b76
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -11,23 +11,18 @@ import XCTest
class InstanceURLServiceTests: XCTestCase {
func testFiltering() throws {
let sut = InstanceURLService(environment: .mock())
let unfilteredInstanceURL = URL(string: "https://unfiltered.instance")!
let filteredInstanceURL = URL(string: "https://filtered.instance")!
let subdomainFilteredInstanceURL = URL(string: "https://subdomain.filtered.instance")!
XCTAssertFalse(sut.isFiltered(url: unfilteredInstanceURL))
XCTAssertTrue(sut.isFiltered(url: filteredInstanceURL))
XCTAssertTrue(sut.isFiltered(url: subdomainFilteredInstanceURL))
XCTAssertNotNil(sut.url(text: "unfiltered.instance"))
XCTAssertNil(sut.url(text: "filtered.instance"))
XCTAssertNil(sut.url(text: "subdomain.filtered.instance"))
}
func testUpdating() throws {
let environment = AppEnvironment.mock()
var sut = InstanceURLService(environment: environment)
let previouslyFilteredInstanceURL = URL(string: "https://filtered.instance")!
let newlyFilteredInstanceURL = URL(string: "https://instance.filtered")!
XCTAssertTrue(sut.isFiltered(url: previouslyFilteredInstanceURL))
XCTAssertFalse(sut.isFiltered(url: newlyFilteredInstanceURL))
XCTAssertNil(sut.url(text: "filtered.instance"))
XCTAssertNotNil(sut.url(text: "instance.filtered"))
var updatedFilter = try BloomFilter<String>(hashes: [.djb232, .sdbm32], byteCount: 16)
@ -36,18 +31,18 @@ class InstanceURLServiceTests: XCTestCase {
let updatedFilterData = try JSONEncoder().encode(updatedFilter)
let stub: HTTPStub = .success((URLResponse(), updatedFilterData))
StubbingURLProtocol.setStub(stub, forURL: URL(string: "https://filter.metabolist.com/filter.json")!)
StubbingURLProtocol.setStub(stub, forURL: URL(string: "https://filter.metabolist.com/filter")!)
let updateRecorder = sut.updateFilter().collect().record()
_ = try wait(for: updateRecorder.next(), timeout: 1)
XCTAssertFalse(sut.isFiltered(url: previouslyFilteredInstanceURL))
XCTAssertTrue(sut.isFiltered(url: newlyFilteredInstanceURL))
XCTAssertNotNil(sut.url(text: "filtered.instance"))
XCTAssertNil(sut.url(text: "instance.filtered"))
sut = InstanceURLService(environment: environment)
XCTAssertFalse(sut.isFiltered(url: previouslyFilteredInstanceURL))
XCTAssertTrue(sut.isFiltered(url: newlyFilteredInstanceURL))
XCTAssertNotNil(sut.url(text: "filtered.instance"))
XCTAssertNil(sut.url(text: "instance.filtered"))
}
}