Skip to content

Commit

Permalink
fix: correct hasdomain function and increase df update letter
Browse files Browse the repository at this point in the history
  • Loading branch information
minhluuquang authored and huynguyenh committed Apr 5, 2023
1 parent 16b0b9f commit f582765
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/service/notion/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const MJMLChangelogTemplate = ` <mjml> <mj-head> <mj-title>Changelog Email</mj-t

// MJMLDFUpdateTemplate is the template for the Dwarves Updates email
const MJMLDFUpdateTemplate = ` <mjml> <mj-head> <mj-title>Changelog Email</mj-title> <mj-attributes> <mj-all font-family="Helvetica, sans-serif"></mj-all> <mj-section padding="0px"></mj-section>
<mj-text font-weight="400" font-size="12px" line-height="16px" font-family="helvetica"></mj-text>
<mj-text font-weight="400" font-size="13px" line-height="16px" font-family="helvetica"></mj-text>
</mj-attributes>
</mj-head>
<mj-body>
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ func RemoveAllSpace(str string) string {

func HasDomain(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != "" && regexp.MustCompile(`^[^.]+\.?[^.]+$`).MatchString(u.Host)
return err == nil && u.Scheme != "" && u.Host != "" && regexp.MustCompile(`^[^.]+\.[^.]+(\.[^.]+)*$`).MatchString(u.Host)
}
32 changes: 31 additions & 1 deletion pkg/utils/strings_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import "testing"
import (
"testing"
)

func TestIsNumber(t *testing.T) {
type args struct {
Expand Down Expand Up @@ -34,3 +36,31 @@ func TestIsNumber(t *testing.T) {
})
}
}

func TestHasDomain(t *testing.T) {
testCases := []struct {
url string
expected bool
}{
{"https://www.example.com", true},
{"https://www.facebook.com", true},
{"http://google.com", true},
{"https://docs.google.co.uk", true},
{"https://example.com", true},
{"https://example.co.uk", true},
{"https://sub.example.co.uk", true},
{"https://sub.sub.example.co.uk", true},
{"https://example..com", false},
{"ftp://example.com", true},
{"not a url", false},
}

for _, tc := range testCases {
t.Run(tc.url, func(t *testing.T) {
result := HasDomain(tc.url)
if result != tc.expected {
t.Errorf("HasDomain() = %v, want %v", result, tc.expected)
}
})
}
}

0 comments on commit f582765

Please sign in to comment.