Skip to content

Commit

Permalink
add gif link type
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Aug 30, 2021
1 parent 05465ee commit c8615ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 21 additions & 1 deletion engagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ func (l *Link) validateLinkType() error {
if !strings.Contains(l.URL, ".png") {
return fmt.Errorf("%s does not end with .pdf", l.URL)
}
case LinkTypeGif:
if !strings.Contains(l.URL, ".gif") {
return fmt.Errorf("%s does not end with .gif", l.URL)
}
case LinkTypePngImage:
if !strings.Contains(l.URL, ".png") {
return fmt.Errorf("%s does not end with .png", l.URL)
Expand Down Expand Up @@ -722,6 +726,7 @@ const (
LinkTypePngImage LinkType = "PNG_IMAGE"
LinkTypePdfDocument LinkType = "PDF_DOCUMENT"
LinkTypeSvgImage LinkType = "SVG_IMAGE"
LinkTypeGif LinkType = "GIF"
LinkTypeDefault LinkType = "DEFAULT"
)

Expand All @@ -731,13 +736,14 @@ var AllLinkType = []LinkType{
LinkTypePngImage,
LinkTypePdfDocument,
LinkTypeSvgImage,
LinkTypeGif,
LinkTypeDefault,
}

// IsValid is true only when a link type is avalid
func (e LinkType) IsValid() bool {
switch e {
case LinkTypeYoutubeVideo, LinkTypePngImage, LinkTypePdfDocument, LinkTypeSvgImage, LinkTypeDefault:
case LinkTypeYoutubeVideo, LinkTypePngImage, LinkTypePdfDocument, LinkTypeSvgImage, LinkTypeGif, LinkTypeDefault:
return true
}
return false
Expand Down Expand Up @@ -1016,6 +1022,20 @@ func GetPDFDocumentLink(url string, title string, description string, thumbnailU
}
}

// GetGIFLink returns an initialized GIF link.
//
// It is used in testing and default data generation.
func GetGIFLink(url string, title string, description string, thumbnailURL string) Link {
return Link{
ID: ksuid.New().String(),
URL: url,
LinkType: LinkTypeGif,
Title: title,
Description: description,
Thumbnail: thumbnailURL,
}
}

// getSchemaURL serves JSON schema from this server and only falls back to a
// remote schema host when the local server cannot serve the JSON schema files.
// This has been done so as to reduce the impact of the network and DNS on the
Expand Down
5 changes: 5 additions & 0 deletions engagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,11 @@ func TestLinkType_MarshalGQL(t *testing.T) {
e: feedlib.LinkTypeYoutubeVideo,
wantW: `"YOUTUBE_VIDEO"`,
},
{
name: "GIF",
e: feedlib.LinkTypeGif,
wantW: `"GIF"`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit c8615ee

Please sign in to comment.