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

Function TestGetUserStatusCounts

coderd/insights_test.go:2484–2568  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2482}
2483
2484func TestGetUserStatusCounts(t *testing.T) {
2485 t.Parallel()
2486
2487 type testCase struct {
2488 name string
2489 request codersdk.GetUserStatusCountsRequest
2490 checkError func(t *testing.T, err error)
2491 checkResponse func(t *testing.T, resp codersdk.GetUserStatusCountsResponse)
2492 }
2493
2494 happyResponseCheck := func(t *testing.T, resp codersdk.GetUserStatusCountsResponse) {
2495 require.Len(t, resp.StatusCounts, 1)
2496 require.NotNil(t, resp.StatusCounts[codersdk.UserStatusActive])
2497 require.Len(t, resp.StatusCounts[codersdk.UserStatusActive], 61)
2498 // Depending on the current time of day relative to the
2499 // timezone/offset, the first user's creation may land on the
2500 // last date in the range. All earlier dates must be zero; the
2501 // last date may be 0 or 1.
2502 counts := resp.StatusCounts[codersdk.UserStatusActive]
2503 for _, count := range counts[:len(counts)-1] {
2504 require.Zero(t, count.Count)
2505 }
2506 require.LessOrEqual(t, counts[len(counts)-1].Count, int64(1))
2507 }
2508 testcases := []testCase{
2509 {
2510 name: "OK when timezone and offset are provided",
2511 request: codersdk.GetUserStatusCountsRequest{
2512 Timezone: "America/St_Johns",
2513 Offset: -2,
2514 },
2515 checkError: func(t *testing.T, err error) {
2516 require.NoError(t, err)
2517 },
2518 checkResponse: happyResponseCheck,
2519 },
2520 {
2521 name: "OK when timezone without offset",
2522 request: codersdk.GetUserStatusCountsRequest{
2523 Timezone: "America/St_Johns",
2524 },
2525 checkError: func(t *testing.T, err error) {
2526 require.NoError(t, err)
2527 },
2528 checkResponse: happyResponseCheck,
2529 },
2530 {
2531 name: "OK when offset is provided without timezone",
2532 request: codersdk.GetUserStatusCountsRequest{
2533 Offset: -2,
2534 },
2535 checkError: func(t *testing.T, err error) {
2536 require.NoError(t, err)
2537 },
2538 checkResponse: happyResponseCheck,
2539 },
2540 {
2541 name: "Error when timezone is invalid",

Callers

nothing calls this directly

Calls 11

SDKErrorFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
ContextFunction · 0.92
RunMethod · 0.65
GetUserStatusCountsMethod · 0.65
LenMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45
StatusCodeMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected