|
5 | 5 | RSpec.describe DiscourseAi::Admin::AiUsageController do |
6 | 6 | fab!(:admin) |
7 | 7 | fab!(:user) |
8 | | - let(:usage_path) { "/admin/plugins/discourse-ai/ai-usage.json" } |
| 8 | + let(:usage_report_path) { "/admin/plugins/discourse-ai/ai-usage-report.json" } |
9 | 9 |
|
10 | 10 | before { SiteSetting.discourse_ai_enabled = true } |
11 | 11 |
|
|
36 | 36 | end |
37 | 37 |
|
38 | 38 | it "returns correct data structure" do |
39 | | - get usage_path |
| 39 | + get usage_report_path |
40 | 40 |
|
41 | 41 | expect(response.status).to eq(200) |
42 | 42 |
|
|
48 | 48 | end |
49 | 49 |
|
50 | 50 | it "respects date filters" do |
51 | | - get usage_path, params: { start_date: 3.days.ago.to_date, end_date: 1.day.ago.to_date } |
| 51 | + get usage_report_path, |
| 52 | + params: { |
| 53 | + start_date: 3.days.ago.to_date, |
| 54 | + end_date: 1.day.ago.to_date, |
| 55 | + } |
52 | 56 |
|
53 | 57 | json = response.parsed_body |
54 | 58 | expect(json["summary"]["total_tokens"]).to eq(450) # sum of all tokens |
55 | 59 | end |
56 | 60 |
|
57 | 61 | it "filters by feature" do |
58 | | - get usage_path, params: { feature: "summarize" } |
| 62 | + get usage_report_path, params: { feature: "summarize" } |
59 | 63 |
|
60 | 64 | json = response.parsed_body |
61 | 65 |
|
|
66 | 70 | end |
67 | 71 |
|
68 | 72 | it "filters by model" do |
69 | | - get usage_path, params: { model: "gpt-3.5" } |
| 73 | + get usage_report_path, params: { model: "gpt-3.5" } |
70 | 74 |
|
71 | 75 | json = response.parsed_body |
72 | 76 | models = json["models"] |
|
76 | 80 | end |
77 | 81 |
|
78 | 82 | it "handles different period groupings" do |
79 | | - get usage_path, params: { period: "hour" } |
| 83 | + get usage_report_path, params: { period: "hour" } |
80 | 84 | expect(response.status).to eq(200) |
81 | 85 |
|
82 | | - get usage_path, params: { period: "month" } |
| 86 | + get usage_report_path, params: { period: "month" } |
83 | 87 | expect(response.status).to eq(200) |
84 | 88 | end |
85 | 89 | end |
|
102 | 106 | end |
103 | 107 |
|
104 | 108 | it "returns hourly data when period is day" do |
105 | | - get usage_path, params: { start_date: 1.day.ago.to_date, end_date: Time.current.to_date } |
| 109 | + get usage_report_path, |
| 110 | + params: { |
| 111 | + start_date: 1.day.ago.to_date, |
| 112 | + end_date: Time.current.to_date, |
| 113 | + } |
106 | 114 |
|
107 | 115 | expect(response.status).to eq(200) |
108 | 116 | json = response.parsed_body |
|
121 | 129 | before { sign_in(user) } |
122 | 130 |
|
123 | 131 | it "blocks access" do |
124 | | - get usage_path |
| 132 | + get usage_report_path |
125 | 133 | expect(response.status).to eq(404) |
126 | 134 | end |
127 | 135 | end |
|
133 | 141 | end |
134 | 142 |
|
135 | 143 | it "returns error" do |
136 | | - get usage_path |
| 144 | + get usage_report_path |
137 | 145 | expect(response.status).to eq(404) |
138 | 146 | end |
139 | 147 | end |
|
0 commit comments