component.share(link)
// expect(navigatorSpy).toHaveBeenCalledWith({ url: component.getShareUrl(link) })
})
+
+ it('should correctly generate share URLs', () => {
+ environment.apiBaseUrl = 'http://example.com/api/'
+ expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
+ 'http://example.com/share/123abc123'
+ )
+ environment.apiBaseUrl = 'http://example.domainwithapiinit.com/api/'
+ expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
+ 'http://example.domainwithapiinit.com/share/123abc123'
+ )
+ environment.apiBaseUrl = 'http://example.domainwithapiinit.com:1234/api/'
+ expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
+ 'http://example.domainwithapiinit.com:1234/share/123abc123'
+ )
+ environment.apiBaseUrl =
+ 'http://example.domainwithapiinit.com:1234/subpath/api/'
+ expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
+ 'http://example.domainwithapiinit.com:1234/subpath/share/123abc123'
+ )
+ })
})
}
getShareUrl(link: PaperlessShareLink): string {
- return `${environment.apiBaseUrl.replace('api', 'share')}${link.slug}`
+ const apiURL = new URL(environment.apiBaseUrl)
+ return `${apiURL.origin}${apiURL.pathname.replace(/\/api\/$/, '/share/')}${
+ link.slug
+ }`
}
getDaysRemaining(link: PaperlessShareLink): string {