mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Add test for making QR code url
This commit is contained in:
@@ -11,7 +11,7 @@ func MakeQRCodeURL(data string) string {
|
|||||||
rv := url.URL{
|
rv := url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: "api.qrserver.com",
|
Host: "api.qrserver.com",
|
||||||
Path: "v1/create-qr-code",
|
Path: "/v1/create-qr-code",
|
||||||
RawQuery: values.Encode(),
|
RawQuery: values.Encode(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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{})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user