Skip to content

Commit 18a71d3

Browse files
jayjay19630DesSnowyRichDom2185sayomaki
authored
Create hasTokenCounter attribute to assessment_config (#1062)
* Create new attribute to assessment_config * fix bug which cause tokenCounter to default false * Fix format * Modify controller tests --------- Co-authored-by: DesSnowy <[email protected]> Co-authored-by: Richard Dominick <[email protected]> Co-authored-by: sayomaki <[email protected]>
1 parent dba4f95 commit 18a71d3

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

lib/cadet/courses/assessment_config.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ defmodule Cadet.Courses.AssessmentConfig do
1212
field(:type, :string)
1313
field(:show_grading_summary, :boolean, default: true)
1414
field(:is_manually_graded, :boolean, default: true)
15-
# used by fronend to determine display styles
15+
field(:has_token_counter, :boolean, default: false)
16+
# used by frontend to determine display styles
1617
field(:early_submission_xp, :integer, default: 0)
1718
field(:hours_before_early_xp_decay, :integer, default: 0)
1819

@@ -23,7 +24,7 @@ defmodule Cadet.Courses.AssessmentConfig do
2324

2425
@required_fields ~w(course_id)a
2526
@optional_fields ~w(order type early_submission_xp
26-
hours_before_early_xp_decay show_grading_summary is_manually_graded)a
27+
hours_before_early_xp_decay show_grading_summary is_manually_graded has_token_counter)a
2728

2829
def changeset(assessment_config, params) do
2930
assessment_config

lib/cadet_web/admin_views/admin_courses_view.ex

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule CadetWeb.AdminCoursesView do
1212
displayInDashboard: :show_grading_summary,
1313
isManuallyGraded: :is_manually_graded,
1414
earlySubmissionXp: :early_submission_xp,
15+
hasTokenCounter: :has_token_counter,
1516
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
1617
})
1718
end

lib/cadet_web/views/user_view.ex

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ defmodule CadetWeb.UserView do
125125
type: :type,
126126
displayInDashboard: :show_grading_summary,
127127
isManuallyGraded: :is_manually_graded,
128+
hasTokenCounter: :has_token_counter,
128129
earlySubmissionXp: :early_submission_xp,
129130
hoursBeforeEarlyXpDecay: :hours_before_early_xp_decay
130131
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Cadet.Repo.Migrations.AddHasTokenCounterToggleToAssessmentConfig do
2+
use Ecto.Migration
3+
4+
def up do
5+
alter table(:assessment_configs) do
6+
add(:has_token_counter, :boolean, null: false, default: false)
7+
end
8+
end
9+
10+
def down do
11+
alter table(:assessment_configs) do
12+
remove(:has_token_counter)
13+
end
14+
end
15+
end

test/cadet_web/admin_controllers/admin_courses_controller_test.exs

+8-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ defmodule CadetWeb.AdminCoursesControllerTest do
157157
is_manually_graded: false,
158158
order: 2,
159159
type: "Mission2",
160-
course: course
160+
course: course,
161+
has_token_counter: true
161162
})
162163

163164
resp =
@@ -172,23 +173,26 @@ defmodule CadetWeb.AdminCoursesControllerTest do
172173
"displayInDashboard" => true,
173174
"isManuallyGraded" => true,
174175
"type" => "Mission1",
175-
"assessmentConfigId" => config1.id
176+
"assessmentConfigId" => config1.id,
177+
"hasTokenCounter" => false
176178
},
177179
%{
178180
"earlySubmissionXp" => 200,
179181
"hoursBeforeEarlyXpDecay" => 48,
180182
"displayInDashboard" => false,
181183
"isManuallyGraded" => false,
182184
"type" => "Mission2",
183-
"assessmentConfigId" => config2.id
185+
"assessmentConfigId" => config2.id,
186+
"hasTokenCounter" => true
184187
},
185188
%{
186189
"earlySubmissionXp" => 200,
187190
"hoursBeforeEarlyXpDecay" => 48,
188191
"displayInDashboard" => true,
189192
"isManuallyGraded" => true,
190193
"type" => "Mission3",
191-
"assessmentConfigId" => config3.id
194+
"assessmentConfigId" => config3.id,
195+
"hasTokenCounter" => false
192196
}
193197
]
194198

test/cadet_web/controllers/user_controller_test.exs

+6-3
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,26 @@ defmodule CadetWeb.UserControllerTest do
122122
"isManuallyGraded" => true,
123123
"assessmentConfigId" => config1.id,
124124
"earlySubmissionXp" => 200,
125-
"hoursBeforeEarlyXpDecay" => 48
125+
"hoursBeforeEarlyXpDecay" => 48,
126+
"hasTokenCounter" => false
126127
},
127128
%{
128129
"type" => "test type 2",
129130
"displayInDashboard" => true,
130131
"isManuallyGraded" => true,
131132
"assessmentConfigId" => config2.id,
132133
"earlySubmissionXp" => 200,
133-
"hoursBeforeEarlyXpDecay" => 48
134+
"hoursBeforeEarlyXpDecay" => 48,
135+
"hasTokenCounter" => false
134136
},
135137
%{
136138
"type" => "test type 3",
137139
"displayInDashboard" => true,
138140
"isManuallyGraded" => true,
139141
"assessmentConfigId" => config3.id,
140142
"earlySubmissionXp" => 200,
141-
"hoursBeforeEarlyXpDecay" => 48
143+
"hoursBeforeEarlyXpDecay" => 48,
144+
"hasTokenCounter" => false
142145
}
143146
]
144147
}

0 commit comments

Comments
 (0)