Mike Schwörer 8c0f0e3e8f
All checks were successful
Build Docker and Deploy / Run Unit-Tests (push) Has been skipped
Build Docker and Deploy / Build Docker Container (push) Successful in 43s
Build Docker and Deploy / Deploy to Server (push) Successful in 16s
Add various deleted flags to entities | Add active to subscriptions | Add DeleteUser && DeleteChannel endpoints [skip-tests]
2025-04-13 16:22:55 +02:00

35 lines
1.3 KiB
Go

package util
import (
"fmt"
"testing"
)
func FindSubscriptionByChanName(t *testing.T, baseUrl string, subscriber Userdat, ownerUID string, chanName string) (subscriptionID string, channelID string) {
type subobj struct {
SubscriptionId string `json:"subscription_id"`
ChannelId string `json:"channel_id"`
ChannelInternalName string `json:"channel_internal_name"`
ChannelOwnerUserId string `json:"channel_owner_user_id"`
Confirmed bool `json:"confirmed"`
Active bool `json:"active"`
}
type sublist struct {
Subscriptions []subobj `json:"subscriptions"`
}
subs := RequestAuthGet[sublist](t, subscriber.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?direction=outgoing", subscriber.UID))
for _, sub := range subs.Subscriptions {
if sub.ChannelOwnerUserId == ownerUID && sub.ChannelInternalName == chanName {
fullSub := RequestAuthGet[subobj](t, subscriber.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", subscriber.UID, sub.SubscriptionId))
if fullSub.ChannelOwnerUserId == ownerUID && fullSub.ChannelInternalName == chanName {
return fullSub.SubscriptionId, fullSub.ChannelId
}
}
}
t.Fatalf("Could not find subscription for user %s to channel %s owned by %s", subscriber.UID, chanName, ownerUID)
return "", ""
}