github.com/anthropics/anthropic-sdk-go@v1.70.1/betauserprofile_test.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic_test
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"os"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/anthropics/anthropic-sdk-go"
    13  	"github.com/anthropics/anthropic-sdk-go/internal/testutil"
    14  	"github.com/anthropics/anthropic-sdk-go/option"
    15  )
    16  
    17  func TestBetaUserProfileNewWithOptionalParams(t *testing.T) {
    18  	baseURL := "http://localhost:4010"
    19  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    20  		baseURL = envURL
    21  	}
    22  	if !testutil.CheckTestServer(t, baseURL) {
    23  		return
    24  	}
    25  	client := anthropic.NewClient(
    26  		option.WithBaseURL(baseURL),
    27  		option.WithAPIKey("my-anthropic-api-key"),
    28  	)
    29  	_, err := client.Beta.UserProfiles.New(context.TODO(), anthropic.BetaUserProfileNewParams{
    30  		AccessType:              anthropic.BetaUserProfileNewParamsAccessTypeApplication,
    31  		ExternalID:              anthropic.String("user_12345"),
    32  		ExternalUserOnboardedAt: anthropic.Time(time.Now()),
    33  		Metadata:                map[string]string{},
    34  		Name:                    anthropic.String("x"),
    35  		Betas:                   []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    36  	})
    37  	if err != nil {
    38  		var apierr *anthropic.Error
    39  		if errors.As(err, &apierr) {
    40  			t.Log(string(apierr.DumpRequest(true)))
    41  		}
    42  		t.Fatalf("err should be nil: %s", err.Error())
    43  	}
    44  }
    45  
    46  func TestBetaUserProfileGetWithOptionalParams(t *testing.T) {
    47  	baseURL := "http://localhost:4010"
    48  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    49  		baseURL = envURL
    50  	}
    51  	if !testutil.CheckTestServer(t, baseURL) {
    52  		return
    53  	}
    54  	client := anthropic.NewClient(
    55  		option.WithBaseURL(baseURL),
    56  		option.WithAPIKey("my-anthropic-api-key"),
    57  	)
    58  	_, err := client.Beta.UserProfiles.Get(
    59  		context.TODO(),
    60  		"uprof_011CZkZCu8hGbp5mYRQgUmz9",
    61  		anthropic.BetaUserProfileGetParams{
    62  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    63  		},
    64  	)
    65  	if err != nil {
    66  		var apierr *anthropic.Error
    67  		if errors.As(err, &apierr) {
    68  			t.Log(string(apierr.DumpRequest(true)))
    69  		}
    70  		t.Fatalf("err should be nil: %s", err.Error())
    71  	}
    72  }
    73  
    74  func TestBetaUserProfileUpdateWithOptionalParams(t *testing.T) {
    75  	baseURL := "http://localhost:4010"
    76  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    77  		baseURL = envURL
    78  	}
    79  	if !testutil.CheckTestServer(t, baseURL) {
    80  		return
    81  	}
    82  	client := anthropic.NewClient(
    83  		option.WithBaseURL(baseURL),
    84  		option.WithAPIKey("my-anthropic-api-key"),
    85  	)
    86  	_, err := client.Beta.UserProfiles.Update(
    87  		context.TODO(),
    88  		"uprof_011CZkZCu8hGbp5mYRQgUmz9",
    89  		anthropic.BetaUserProfileUpdateParams{
    90  			AccessType:              anthropic.BetaUserProfileUpdateParamsAccessTypeApplication,
    91  			ExternalID:              anthropic.String("user_12345"),
    92  			ExternalUserOnboardedAt: anthropic.Time(time.Now()),
    93  			Metadata: map[string]string{
    94  				"foo": "string",
    95  			},
    96  			Name:  anthropic.String("x"),
    97  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    98  		},
    99  	)
   100  	if err != nil {
   101  		var apierr *anthropic.Error
   102  		if errors.As(err, &apierr) {
   103  			t.Log(string(apierr.DumpRequest(true)))
   104  		}
   105  		t.Fatalf("err should be nil: %s", err.Error())
   106  	}
   107  }
   108  
   109  func TestBetaUserProfileListWithOptionalParams(t *testing.T) {
   110  	baseURL := "http://localhost:4010"
   111  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   112  		baseURL = envURL
   113  	}
   114  	if !testutil.CheckTestServer(t, baseURL) {
   115  		return
   116  	}
   117  	client := anthropic.NewClient(
   118  		option.WithBaseURL(baseURL),
   119  		option.WithAPIKey("my-anthropic-api-key"),
   120  	)
   121  	_, err := client.Beta.UserProfiles.List(context.TODO(), anthropic.BetaUserProfileListParams{
   122  		Limit:   anthropic.Int(0),
   123  		Order:   anthropic.BetaUserProfileListParamsOrderAsc,
   124  		OrderBy: anthropic.BetaUserProfileListParamsOrderByCreatedAt,
   125  		Page:    anthropic.String("page"),
   126  		Betas:   []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   127  	})
   128  	if err != nil {
   129  		var apierr *anthropic.Error
   130  		if errors.As(err, &apierr) {
   131  			t.Log(string(apierr.DumpRequest(true)))
   132  		}
   133  		t.Fatalf("err should be nil: %s", err.Error())
   134  	}
   135  }
   136  
   137  func TestBetaUserProfileNewEnrollmentURLWithOptionalParams(t *testing.T) {
   138  	baseURL := "http://localhost:4010"
   139  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   140  		baseURL = envURL
   141  	}
   142  	if !testutil.CheckTestServer(t, baseURL) {
   143  		return
   144  	}
   145  	client := anthropic.NewClient(
   146  		option.WithBaseURL(baseURL),
   147  		option.WithAPIKey("my-anthropic-api-key"),
   148  	)
   149  	_, err := client.Beta.UserProfiles.NewEnrollmentURL(
   150  		context.TODO(),
   151  		"uprof_011CZkZCu8hGbp5mYRQgUmz9",
   152  		anthropic.BetaUserProfileNewEnrollmentURLParams{
   153  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   154  		},
   155  	)
   156  	if err != nil {
   157  		var apierr *anthropic.Error
   158  		if errors.As(err, &apierr) {
   159  			t.Log(string(apierr.DumpRequest(true)))
   160  		}
   161  		t.Fatalf("err should be nil: %s", err.Error())
   162  	}
   163  }