...

Source file src/github.com/okta/okta-sdk-golang/v2/tests/integration/subscription_test.go

Documentation: github.com/okta/okta-sdk-golang/v2/tests/integration

     1  /*
     2   * Copyright 2018 - Present Okta, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package integration
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/okta/okta-sdk-golang/v2/tests"
    24  	"github.com/stretchr/testify/assert"
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  func TestListRoleSubscriptions(t *testing.T) {
    29  	ctx, client, err := tests.NewClient(context.TODO())
    30  	require.NoError(t, err)
    31  
    32  	subscriptions, _, err := client.Subscription.ListRoleSubscriptions(ctx, "SUPER_ADMIN")
    33  	require.NoError(t, err, "Getting subscriptions for a role should not error")
    34  
    35  	assert.True(t, len(subscriptions) > 0, "There should be subscriptions")
    36  }
    37  
    38  func TestGetRoleSubscriptionByNotificationType(t *testing.T) {
    39  	ctx, client, err := tests.NewClient(context.TODO())
    40  	require.NoError(t, err)
    41  
    42  	subscription, _, err := client.Subscription.GetRoleSubscriptionByNotificationType(ctx, "SUPER_ADMIN", "OKTA_ANNOUNCEMENT")
    43  	require.NoError(t, err, "Getting subscription for a role by a notification type should not error")
    44  
    45  	assert.True(t, subscription.NotificationType == "OKTA_ANNOUNCEMENT", "There should be a subscription")
    46  }
    47  
    48  func TestSubscribeRoleSubscriptionByNotificationType(t *testing.T) {
    49  	ctx, client, err := tests.NewClient(context.TODO())
    50  	require.NoError(t, err)
    51  
    52  	_, err = client.Subscription.SubscribeRoleSubscriptionByNotificationType(ctx, "SUPER_ADMIN", "OKTA_ANNOUNCEMENT")
    53  	require.NoError(t, err, "Subscribing for a role by a notification type should not error")
    54  }
    55  
    56  func TestUnsubscribeRoleSubscriptionByNotificationType(t *testing.T) {
    57  	ctx, client, err := tests.NewClient(context.TODO())
    58  	require.NoError(t, err)
    59  
    60  	_, err = client.Subscription.UnsubscribeRoleSubscriptionByNotificationType(ctx, "SUPER_ADMIN", "OKTA_ANNOUNCEMENT")
    61  	require.NoError(t, err, "Unsubscribing for a role by a notification type should not error")
    62  }
    63  
    64  func TestSubscribeUserSubscriptionByNotificationType(t *testing.T) {
    65  	ctx, client, err := tests.NewClient(context.TODO())
    66  	require.NoError(t, err)
    67  
    68  	user, _, err := client.User.GetUser(ctx, "me")
    69  	require.NoError(t, err, "Getting the current user should not error")
    70  
    71  	_, err = client.Subscription.SubscribeUserSubscriptionByNotificationType(ctx, user.Id, "OKTA_ANNOUNCEMENT")
    72  	require.NoError(t, err, "Subscribing user by a notification type should not error")
    73  }
    74  
    75  func TestUnsubscribeUserSubscriptionByNotificationType(t *testing.T) {
    76  	ctx, client, err := tests.NewClient(context.TODO())
    77  	require.NoError(t, err)
    78  
    79  	user, _, err := client.User.GetUser(ctx, "me")
    80  	require.NoError(t, err, "Getting the current user should not error")
    81  
    82  	_, err = client.Subscription.UnsubscribeUserSubscriptionByNotificationType(ctx, user.Id, "OKTA_ANNOUNCEMENT")
    83  	require.NoError(t, err, "Unsubscribing user by a notification type should not error")
    84  }
    85  

View as plain text