Add test for making QR code url

This commit is contained in:
9seconds
2021-07-30 15:18:26 +03:00
parent ed91290e47
commit c53364d952
2 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ func MakeQRCodeURL(data string) string {
rv := url.URL{
Scheme: "https",
Host: "api.qrserver.com",
Path: "v1/create-qr-code",
Path: "/v1/create-qr-code",
RawQuery: values.Encode(),
}
+31
View File
@@ -0,0 +1,31 @@
package utils_test
import (
"net/url"
"strings"
"testing"
"github.com/9seconds/mtg/v2/internal/utils"
"github.com/stretchr/testify/suite"
)
type MakeQRCodeURLTestSuite struct {
suite.Suite
}
func (suite *MakeQRCodeURLTestSuite) TestSomeData() {
value := utils.MakeQRCodeURL("some data")
parsed, err := url.Parse(value)
suite.NoError(err)
suite.Equal("some data", parsed.Query().Get("data"))
suite.Equal("svg", parsed.Query().Get("format"))
suite.Equal("api.qrserver.com", strings.TrimPrefix(parsed.Host, "www."))
suite.Equal("v1/create-qr-code", strings.Trim(parsed.Path, "/"))
}
func TestMakeQRCodeURL(t *testing.T) {
t.Parallel()
suite.Run(t, &MakeQRCodeURLTestSuite{})
}