MCPcopy Index your code
hub / github.com/coder/coder / TestChatCostSummary_DateRange

Function TestChatCostSummary_DateRange

coderd/exp_chats_test.go:10375–10425  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10373}
10374
10375func TestChatCostSummary_DateRange(t *testing.T) {
10376 t.Parallel()
10377
10378 client, db := newChatClientWithDatabase(t)
10379 firstUser := coderdtest.CreateFirstUser(t, client.Client)
10380 modelConfig := createChatModelConfig(t, client)
10381
10382 chat := dbgen.Chat(t, db, database.Chat{
10383 OrganizationID: firstUser.OrganizationID,
10384 OwnerID: firstUser.UserID,
10385 LastModelConfigID: modelConfig.ID,
10386 Title: "date range test",
10387 })
10388
10389 _ = dbgen.ChatMessage(t, db, database.ChatMessage{
10390 ChatID: chat.ID,
10391 ModelConfigID: uuid.NullUUID{UUID: modelConfig.ID, Valid: true},
10392 Role: database.ChatMessageRoleAssistant,
10393 InputTokens: sql.NullInt64{Int64: 100, Valid: true},
10394 OutputTokens: sql.NullInt64{Int64: 50, Valid: true},
10395 TotalCostMicros: sql.NullInt64{Int64: 500, Valid: true},
10396 })
10397
10398 now := time.Now()
10399
10400 t.Run("MessageInRange", func(t *testing.T) {
10401 t.Parallel()
10402
10403 ctx := testutil.Context(t, testutil.WaitLong)
10404 summary, err := client.GetChatCostSummary(ctx, "me", codersdk.ChatCostSummaryOptions{
10405 StartDate: now.Add(-time.Hour),
10406 EndDate: now.Add(time.Hour),
10407 })
10408 require.NoError(t, err)
10409 require.Equal(t, int64(500), summary.TotalCostMicros)
10410 require.Equal(t, int64(1), summary.PricedMessageCount)
10411 })
10412
10413 t.Run("MessageOutOfRange", func(t *testing.T) {
10414 t.Parallel()
10415
10416 ctx := testutil.Context(t, testutil.WaitLong)
10417 summary, err := client.GetChatCostSummary(ctx, "me", codersdk.ChatCostSummaryOptions{
10418 StartDate: now.Add(time.Hour),
10419 EndDate: now.Add(2 * time.Hour),
10420 })
10421 require.NoError(t, err)
10422 require.Equal(t, int64(0), summary.TotalCostMicros)
10423 require.Equal(t, int64(0), summary.PricedMessageCount)
10424 })
10425}
10426
10427func TestChatCostSummary_UnpricedMessages(t *testing.T) {
10428 t.Parallel()

Callers

nothing calls this directly

Calls 10

CreateFirstUserFunction · 0.92
ChatFunction · 0.92
ChatMessageFunction · 0.92
ContextFunction · 0.92
createChatModelConfigFunction · 0.70
RunMethod · 0.65
GetChatCostSummaryMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected