From 5e128b901b8230dbfd85591e9144d78b4729fdf2 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Thu, 2 Jan 2025 20:43:44 +0000 Subject: [PATCH] BUG: Fix empty person external link IDs --- Sources/TMDb/Domain/Models/FacebookLink.swift | 1 + Sources/TMDb/Domain/Models/IMDbLink.swift | 1 + Sources/TMDb/Domain/Models/InstagramLink.swift | 1 + Sources/TMDb/Domain/Models/TikTokLink.swift | 1 + Sources/TMDb/Domain/Models/TwitterLink.swift | 1 + Sources/TMDb/Domain/Models/WikiDataLink.swift | 1 + .../TMDb/Domain/Services/People/TMDbPersonService.swift | 5 +++-- Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift | 7 +++++++ Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift | 7 +++++++ Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift | 7 +++++++ Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift | 7 +++++++ Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift | 7 +++++++ Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift | 7 +++++++ 13 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Sources/TMDb/Domain/Models/FacebookLink.swift b/Sources/TMDb/Domain/Models/FacebookLink.swift index be586582..d43213fb 100644 --- a/Sources/TMDb/Domain/Models/FacebookLink.swift +++ b/Sources/TMDb/Domain/Models/FacebookLink.swift @@ -44,6 +44,7 @@ public struct FacebookLink: ExternalLink { public init?(facebookID: String?) { guard let facebookID, + !facebookID.isEmpty, let url = Self.facebookURL(for: facebookID) else { return nil diff --git a/Sources/TMDb/Domain/Models/IMDbLink.swift b/Sources/TMDb/Domain/Models/IMDbLink.swift index 6f776b1a..5117d6af 100644 --- a/Sources/TMDb/Domain/Models/IMDbLink.swift +++ b/Sources/TMDb/Domain/Models/IMDbLink.swift @@ -64,6 +64,7 @@ public struct IMDbLink: ExternalLink { public init?(imdbNameID: String?) { guard let imdbNameID, + !imdbNameID.isEmpty, let url = Self.imdbURL(forName: imdbNameID) else { return nil diff --git a/Sources/TMDb/Domain/Models/InstagramLink.swift b/Sources/TMDb/Domain/Models/InstagramLink.swift index ae209ff2..9be98be5 100644 --- a/Sources/TMDb/Domain/Models/InstagramLink.swift +++ b/Sources/TMDb/Domain/Models/InstagramLink.swift @@ -44,6 +44,7 @@ public struct InstagramLink: ExternalLink { public init?(instagramID: String?) { guard let instagramID, + !instagramID.isEmpty, let url = Self.instagramURL(for: instagramID) else { return nil diff --git a/Sources/TMDb/Domain/Models/TikTokLink.swift b/Sources/TMDb/Domain/Models/TikTokLink.swift index 6a0b2565..4bd0a8a6 100644 --- a/Sources/TMDb/Domain/Models/TikTokLink.swift +++ b/Sources/TMDb/Domain/Models/TikTokLink.swift @@ -44,6 +44,7 @@ public struct TikTokLink: ExternalLink { public init?(tikTokID: String?) { guard let tikTokID, + !tikTokID.isEmpty, let url = Self.tikTokURL(for: tikTokID) else { return nil diff --git a/Sources/TMDb/Domain/Models/TwitterLink.swift b/Sources/TMDb/Domain/Models/TwitterLink.swift index 0a9003c0..3296061e 100644 --- a/Sources/TMDb/Domain/Models/TwitterLink.swift +++ b/Sources/TMDb/Domain/Models/TwitterLink.swift @@ -44,6 +44,7 @@ public struct TwitterLink: ExternalLink { public init?(twitterID: String?) { guard let twitterID, + !twitterID.isEmpty, let url = Self.twitterURL(for: twitterID) else { return nil diff --git a/Sources/TMDb/Domain/Models/WikiDataLink.swift b/Sources/TMDb/Domain/Models/WikiDataLink.swift index 36bf4129..310e723d 100644 --- a/Sources/TMDb/Domain/Models/WikiDataLink.swift +++ b/Sources/TMDb/Domain/Models/WikiDataLink.swift @@ -44,6 +44,7 @@ public struct WikiDataLink: ExternalLink { public init?(wikiDataID: String?) { guard let wikiDataID, + !wikiDataID.isEmpty, let url = Self.wikiDataURL(for: wikiDataID) else { return nil diff --git a/Sources/TMDb/Domain/Services/People/TMDbPersonService.swift b/Sources/TMDb/Domain/Services/People/TMDbPersonService.swift index d8b81124..95ffa026 100644 --- a/Sources/TMDb/Domain/Services/People/TMDbPersonService.swift +++ b/Sources/TMDb/Domain/Services/People/TMDbPersonService.swift @@ -115,8 +115,9 @@ final class TMDbPersonService: PersonService { return personList } - func externalLinks(forPerson personID: Person.ID) async throws -> PersonExternalLinksCollection - { + func externalLinks( + forPerson personID: Person.ID + ) async throws -> PersonExternalLinksCollection { let request = PersonExternalLinksRequest(id: personID) let linksCollection: PersonExternalLinksCollection diff --git a/Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift b/Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift index 5afc834f..af8af1e6 100644 --- a/Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift @@ -32,6 +32,13 @@ struct FacebookLinkTests { #expect(facebookLink == nil) } + @Test("Init with Facebook ID when ID is empty string returns nil") + func initWithFacebookIDWhenIDIsEmptyStringReturnsNil() { + let facebookLink = FacebookLink(facebookID: "") + + #expect(facebookLink == nil) + } + @Test("Facebook URL") func testURL() throws { let facebookID = "BarbieTheMovie" diff --git a/Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift b/Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift index edb03486..a62900b7 100644 --- a/Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift @@ -39,6 +39,13 @@ struct IMDbLinkTests { #expect(imdbLink == nil) } + @Test("init with IMDB name ID when ID is empty string returns nil") + func initWithIMDbNameIDWhenIDIsEmptyStringReturnsNil() { + let imdbLink = IMDbLink(imdbNameID: "") + + #expect(imdbLink == nil) + } + @Test("URL when using title ID returns show URL") func urlWhenUsingTitleIDReturnsShowURL() throws { let imdbID = "tt1517268" diff --git a/Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift b/Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift index 7c98f8be..e6716751 100644 --- a/Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift @@ -32,6 +32,13 @@ struct InstagramLinkTests { #expect(instagramLink == nil) } + @Test("init with instagramID when ID is empty string returns nil") + func initWithInstagramIDWhenIDIsEmptyStringReturnsNil() { + let instagramLink = InstagramLink(instagramID: "") + + #expect(instagramLink == nil) + } + @Test("URL returns post URL") func urlReturnsPostURL() throws { let instagramID = "barbiethemovie" diff --git a/Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift b/Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift index 7bee8427..0521a064 100644 --- a/Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift @@ -32,6 +32,13 @@ struct TikTokLinkTests { #expect(tikTokLink == nil) } + @Test("init with TikTok ID when ID is empty string returns nil") + func initWithTikTokIDWhenIDIsEmptyStringReturnsNil() { + let tikTokLink = TikTokLink(tikTokID: "") + + #expect(tikTokLink == nil) + } + @Test("url returns TikTok URL") func urlReturnsTikTokURL() throws { let tikTokID = "jasonstatham" diff --git a/Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift b/Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift index 545d60cb..82caee6a 100644 --- a/Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift @@ -32,6 +32,13 @@ struct TwitterLinkTests { #expect(twitterLint == nil) } + @Test("init with twitterID when ID is empty string returns nil") + func initWithTwitterIDWhenIDIsEmptyStringReturnsNil() { + let twitterLint = TwitterLink(twitterID: "") + + #expect(twitterLint == nil) + } + @Test("url returns Twitter URL") func urlReturnsTwitterURL() throws { let twitterID = "barbiethemovie" diff --git a/Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift b/Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift index f404fea1..38d55b4b 100644 --- a/Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift +++ b/Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift @@ -32,6 +32,13 @@ struct WikiDataLinkTests { #expect(wikiDataLink == nil) } + @Test("init with wikiDataID when ID is empty string returns nil") + func initWithWikiDataIDWhenIDIsEmptyStringReturnsNil() { + let wikiDataLink = WikiDataLink(wikiDataID: "") + + #expect(wikiDataLink == nil) + } + @Test("url returns WikiData URL") func urlReturnsWikiDataURL() throws { let wikiDataID = "Q55436290"