Skip to content

Commit

Permalink
TECH DEBT: Tidy models
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung committed May 15, 2024
1 parent 27b206d commit 01374e6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 56 deletions.
18 changes: 0 additions & 18 deletions Sources/TMDb/Domain/Models/MovieExternalLinksCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ public struct MovieExternalLinksCollection: Identifiable, Codable, Equatable, Ha
self.twitter = twitter
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(imdb?.id)
hasher.combine(wikiData?.id)
hasher.combine(facebook?.id)
hasher.combine(instagram?.id)
hasher.combine(twitter?.id)
}

public static func == (lhs: MovieExternalLinksCollection, rhs: MovieExternalLinksCollection) -> Bool {
lhs.id == rhs.id
&& lhs.imdb == rhs.imdb
&& lhs.wikiData == rhs.wikiData
&& lhs.facebook == rhs.facebook
&& lhs.instagram == rhs.instagram
&& lhs.twitter == rhs.twitter
}

}

public extension MovieExternalLinksCollection {
Expand Down
20 changes: 0 additions & 20 deletions Sources/TMDb/Domain/Models/PersonExternalLinksCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@ public struct PersonExternalLinksCollection: Identifiable, Codable, Equatable, H
self.tikTok = tikTok
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(imdb?.id)
hasher.combine(wikiData?.id)
hasher.combine(facebook?.id)
hasher.combine(instagram?.id)
hasher.combine(twitter?.id)
hasher.combine(tikTok?.id)
}

public static func == (lhs: PersonExternalLinksCollection, rhs: PersonExternalLinksCollection) -> Bool {
lhs.id == rhs.id
&& lhs.imdb == rhs.imdb
&& lhs.wikiData == rhs.wikiData
&& lhs.facebook == rhs.facebook
&& lhs.instagram == rhs.instagram
&& lhs.twitter == rhs.twitter
&& lhs.tikTok == rhs.tikTok
}

}

public extension PersonExternalLinksCollection {
Expand Down
2 changes: 2 additions & 0 deletions Sources/TMDb/Domain/Models/TMDbError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public enum TMDbError: Equatable, LocalizedError, Sendable {

public extension TMDbError {

///
/// A localized message describing what error occurred.
///
var errorDescription: String? {
switch self {
case .notFound:
Expand Down
18 changes: 0 additions & 18 deletions Sources/TMDb/Domain/Models/TVSeriesExternalLinksCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ public struct TVSeriesExternalLinksCollection: Identifiable, Codable, Equatable,
self.twitter = twitter
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(imdb?.id)
hasher.combine(wikiData?.id)
hasher.combine(facebook?.id)
hasher.combine(instagram?.id)
hasher.combine(twitter?.id)
}

public static func == (lhs: TVSeriesExternalLinksCollection, rhs: TVSeriesExternalLinksCollection) -> Bool {
lhs.id == rhs.id
&& lhs.imdb == rhs.imdb
&& lhs.wikiData == rhs.wikiData
&& lhs.facebook == rhs.facebook
&& lhs.instagram == rhs.instagram
&& lhs.twitter == rhs.twitter
}

}

public extension TVSeriesExternalLinksCollection {
Expand Down
30 changes: 30 additions & 0 deletions Tests/TMDbTests/Domain/Models/PersonCombinedCreditsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ final class PersonCombinedCreditsTests: XCTestCase {
XCTAssertEqual(result.crew, personCombinedCredits.crew)
}

func testAllShows() {
let credits = PersonCombinedCredits(
id: 1,
cast: [
.movie(Movie(id: 1, title: "Movie 1")),
.movie(Movie(id: 2, title: "Movie 2")),
.tvSeries(TVSeries(id: 11, name: "TV 1")),
.tvSeries(TVSeries(id: 12, name: "TV 2"))
],
crew: [
.movie(Movie(id: 1, title: "Movie 1")),
.movie(Movie(id: 3, title: "Movie 3")),
.tvSeries(TVSeries(id: 11, name: "TV 1")),
.tvSeries(TVSeries(id: 13, name: "TV 3"))
]
)
let expectedResult: [Show] = [
.movie(Movie(id: 1, title: "Movie 1")),
.movie(Movie(id: 2, title: "Movie 2")),
.movie(Movie(id: 3, title: "Movie 3")),
.tvSeries(TVSeries(id: 11, name: "TV 1")),
.tvSeries(TVSeries(id: 12, name: "TV 2")),
.tvSeries(TVSeries(id: 13, name: "TV 3"))
].sorted { $0.id < $1.id }

let result = credits.allShows.sorted { $0.id < $1.id }

XCTAssertEqual(result, expectedResult)
}

// swiftlint:disable line_length
private let personCombinedCredits = PersonCombinedCredits(
id: 287,
Expand Down

0 comments on commit 01374e6

Please sign in to comment.