Skip to content

Commit

Permalink
Merge branch 'main' into test/migrate-integration-tests-to-swift-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung authored Sep 16, 2024
2 parents 8ab395a + 049d827 commit 0cc1102
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@
// limitations under the License.
//

import Foundation
import Testing
@testable import TMDb
import XCTest

final class AccountRequestTests: XCTestCase {
@Suite(.tags(.requests, .account))
struct AccountRequestTests {

var request: AccountRequest!

override func setUp() {
super.setUp()
request = AccountRequest(sessionID: "1234567890")
init() {
self.request = AccountRequest(sessionID: "1234567890")
}

override func tearDown() {
request = nil
super.tearDown()
@Test("path")
func path() {
#expect(request.path == "/account")
}

func testPath() {
XCTAssertEqual(request.path, "/account")
@Test("queryItems contains session_id")
func queryItemsContainsSessionID() {
#expect(request.queryItems == ["session_id": "1234567890"])
}

func testQueryItemsContainsSessionID() {
XCTAssertEqual(request.queryItems.count, 1)
XCTAssertEqual(request.queryItems["session_id"], "1234567890")
@Test("method is GET")
func methodIsGet() {
#expect(request.method == .get)
}

func testMethodIsGet() {
XCTAssertEqual(request.method, .get)
@Test("headers is empty")
func headersIsEmpty() {
#expect(request.headers.isEmpty)
}

func testHeadersIsEmpty() {
XCTAssertTrue(request.headers.isEmpty)
}

func testBodyIsNil() {
XCTAssertNil(request.body)
@Test("body is nil")
func bodyIsNil() {
#expect(request.body == nil)
}

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

import Foundation
import Testing
@testable import TMDb
import XCTest

final class AddFavouriteRequestTests: XCTestCase {
@Suite(.tags(.requests, .account))
struct AddFavouriteRequestTests {

func testPath() {
@Test("path")
func path() {
let request = AddFavouriteRequest(
showType: .movie,
showID: 1,
Expand All @@ -31,10 +34,11 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

XCTAssertEqual(request.path, "/account/1/favorite")
#expect(request.path == "/account/1/favorite")
}

func testQueryItemsContainsSessionID() {
@Test("queryItems contains session_id")
func queryItemsContainsSessionID() {
let request = AddFavouriteRequest(
showType: .movie,
showID: 1,
Expand All @@ -43,11 +47,11 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testMethodIsPost() {
@Test("method is POST")
func methodIsPost() {
let request = AddFavouriteRequest(
showType: .movie,
showID: 1,
Expand All @@ -56,10 +60,11 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = AddFavouriteRequest(
showType: .movie,
showID: 1,
Expand All @@ -68,10 +73,11 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testBodyWhenMovieAndAddingAsFavourite() throws {
@Test("body when movie and adding as favourite")
func bodyWhenMovieAndAddingAsFavourite() throws {
let request = AddFavouriteRequest(
showType: .movie,
showID: 1,
Expand All @@ -80,14 +86,15 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .movie)
XCTAssertEqual(body.showID, 1)
XCTAssertTrue(body.isFavourite)
#expect(body.showType == .movie)
#expect(body.showID == 1)
#expect(body.isFavourite)
}

func testBodyWhenMovieAndRemovingAsFavourite() throws {
@Test("body when movie and removing as favourite")
func bodyWhenMovieAndRemovingAsFavourite() throws {
let request = AddFavouriteRequest(
showType: .movie,
showID: 2,
Expand All @@ -96,14 +103,15 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .movie)
XCTAssertEqual(body.showID, 2)
XCTAssertFalse(body.isFavourite)
#expect(body.showType == .movie)
#expect(body.showID == 2)
#expect(!body.isFavourite)
}

func testBodyWhenTVSeriesAndAddingAsFavourite() throws {
@Test("body when TV series and adding as favourite")
func bodyWhenTVSeriesAndAddingAsFavourite() throws {
let request = AddFavouriteRequest(
showType: .tvSeries,
showID: 3,
Expand All @@ -112,14 +120,15 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .tvSeries)
XCTAssertEqual(body.showID, 3)
XCTAssertTrue(body.isFavourite)
#expect(body.showType == .tvSeries)
#expect(body.showID == 3)
#expect(body.isFavourite)
}

func testBodyWhenTVSeriesAndRemovingAsFavourite() throws {
@Test("body when TV series and removing as favourite")
func bodyWhenTVSeriesAndRemovingAsFavourite() throws {
let request = AddFavouriteRequest(
showType: .tvSeries,
showID: 4,
Expand All @@ -128,11 +137,11 @@ final class AddFavouriteRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .tvSeries)
XCTAssertEqual(body.showID, 4)
XCTAssertFalse(body.isFavourite)
#expect(body.showType == .tvSeries)
#expect(body.showID == 4)
#expect(!body.isFavourite)
}

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

import Foundation
import Testing
@testable import TMDb
import XCTest

final class AddToWatchlistRequestTests: XCTestCase {
@Suite(.tags(.requests, .account))
struct AddToWatchlistRequestTests {

func testPath() {
@Test("path")
func path() {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 1,
Expand All @@ -31,10 +34,11 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

XCTAssertEqual(request.path, "/account/1/watchlist")
#expect(request.path == "/account/1/watchlist")
}

func testQueryItemsContainsSessionID() {
@Test("queryItems contains session_id")
func queryItemsContainsSessionID() {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 1,
Expand All @@ -43,11 +47,11 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testMethodIsPost() {
@Test("method is POST")
func methodIsPost() {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 1,
Expand All @@ -56,10 +60,11 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testHeadersIsEmpty() {
@Test("headers is empty")
func headersIsEmpty() {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 1,
Expand All @@ -68,10 +73,11 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

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

func testBodyWhenMovieAndAddingAsFavourite() throws {
@Test("body when movie and adding as favourite")
func bodyWhenMovieAndAddingAsFavourite() throws {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 1,
Expand All @@ -80,14 +86,15 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .movie)
XCTAssertEqual(body.showID, 1)
XCTAssertTrue(body.isInWatchlist)
#expect(body.showType == .movie)
#expect(body.showID == 1)
#expect(body.isInWatchlist)
}

func testBodyWhenMovieAndRemovingAsFavourite() throws {
@Test("body when movie and removing as favourite")
func bodyWhenMovieAndRemovingAsFavourite() throws {
let request = AddToWatchlistRequest(
showType: .movie,
showID: 2,
Expand All @@ -96,14 +103,15 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .movie)
XCTAssertEqual(body.showID, 2)
XCTAssertFalse(body.isInWatchlist)
#expect(body.showType == .movie)
#expect(body.showID == 2)
#expect(!body.isInWatchlist)
}

func testBodyWhenTVSeriesAndAddingAsFavourite() throws {
@Test("body when TV series and adding as favourite")
func bodyWhenTVSeriesAndAddingAsFavourite() throws {
let request = AddToWatchlistRequest(
showType: .tvSeries,
showID: 3,
Expand All @@ -112,14 +120,15 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .tvSeries)
XCTAssertEqual(body.showID, 3)
XCTAssertTrue(body.isInWatchlist)
#expect(body.showType == .tvSeries)
#expect(body.showID == 3)
#expect(body.isInWatchlist)
}

func testBodyWhenTVSeriesAndRemovingAsFavourite() throws {
@Test("body when TV series and removing as favourite")
func bodyWhenTVSeriesAndRemovingAsFavourite() throws {
let request = AddToWatchlistRequest(
showType: .tvSeries,
showID: 4,
Expand All @@ -128,11 +137,11 @@ final class AddToWatchlistRequestTests: XCTestCase {
sessionID: "abc"
)

let body = try XCTUnwrap(request.body)
let body = try #require(request.body)

XCTAssertEqual(body.showType, .tvSeries)
XCTAssertEqual(body.showID, 4)
XCTAssertFalse(body.isInWatchlist)
#expect(body.showType == .tvSeries)
#expect(body.showID == 4)
#expect(!body.isInWatchlist)
}

}
Loading

0 comments on commit 0cc1102

Please sign in to comment.