Skip to content

Commit

Permalink
REFACTOR: Migrate Trending tests to Swift Testing (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung authored Sep 18, 2024
1 parent 04f0697 commit e4b4ec1
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@
// limitations under the License.
//

import Foundation
import Testing
@testable import TMDb
import XCTest

final class TrendingTimeWindowFilterTypeTests: XCTestCase {
@Suite(.tags(.trending))
struct TrendingTimeWindowFilterTypeTests {

func testDayReturnsRawValue() {
let expectedResult = "day"
@Test("day raw value is \"day\"")
func dayRawValue() {
let filterType = TrendingTimeWindowFilterType.day

let result = TrendingTimeWindowFilterType.day.rawValue

XCTAssertEqual(result, expectedResult)
#expect(filterType.rawValue == "day")
}

func testWeekReturnsRawValue() {
let expectedResult = "week"

let result = TrendingTimeWindowFilterType.week.rawValue
func weekRawValue() {
let filterType = TrendingTimeWindowFilterType.week

XCTAssertEqual(result, expectedResult)
#expect(filterType.rawValue == "week")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,74 @@
// limitations under the License.
//

import Foundation
import Testing
@testable import TMDb
import XCTest

final class TrendingMoviesRequestTests: XCTestCase {
@Suite(.tags(.requests, .trending))
struct TrendingMoviesRequestTests {

func testPathWithDayTimeWindow() {
@Test("path with day time window")
func pathWithDayTimeWindow() {
let request = TrendingMoviesRequest(timeWindow: .day)

XCTAssertEqual(request.path, "/trending/movie/day")
#expect(request.path == "/trending/movie/day")
}

func testPathWithWeekTimeWindow() {
@Test("path with week time window")
func pathWithWeekTimeWindow() {
let request = TrendingMoviesRequest(timeWindow: .week)

XCTAssertEqual(request.path, "/trending/movie/week")
#expect(request.path == "/trending/movie/week")
}

func testQueryItemsIsEmpty() {
@Test("queryItems is empty")
func queryItemsIsEmpty() {
let request = TrendingMoviesRequest(timeWindow: .day)

XCTAssertTrue(request.queryItems.isEmpty)
#expect(request.queryItems.isEmpty)
}

func testQueryItemsWithPage() {
@Test("queryItems with page")
func queryItemsWithPage() {
let request = TrendingMoviesRequest(timeWindow: .day, page: 1)

XCTAssertEqual(request.queryItems, ["page": "1"])
#expect(request.queryItems == ["page": "1"])
}

func testQueryItemsWithLanguage() {
@Test("queryItems with language")
func queryItemsWithLanguage() {
let request = TrendingMoviesRequest(timeWindow: .day, language: "en")

XCTAssertEqual(request.queryItems, ["language": "en"])
#expect(request.queryItems == ["language": "en"])
}

func testQueryItemsWithPageAndLanguage() {
@Test("queryItems with page and language")
func queryItemsWithPageAndLanguage() {
let request = TrendingMoviesRequest(timeWindow: .day, page: 1, language: "en")

XCTAssertEqual(request.queryItems, ["page": "1", "language": "en"])
#expect(request.queryItems == ["page": "1", "language": "en"])
}

func testMethodIsGet() {
@Test("method is GET")
func methodIsGet() {
let request = TrendingMoviesRequest(timeWindow: .day)

XCTAssertEqual(request.method, .get)
#expect(request.method == .get)
}

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = TrendingMoviesRequest(timeWindow: .day)

XCTAssertTrue(request.headers.isEmpty)
#expect(request.headers.isEmpty)
}

func testBodyIsNil() {
@Test("body is nil")
func bodyIsNil() {
let request = TrendingMoviesRequest(timeWindow: .day)

XCTAssertNil(request.body)
#expect(request.body == nil)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,74 @@
// limitations under the License.
//

import Foundation
import Testing
@testable import TMDb
import XCTest

final class TrendingPeopleRequestTests: XCTestCase {
@Suite(.tags(.requests, .trending))
struct TrendingPeopleRequestTests {

func testPathWithDayTimeWindow() {
@Test("path with day time window")
func pathWithDayTimeWindow() {
let request = TrendingPeopleRequest(timeWindow: .day)

XCTAssertEqual(request.path, "/trending/person/day")
#expect(request.path == "/trending/person/day")
}

func testPathWithWeekTimeWindow() {
@Test("path with week time window")
func pathWithWeekTimeWindow() {
let request = TrendingPeopleRequest(timeWindow: .week)

XCTAssertEqual(request.path, "/trending/person/week")
#expect(request.path == "/trending/person/week")
}

func testQueryItemsIsEmpty() {
@Test("queryItems is empty")
func queryItemsIsEmpty() {
let request = TrendingPeopleRequest(timeWindow: .day)

XCTAssertTrue(request.queryItems.isEmpty)
#expect(request.queryItems.isEmpty)
}

func testQueryItemsWithPage() {
@Test("queryItems with page")
func queryItemsWithPage() {
let request = TrendingPeopleRequest(timeWindow: .day, page: 1)

XCTAssertEqual(request.queryItems, ["page": "1"])
#expect(request.queryItems == ["page": "1"])
}

func testQueryItemsWithLanguage() {
@Test("queryItems with language")
func queryItemsWithLanguage() {
let request = TrendingPeopleRequest(timeWindow: .day, language: "en")

XCTAssertEqual(request.queryItems, ["language": "en"])
#expect(request.queryItems == ["language": "en"])
}

func testQueryItemsWithPageAndLanguage() {
@Test("queryItems with page and language")
func queryItemsWithPageAndLanguage() {
let request = TrendingPeopleRequest(timeWindow: .day, page: 1, language: "en")

XCTAssertEqual(request.queryItems, ["page": "1", "language": "en"])
#expect(request.queryItems == ["page": "1", "language": "en"])
}

func testMethodIsGet() {
@Test("method is GET")
func methodIsGet() {
let request = TrendingPeopleRequest(timeWindow: .day)

XCTAssertEqual(request.method, .get)
#expect(request.method == .get)
}

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = TrendingPeopleRequest(timeWindow: .day)

XCTAssertTrue(request.headers.isEmpty)
#expect(request.headers.isEmpty)
}

func testBodyIsNil() {
@Test("body is nil")
func bodyIsNil() {
let request = TrendingPeopleRequest(timeWindow: .day)

XCTAssertNil(request.body)
#expect(request.body == nil)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,74 @@
// limitations under the License.
//

import Foundation
import Testing
@testable import TMDb
import XCTest

final class TrendingTVSeriesRequestTests: XCTestCase {
@Suite(.tags(.requests, .trending))
struct TrendingTVSeriesRequestTests {

func testPathWithDayTimeWindow() {
@Test("path with day time window")
func pathWithDayTimeWindow() {
let request = TrendingTVSeriesRequest(timeWindow: .day)

XCTAssertEqual(request.path, "/trending/tv/day")
#expect(request.path == "/trending/tv/day")
}

func testPathWithWeekTimeWindow() {
@Test("path with week time window")
func pathWithWeekTimeWindow() {
let request = TrendingTVSeriesRequest(timeWindow: .week)

XCTAssertEqual(request.path, "/trending/tv/week")
#expect(request.path == "/trending/tv/week")
}

func testQueryItemsIsEmpty() {
@Test("queryItems is empty")
func queryItemsIsEmpty() {
let request = TrendingTVSeriesRequest(timeWindow: .day)

XCTAssertTrue(request.queryItems.isEmpty)
#expect(request.queryItems.isEmpty)
}

func testQueryItemsWithPage() {
@Test("queryItems with page")
func queryItemsWithPage() {
let request = TrendingTVSeriesRequest(timeWindow: .day, page: 1)

XCTAssertEqual(request.queryItems, ["page": "1"])
#expect(request.queryItems == ["page": "1"])
}

func testQueryItemsWithLanguage() {
@Test("queryItems with language")
func queryItemsWithLanguage() {
let request = TrendingTVSeriesRequest(timeWindow: .day, language: "en")

XCTAssertEqual(request.queryItems, ["language": "en"])
#expect(request.queryItems == ["language": "en"])
}

func testQueryItemsWithPageAndLanguage() {
@Test("queryItems with page and language")
func queryItemsWithPageAndLanguage() {
let request = TrendingTVSeriesRequest(timeWindow: .day, page: 1, language: "en")

XCTAssertEqual(request.queryItems, ["page": "1", "language": "en"])
#expect(request.queryItems == ["page": "1", "language": "en"])
}

func testMethodIsGet() {
@Test("method is GET")
func methodIsGet() {
let request = TrendingTVSeriesRequest(timeWindow: .day)

XCTAssertEqual(request.method, .get)
#expect(request.method == .get)
}

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = TrendingTVSeriesRequest(timeWindow: .day)

XCTAssertTrue(request.headers.isEmpty)
#expect(request.headers.isEmpty)
}

func testBodyIsNil() {
@Test("body is nil")
func bodyIsNil() {
let request = TrendingTVSeriesRequest(timeWindow: .day)

XCTAssertNil(request.body)
#expect(request.body == nil)
}

}
Loading

0 comments on commit e4b4ec1

Please sign in to comment.