-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(component): Add more test cases for anomalous conditions
Some conditions must cause errors.
- Loading branch information
Showing
4 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import { type service, services } from "../types/services"; | ||
|
||
const isFediverse = (service: service): boolean => { | ||
return service === "Mastodon" || service === "Misskey"; | ||
}; | ||
|
||
type contact = { url: string; icon: string }; | ||
|
||
export const getContact = (service: service, id: string): contact => { | ||
const url: string = | ||
service === "Mastodon" || service === "Misskey" | ||
? `https://${id.split("@")[2]}/${id}` | ||
: services[service].url + id; | ||
return { url, icon: services[service].icon }; | ||
const specified: contact = services[service]; | ||
|
||
if (!specified) throw new Error(`Unsupported service: ${service}`); | ||
|
||
if (isFediverse(service)) { | ||
const parts: string[] = id.split("@"); | ||
if (parts.length !== 3 || parts[0] !== "") { | ||
throw new Error(`Invalid ${service} ID format`); | ||
} | ||
} | ||
|
||
const url: string = isFediverse(service) | ||
? `https://${id.split("@")[2]}/${id}` | ||
: specified.url + id; | ||
return { url, icon: specified.icon }; | ||
}; |