(t *testing.T)
| 2161 | } |
| 2162 | |
| 2163 | func TestTemplateInsights_RBAC(t *testing.T) { |
| 2164 | t.Parallel() |
| 2165 | |
| 2166 | y, m, d := time.Now().UTC().Date() |
| 2167 | today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC) |
| 2168 | |
| 2169 | type test struct { |
| 2170 | interval codersdk.InsightsReportInterval |
| 2171 | withTemplate bool |
| 2172 | } |
| 2173 | |
| 2174 | tests := []test{ |
| 2175 | {codersdk.InsightsReportIntervalDay, true}, |
| 2176 | {codersdk.InsightsReportIntervalDay, false}, |
| 2177 | {"", true}, |
| 2178 | {"", false}, |
| 2179 | } |
| 2180 | |
| 2181 | for _, tt := range tests { |
| 2182 | t.Run(fmt.Sprintf("with interval=%q", tt.interval), func(t *testing.T) { |
| 2183 | t.Parallel() |
| 2184 | |
| 2185 | t.Run("AsOwner", func(t *testing.T) { |
| 2186 | t.Parallel() |
| 2187 | |
| 2188 | client := coderdtest.New(t, nil) |
| 2189 | owner := coderdtest.CreateFirstUser(t, client) |
| 2190 | |
| 2191 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 2192 | defer cancel() |
| 2193 | |
| 2194 | var templateIDs []uuid.UUID |
| 2195 | if tt.withTemplate { |
| 2196 | version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) |
| 2197 | template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID) |
| 2198 | templateIDs = append(templateIDs, template.ID) |
| 2199 | } |
| 2200 | |
| 2201 | _, err := client.TemplateInsights(ctx, codersdk.TemplateInsightsRequest{ |
| 2202 | StartTime: today.AddDate(0, 0, -1), |
| 2203 | EndTime: today, |
| 2204 | Interval: tt.interval, |
| 2205 | TemplateIDs: templateIDs, |
| 2206 | }) |
| 2207 | require.NoError(t, err) |
| 2208 | }) |
| 2209 | t.Run("AsTemplateAdmin", func(t *testing.T) { |
| 2210 | t.Parallel() |
| 2211 | |
| 2212 | client := coderdtest.New(t, nil) |
| 2213 | owner := coderdtest.CreateFirstUser(t, client) |
| 2214 | |
| 2215 | templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 2216 | |
| 2217 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 2218 | defer cancel() |
| 2219 | |
| 2220 | var templateIDs []uuid.UUID |
nothing calls this directly
no test coverage detected