Skip to content

Commit

Permalink
BUG: Fix empty person external link IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung committed Jan 2, 2025
1 parent 5b99bf4 commit 5e128b9
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/FacebookLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/IMDbLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/InstagramLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/TikTokLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/TwitterLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/TMDb/Domain/Models/WikiDataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Sources/TMDb/Domain/Services/People/TMDbPersonService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/FacebookLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/IMDbLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/InstagramLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/TikTokLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/TwitterLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Tests/TMDbTests/Domain/Models/WikiDataLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5e128b9

Please sign in to comment.