Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: Migrate Discover tests to Swift Testing #200

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ struct FavouriteSortTests {

@Test("createdAt default description is created_at.asc")
func createdAtWhenDefaultReturnsDescription() {
#expect(FavouriteSort.createdAt().description == "created_at.asc")
let sort = FavouriteSort.createdAt()

#expect(sort.description == "created_at.asc")
}

@Test("createdAt ascending description is created_at.asc")
func createdAtWhenAscendingReturnsDescription() {
#expect(FavouriteSort.createdAt(descending: false).description == "created_at.asc")
let sort = FavouriteSort.createdAt(descending: false)

#expect(sort.description == "created_at.asc")
}

@Test("createdAt descending description is created_at.desc")
func createdAtWhenDescendingReturnsDescription() {
#expect(FavouriteSort.createdAt(descending: true).description == "created_at.desc")
let sort = FavouriteSort.createdAt(descending: true)

#expect(sort.description == "created_at.desc")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ struct WatchlistSortTests {

@Test("createdAt default description is created_at.asc")
func createdAtWhenDefaultReturnsDescription() {
#expect(WatchlistSort.createdAt().description == "created_at.asc")
let sort = WatchlistSort.createdAt()

#expect(sort.description == "created_at.asc")
}

@Test("createdAt ascending description is created_at.asc")
func createdAtWhenAscendingReturnsDescription() {
#expect(WatchlistSort.createdAt(descending: false).description == "created_at.asc")
let sort = WatchlistSort.createdAt(descending: false)

#expect(sort.description == "created_at.asc")
}

@Test("createdAt descending description is created_at.desc")
func createdAtWhenDescendingReturnsDescription() {
#expect(WatchlistSort.createdAt(descending: true).description == "created_at.desc")
let sort = WatchlistSort.createdAt(descending: true)

#expect(sort.description == "created_at.desc")
}

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

import Foundation
import Testing
@testable import TMDb
import XCTest

final class DiscoverMoviesRequestTests: XCTestCase {
@Suite(.tags(.requests, .discover))
struct DiscoverMoviesRequestTests {

func testPath() {
@Test("path is correct")
func path() {
let request = DiscoverMoviesRequest()

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

func testQueryItemsIsEmpty() {
@Test("queryItems is empty")
func queryItemsIsEmpty() {
let request = DiscoverMoviesRequest()

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

func testQueryItemsWithPeople() {
@Test("queryItems with people")
func queryItemsWithPeople() {
let request = DiscoverMoviesRequest(people: [1, 2, 3])

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

func testQueryItemsWithSortedBy() {
@Test("queryItems with sortedBy")
func queryItemsWithSortedBy() {
let request = DiscoverMoviesRequest(sortedBy: .originalTitle(descending: false))

XCTAssertEqual(request.queryItems, ["sort_by": "original_title.asc"])
#expect(request.queryItems == ["sort_by": "original_title.asc"])
}

func testQueryItemsWithPage() {
@Test("queryItems with page")
func queryItemsWithPage() {
let request = DiscoverMoviesRequest(page: 1)

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

func testQueryItemsWithLanguage() {
@Test("queryItems with language")
func queryItemsWithLanguage() {
let request = DiscoverMoviesRequest(language: "en")

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

func testQueryItemsWithSortedByAndPeopleAndPageAndLanguage() {
@Test("queryItems with sortedBy, people, page and language")
func queryItemsWithSortedByAndPeopleAndPageAndLanguage() {
let request = DiscoverMoviesRequest(
people: [1, 2, 3],
sortedBy: .originalTitle(descending: false),
page: 2,
language: "en"
)

XCTAssertEqual(
request.queryItems,
["sort_by": "original_title.asc", "with_people": "1,2,3", "page": "2", "language": "en"]
)
#expect(request.queryItems == [
"sort_by": "original_title.asc",
"with_people": "1,2,3",
"page": "2",
"language": "en"
])
}

func testMethodIsGet() {
@Test("method is GET")
func methodIsGet() {
let request = DiscoverMoviesRequest()

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

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = DiscoverMoviesRequest()

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

func testBodyIsNil() {
@Test("body is nil")
func bodyIsNil() {
let request = DiscoverMoviesRequest()

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

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

import Foundation
import Testing
@testable import TMDb
import XCTest

final class DiscoverTVSeriesRequestTests: XCTestCase {
@Suite(.tags(.requests, .discover))
struct DiscoverTVSeriesRequestTests {

func testPath() {
@Test("path is correct")
func path() {
let request = DiscoverTVSeriesRequest()

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

func testQueryItemsIsEmpty() {
@Test("queryItems is empty")
func queryItemsIsEmpty() {
let request = DiscoverTVSeriesRequest()

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

func testQueryItemsWithSortedBy() {
@Test("queryItems with sortedBy")
func queryItemsWithSortedBy() {
let request = DiscoverTVSeriesRequest(sortedBy: .firstAirDate(descending: false))

XCTAssertEqual(request.queryItems, ["sort_by": "first_air_date.asc"])
#expect(request.queryItems == ["sort_by": "first_air_date.asc"])
}

func testQueryItemsWithPage() throws {
@Test("queryItems with page")
func queryItemsWithPage() throws {
let request = DiscoverTVSeriesRequest(page: 1)

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

func testQueryItemsWithLanguage() {
@Test("queryItems with language")
func queryItemsWithLanguage() {
let request = DiscoverMoviesRequest(language: "en")

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

func testQueryItemsWithSortedByAndPageAndLanguage() {
@Test("queryItems with sortedBy, page and language")
func queryItemsWithSortedByAndPageAndLanguage() {
let request = DiscoverTVSeriesRequest(
sortedBy: .firstAirDate(descending: false),
page: 2,
language: "en"
)

XCTAssertEqual(
request.queryItems,
["sort_by": "first_air_date.asc", "page": "2", "language": "en"]
)
#expect(request.queryItems == [
"sort_by": "first_air_date.asc",
"page": "2",
"language": "en"
])
}

func testMethodIsGet() {
@Test("method is GET")
func methodIsGet() {
let request = DiscoverTVSeriesRequest()

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

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = DiscoverTVSeriesRequest()

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

func testBodyIsNil() {
@Test("body is nil")
func bodyIsNil() {
let request = DiscoverTVSeriesRequest()

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

}
Loading