Skip to content

Commit

Permalink
REFACTOR: Remove random data in test mocks (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung authored Nov 14, 2024
1 parent 5cc04dc commit f86922a
Show file tree
Hide file tree
Showing 51 changed files with 213 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbMovieServiceReviewsTests {

@Test("reviews returns reviews")
func reviewsReturnsReviews() async throws {
let movieID = Int.randomID
let movieID = 1
let expectedResult = ReviewPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = MovieReviewsRequest(id: movieID, page: nil, language: nil)
Expand All @@ -48,7 +48,7 @@ struct TMDbMovieServiceReviewsTests {

@Test("reviews with page and language returns reviews")
func reviewsWithPageAndLanguageReturnsReviews() async throws {
let movieID = Int.randomID
let movieID = 1
let expectedResult = ReviewPageableList.mock()
let page = expectedResult.page
let language = "en"
Expand Down
24 changes: 12 additions & 12 deletions Tests/TMDbTests/Domain/Services/Search/TMDbSearchServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbSearchServiceTests {

@Test("searchAll returns media")
func searchAllReturnsMedia() async throws {
let query = String.random
let query = "media search"
let expectedResult = MediaPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = MultiSearchRequest(
Expand All @@ -49,7 +49,7 @@ struct TMDbSearchServiceTests {

@Test("searchAll with filter, page and language returns media")
func searchAllWithFilterAndPageAndLanguageReturnsMedia() async throws {
let query = String.random
let query = "media search"
let includeAdult = true
let page = 2
let language = "en"
Expand All @@ -72,7 +72,7 @@ struct TMDbSearchServiceTests {

@Test("searchAll when errors throws error")
func searchAllWhenErrorsThrowsError() async throws {
let query = String.random
let query = "media search"
apiClient.addResponse(.failure(.unknown))

await #expect(throws: TMDbError.unknown) {
Expand All @@ -82,7 +82,7 @@ struct TMDbSearchServiceTests {

@Test("searchMovies returns movies")
func searchMoviesReturnsMovies() async throws {
let query = String.random
let query = "search movies"
let expectedResult = MoviePageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = MovieSearchRequest(
Expand All @@ -101,7 +101,7 @@ struct TMDbSearchServiceTests {

@Test("searchMovies with filter, page and language returns movies")
func searchMoviesWithFilterAndPageAndLanguageReturnsMovies() async throws {
let query = String.random
let query = "search movies"
let primaryReleaseYear = 2024
let country = "GB"
let includeAdult = true
Expand Down Expand Up @@ -132,7 +132,7 @@ struct TMDbSearchServiceTests {

@Test("searchMovies when errors throws error")
func searchMoviesWhenErrorsThrowsError() async throws {
let query = String.random
let query = "search movies"
apiClient.addResponse(.failure(.unknown))

await #expect(throws: TMDbError.unknown) {
Expand All @@ -142,7 +142,7 @@ struct TMDbSearchServiceTests {

@Test("searchTVSeries returns TV series")
func searchTVSeriesReturnsTVSeries() async throws {
let query = String.random
let query = "search tv series"
let expectedResult = TVSeriesPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeriesSearchRequest(
Expand All @@ -162,7 +162,7 @@ struct TMDbSearchServiceTests {

@Test("searchTVSeries with filter, page and language returns TV series")
func searchTVSeriesWithFilterAndPageAndLanguageReturnsTVSeries() async throws {
let query = String.random
let query = "search tv series"
let firstAirDateYear = 2023
let year = 2024
let includeAdult = true
Expand Down Expand Up @@ -190,7 +190,7 @@ struct TMDbSearchServiceTests {

@Test("searchTVSeries when errors throws error")
func searchTVSeriesWhenErrorsThrowsError() async throws {
let query = String.random
let query = "search tv series"
apiClient.addResponse(.failure(.unknown))

await #expect(throws: TMDbError.unknown) {
Expand All @@ -200,7 +200,7 @@ struct TMDbSearchServiceTests {

@Test("searchPeople returns people")
func searchPeopleReturnsPeople() async throws {
let query = String.random
let query = "search people"
let expectedResult = PersonPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = PersonSearchRequest(
Expand All @@ -214,7 +214,7 @@ struct TMDbSearchServiceTests {

@Test("searchPeople with filter, page and language returns people")
func searchPeopleWithFilterAndPageAndLanguageReturnsPeople() async throws {
let query = String.random
let query = "search people"
let includeAdult = true
let page = 2
let language = "en"
Expand All @@ -237,7 +237,7 @@ struct TMDbSearchServiceTests {

@Test("searchPeople when errors throws error")
func searchPeopleWhenErrorsThrowsError() async throws {
let query = String.random
let query = "search people"
apiClient.addResponse(.failure(.unknown))

await #expect(throws: TMDbError.unknown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbTVEpisodeServiceTests {

@Test("details returns TV episode")
func detailsReturnsTVEpisode() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVEpisode.mock()
let seasonNumber = expectedResult.seasonNumber
let episodeNumber = expectedResult.episodeNumber
Expand All @@ -59,7 +59,7 @@ struct TMDbTVEpisodeServiceTests {

@Test("details with language returns TV episode")
func detailsWithLanguageReturnsTVEpisode() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVEpisode.mock()
let seasonNumber = expectedResult.seasonNumber
let episodeNumber = expectedResult.episodeNumber
Expand Down Expand Up @@ -101,9 +101,9 @@ struct TMDbTVEpisodeServiceTests {

@Test("images returns images")
func imagesReturnsImages() async throws {
let episodeNumber = Int.randomID
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let episodeNumber = 111
let seasonNumber = 11
let tvSeriesID = 1
let expectedResult = TVEpisodeImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVEpisodeImagesRequest(
Expand All @@ -125,9 +125,9 @@ struct TMDbTVEpisodeServiceTests {

@Test("images with filter returns images")
func imagesWithFilterReturnsImages() async throws {
let episodeNumber = Int.randomID
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let episodeNumber = 111
let seasonNumber = 11
let tvSeriesID = 1
let languages = ["en-GB", "fr"]
let expectedResult = TVEpisodeImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down Expand Up @@ -168,9 +168,9 @@ struct TMDbTVEpisodeServiceTests {

@Test("video returns videos")
func videosReturnsVideos() async throws {
let episodeNumber = Int.randomID
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let episodeNumber = 111
let seasonNumber = 11
let tvSeriesID = 1
let expectedResult = VideoCollection.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVEpisodeVideosRequest(
Expand All @@ -192,9 +192,9 @@ struct TMDbTVEpisodeServiceTests {

@Test("video with filter returns videos")
func videosWithFilterReturnsVideos() async throws {
let episodeNumber = Int.randomID
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let episodeNumber = 111
let seasonNumber = 11
let tvSeriesID = 1
let languages = ["en", "fr"]
let expectedResult = VideoCollection.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbTVSeasonServiceTests {

@Test("details returns TV season")
func detailsReturnsTVSeason() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeason.mock()
let seasonNumber = expectedResult.seasonNumber
apiClient.addResponse(.success(expectedResult))
Expand All @@ -53,7 +53,7 @@ struct TMDbTVSeasonServiceTests {

@Test("details with language returns TV season")
func detailsWithLanguageReturnsTVSeason() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeason.mock()
let seasonNumber = expectedResult.seasonNumber
let language = "en"
Expand Down Expand Up @@ -84,9 +84,9 @@ struct TMDbTVSeasonServiceTests {

@Test("aggregateCredits returns TV season credits")
func aggregateCreditsReturnsTVSeasonCredits() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeasonAggregateCredits(id: 1, cast: [], crew: [])
let seasonNumber = Int.randomID
let seasonNumber = 11
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeasonAggregateCreditsRequest(
seasonNumber: seasonNumber,
Expand All @@ -103,9 +103,9 @@ struct TMDbTVSeasonServiceTests {

@Test("aggregateCredits with language returns TV season credits")
func aggregateCreditsWithLanguageReturnsTVSeasonCredits() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeasonAggregateCredits(id: 1, cast: [], crew: [])
let seasonNumber = Int.randomID
let seasonNumber = 11
let language = "en"
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeasonAggregateCreditsRequest(
Expand Down Expand Up @@ -137,8 +137,8 @@ struct TMDbTVSeasonServiceTests {

@Test("imagess returns images")
func imagesReturnsImages() async throws {
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let seasonNumber = 11
let tvSeriesID = 1
let expectedResult = TVSeasonImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeasonImagesRequest(
Expand All @@ -155,8 +155,8 @@ struct TMDbTVSeasonServiceTests {

@Test("images with filter returns images")
func imagesWithFilterReturnsImages() async throws {
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let seasonNumber = 11
let tvSeriesID = 1
let languages = ["en-GB", "fr"]
let expectedResult = TVSeasonImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down Expand Up @@ -187,8 +187,8 @@ struct TMDbTVSeasonServiceTests {

@Test("videos returns videos")
func videosReturnsVideos() async throws {
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let seasonNumber = 11
let tvSeriesID = 1
let expectedResult = VideoCollection.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeasonVideosRequest(
Expand All @@ -205,8 +205,8 @@ struct TMDbTVSeasonServiceTests {

@Test("videos with filter returns videos")
func videosWithFilterReturnsVideos() async throws {
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
let seasonNumber = 11
let tvSeriesID = 1
let languages = ["en", "fr"]
let expectedResult = VideoCollection.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ struct TMDbTVSeriesServiceListsTests {

@Test("recommenendations returns TV series")
func recommendationsReturnsTVSeries() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeriesPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeriesRecommendationsRequest(
id: tvSeriesID, page: nil, language: nil)
id: tvSeriesID,
page: nil,
language: nil
)

let result = try await service.recommendations(forTVSeries: tvSeriesID)

Expand All @@ -49,7 +52,7 @@ struct TMDbTVSeriesServiceListsTests {

@Test("recommendations with page and language returns TV series")
func recommendationsWithPageAndLanguageReturnsTVSeries() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let page = 2
let language = "en"
let expectedResult = TVSeriesPageableList.mock()
Expand All @@ -76,7 +79,7 @@ struct TMDbTVSeriesServiceListsTests {

@Test("similar returns TV series")
func similarReturnsTVSeries() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = TVSeriesPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = SimilarTVSeriesRequest(id: tvSeriesID, page: nil, language: nil)
Expand All @@ -89,7 +92,7 @@ struct TMDbTVSeriesServiceListsTests {

@Test("similar with page and language returns TV series")
func similarWithPageAndLanguageReturnsTVSeries() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let page = 2
let language = "en"
let expectedResult = TVSeriesPageableList.mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbTVSeriesServiceMediaTests {

@Test("images returns images")
func imagesReturnsImages() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = ImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeriesImagesRequest(id: tvSeriesID, languages: nil)
Expand All @@ -48,7 +48,7 @@ struct TMDbTVSeriesServiceMediaTests {

@Test("images with filter returns images")
func imagesWithFilterReturnsImages() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let languages = ["en-GB", "fr"]
let expectedResult = ImageCollection.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TMDbTVSeriesServiceReviewsTests {

@Test("reviews returns reviews")
func reviewsReturnsReviews() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let expectedResult = ReviewPageableList.mock()
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeriesReviewsRequest(id: tvSeriesID, page: nil, language: nil)
Expand All @@ -48,7 +48,7 @@ struct TMDbTVSeriesServiceReviewsTests {

@Test("reviews with language returns reviews")
func reviewsWithLanguageReturnsReviews() async throws {
let tvSeriesID = Int.randomID
let tvSeriesID = 1
let language = "en"
let expectedResult = ReviewPageableList.mock()
apiClient.addResponse(.success(expectedResult))
Expand Down
18 changes: 9 additions & 9 deletions Tests/TMDbTests/Mocks/Models/CastMember+Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import TMDb
extension CastMember {

static func mock(
id: Int = .randomID,
castID: Int? = .randomID,
creditID: String = .randomID,
name: String? = .random,
character _: String? = .random,
id: Int = 1,
castID: Int? = 2,
creditID: String = "3",
name: String = "Actor Name",
character: String = "Character Name",
gender: Gender? = .male,
profilePath: URL? = .randomImagePath,
order: Int = Int.random(in: 1...10)
profilePath: URL? = URL(string: "/t2yyOv40HZeVlLjYsCsPHnWLk4W.jpg")!,
order: Int = 1
) -> Self {
.init(
id: id,
castID: castID,
creditID: creditID,
name: name ?? "Cast \(id)",
character: name ?? "Character \(id)",
name: name,
character: character,
gender: gender,
profilePath: profilePath,
order: order
Expand Down
Loading

0 comments on commit f86922a

Please sign in to comment.