(t *testing.T)
| 10373 | } |
| 10374 | |
| 10375 | func 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 | |
| 10427 | func TestChatCostSummary_UnpricedMessages(t *testing.T) { |
| 10428 | t.Parallel() |
nothing calls this directly
no test coverage detected