hi-server/internal/logic/common/getdownloadlinklogic_test.go
2026-01-27 03:13:15 -08:00

65 lines
1.4 KiB
Go

package common
import (
"context"
"testing"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/stretchr/testify/assert"
)
func TestGetDownloadLinkLogic_GetDownloadLink(t *testing.T) {
svcCtx := &svc.ServiceContext{
Config: config.Config{
Site: config.SiteConfig{
Host: "test.example.com",
},
},
}
ctx := context.Background()
l := NewGetDownloadLinkLogic(ctx, svcCtx)
tests := []struct {
name string
req *types.GetDownloadLinkRequest
wantSubStr []string // strings that should be in the URL
notSubStr []string // strings that should NOT be in the URL
}{
{
name: "With Invite Code",
req: &types.GetDownloadLinkRequest{
Platform: "windows",
InviteCode: "TESTCODE",
},
wantSubStr: []string{"-ic_TESTCODE.exe"},
notSubStr: []string{},
},
{
name: "Without Invite Code",
req: &types.GetDownloadLinkRequest{
Platform: "mac",
InviteCode: "",
},
wantSubStr: []string{".dmg"},
notSubStr: []string{"-ic", "ic_"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp, err := l.GetDownloadLink(tt.req)
assert.NoError(t, err)
assert.NotNil(t, resp)
for _, s := range tt.wantSubStr {
assert.Contains(t, resp.Url, s)
}
for _, s := range tt.notSubStr {
assert.NotContains(t, resp.Url, s)
}
})
}
}