Skip to content

Commit d33859e

Browse files
authored
Merge pull request #450 from navikt/TOLK-3314
TOLK-3314 : NumberOfParticipants__c speiler ikke det faktisk antall deltakere som er påmeldt
2 parents 6f178cb + 7c64fbc commit d33859e

30 files changed

Lines changed: 499 additions & 508 deletions

force-app/main/default/classes/CourseHandler.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ global with sharing class CourseHandler {
2020
Theme__c,
2121
AvailableSeats__c,
2222
MaxNumberOfParticipants__c,
23-
NumberOfParticipants__c,
23+
RegistrationSignupsCount__c,
2424
PublishWithoutRegistrationForm__c
2525
FROM Course__c
2626
WHERE Active__c = TRUE
@@ -45,7 +45,7 @@ global with sharing class CourseHandler {
4545
wrapper.ShowInActivityList = course.Active__c ? 1 : 0;
4646
wrapper.AvailableSeats = course.AvailableSeats__c;
4747
wrapper.MaxNumberOfParticipants = course.MaxNumberOfParticipants__c;
48-
wrapper.NumberOfParticipants = course.NumberOfParticipants__c;
48+
wrapper.NumberOfParticipants = course.RegistrationSignupsCount__c;
4949
wrapper.PublishWithoutRegistrationForm = course.PublishWithoutRegistrationForm__c;
5050

5151
wrapper.configurable_custom = new CourseApiModel.Configurable_custom();

force-app/main/default/classes/CourseRegistrationController.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public without sharing class CourseRegistrationController {
6363
Course__c = courseId
6464
);
6565

66-
Decimal current = (course.NumberOfParticipants__c != null) ? course.NumberOfParticipants__c : 0;
66+
Decimal current = (course.RegistrationSignupsCount__c != null) ? course.RegistrationSignupsCount__c : 0;
6767
Decimal maxCap = (course.MaxNumberOfParticipants__c != null) ? course.MaxNumberOfParticipants__c : 0;
6868
Decimal avail = maxCap - current;
6969

@@ -126,8 +126,8 @@ public without sharing class CourseRegistrationController {
126126
RegistrationPlaceName__c,
127127
Type__c,
128128
MaxNumberOfParticipants__c,
129-
NumberOfParticipants__c,
130-
Waitinglist__c,
129+
RegistrationSignupsCount__c,
130+
RegistrationWaitlistedCount__c,
131131
ShowCompany__c,
132132
ShowCounty__c,
133133
ShowRole__c,
@@ -170,7 +170,7 @@ public without sharing class CourseRegistrationController {
170170
}
171171
try {
172172
Course__c course = [
173-
SELECT Name, NumberOfParticipants__c, MaxNumberOfParticipants__c, Cancel__c
173+
SELECT Name, RegistrationSignupsCount__c, MaxNumberOfParticipants__c, Cancel__c
174174
FROM Course__c
175175
WHERE Id = :courseId
176176
LIMIT 1

force-app/main/default/classes/CourseRegistrationControllerTest.cls

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,19 @@ private with sharing class CourseRegistrationControllerTest {
125125

126126
@isTest
127127
static void testWaitlistLogic() {
128-
Course__c c = new Course__c(Name = 'Full', MaxNumberOfParticipants__c = 1, NumberOfParticipants__c = 1);
128+
Course__c c = new Course__c(Name = 'Full', MaxNumberOfParticipants__c = 1);
129129
insert c;
130130

131+
CourseRegistration__c existing = new CourseRegistration__c(
132+
ContactFirstName__c = 'Existing',
133+
ContactLastName__c = 'Attendee',
134+
ContactEmail__c = 'existing@nav.no',
135+
Course__c = c.Id,
136+
Status__c = 'Påmeldt',
137+
NumberOfParticipants__c = 1
138+
);
139+
insert existing;
140+
131141
CourseRegistrationModel mw = new CourseRegistrationModel();
132142
mw.firstName = 'M';
133143
mw.lastName = 'W';
@@ -160,22 +170,31 @@ private with sharing class CourseRegistrationControllerTest {
160170
RegistrationToDateTime__c = toDT,
161171
Type__c = 'Kurs',
162172
MaxNumberOfParticipants__c = 50,
163-
Waitinglist__c = 1,
164173
ShowCompany__c = true,
165174
ShowCounty__c = true,
166175
ShowRole__c = true,
167176
Cancel__c = false
168177
);
169178
insert c;
170179

180+
CourseRegistration__c waitlisted = new CourseRegistration__c(
181+
ContactFirstName__c = 'Wait',
182+
ContactLastName__c = 'List',
183+
ContactEmail__c = 'wait@nav.no',
184+
Course__c = c.Id,
185+
Status__c = 'Venteliste',
186+
NumberOfParticipants__c = 1
187+
);
188+
insert waitlisted;
189+
171190
Course__c f = CourseRegistrationController.getCourseFields(c.Id);
172191
System.assertEquals(c.Name, f.Name);
173192
System.assertEquals(c.Type__c, f.Type__c);
174193
System.assertEquals(c.MaxNumberOfParticipants__c, f.MaxNumberOfParticipants__c);
175194
System.assertEquals(c.RegistrationDeadline__c, f.RegistrationDeadline__c);
176195
System.assertEquals(c.RegistrationFromDateTime__c, f.RegistrationFromDateTime__c);
177196
System.assertEquals(c.RegistrationToDateTime__c, f.RegistrationToDateTime__c);
178-
System.assertEquals(c.Waitinglist__c, f.Waitinglist__c);
197+
System.assertEquals(1, Integer.valueOf(f.RegistrationWaitlistedCount__c));
179198
}
180199

181200
@IsTest
@@ -202,4 +221,4 @@ private with sharing class CourseRegistrationControllerTest {
202221

203222
System.assertEquals(0, accounts.size(), 'No accounts should be returned when the organization number is not found');
204223
}
205-
}
224+
}

force-app/main/default/classes/CourseRegistrationControllerTest.cls-meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
33
<apiVersion>48.0</apiVersion>
44
<status>Active</status>

force-app/main/default/classes/CourseRegistrationHandler.cls

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ global class CourseRegistrationHandler extends MyTriggers {
3030

3131
global override void onAfterDelete() {
3232
List<CourseRegistration__c> deletedRegistrations = (List<CourseRegistration__c>) records;
33-
if (deletedRegistrations != null && !deletedRegistrations.isEmpty()) {
34-
CourseRegistrationHelper.getCourseIdToReduce(deletedRegistrations);
35-
}
3633
Set<Id> courseIdsToCheckForPromotion = new Set<Id>();
3734
if (deletedRegistrations != null) {
3835
for (CourseRegistration__c reg : deletedRegistrations) {
@@ -46,10 +43,8 @@ global class CourseRegistrationHandler extends MyTriggers {
4643
}
4744
}
4845
global override void onAfterUndelete() {
49-
CourseRegistrationHelper.getCourseIdToIncrease((List<CourseRegistration__c>) records);
5046
}
5147
global override void onAfterInsert() {
52-
CourseRegistrationHelper.getCourseIdToIncrease((List<CourseRegistration__c>) records);
5348
}
5449

5550
global override void onAfterUpdate(Map<Id, sObject> triggerOldMap) {

force-app/main/default/classes/CourseRegistrationHandlerTest.cls

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ public with sharing class CourseRegistrationHandlerTest {
1010
Course__c course1 = getCourse('Testkurs');
1111
Course__c course2 = getCourse('Testkurs2');
1212

13-
System.assertEquals(null, course1.NumberOfParticipants__c, 'Should be 0 participants');
14-
System.assertEquals(null, course2.NumberOfParticipants__c, 'Should be 0 participants');
13+
System.assertEquals(
14+
0,
15+
course1.RegistrationSignupsCount__c == null
16+
? 0
17+
: course1.RegistrationSignupsCount__c.intValue(),
18+
'Should be 0 participants'
19+
);
20+
System.assertEquals(
21+
0,
22+
course2.RegistrationSignupsCount__c == null
23+
? 0
24+
: course2.RegistrationSignupsCount__c.intValue(),
25+
'Should be 0 participants'
26+
);
1527

1628
Test.StartTest();
1729
CourseRegistration__c cr = getCourseRegistration('Påmeldt', course1.Id);
@@ -22,9 +34,9 @@ public with sharing class CourseRegistrationHandlerTest {
2234
Course__c course1After = fetchCourse('Testkurs');
2335
Course__c course2After = fetchCourse('Testkurs2');
2436

25-
System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
26-
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
27-
System.assertEquals(1, Integer.valueOf(course2After.WaitingList__c), 'Should be 1 on waitinglist');
37+
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
38+
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
39+
System.assertEquals(1, Integer.valueOf(course2After.RegistrationWaitlistedCount__c), 'Should be 1 on waitinglist');
2840
}
2941
@isTest
3042
private static void testDelete() {
@@ -43,7 +55,7 @@ public with sharing class CourseRegistrationHandlerTest {
4355
System.assertEquals(0, crListDel.size(), 'Should be 0 registrations');
4456

4557
Course__c courseAfter = fetchCourse('Testkurs');
46-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
58+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
4759
}
4860
@isTest
4961
private static void testUnDelete() {
@@ -63,7 +75,7 @@ public with sharing class CourseRegistrationHandlerTest {
6375
System.assertEquals(2, crListUnDel.size(), 'Should be 2 registrations');
6476

6577
Course__c courseAfter = fetchCourse('Testkurs');
66-
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
78+
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
6779
}
6880

6981
@isTest
@@ -77,7 +89,7 @@ public with sharing class CourseRegistrationHandlerTest {
7789
Test.StopTest();
7890

7991
Course__c courseAfter = fetchCourse('Testkurs');
80-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
92+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
8193
}
8294

8395
@isTest
@@ -91,7 +103,7 @@ public with sharing class CourseRegistrationHandlerTest {
91103
Test.StopTest();
92104

93105
Course__c courseAfter = fetchCourse('Testkurs');
94-
System.assertEquals(1, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 1 participant');
106+
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 1 participant');
95107
}
96108

97109
@isTest
@@ -105,8 +117,8 @@ public with sharing class CourseRegistrationHandlerTest {
105117
Test.StopTest();
106118

107119
Course__c courseAfter = fetchCourse('Testkurs');
108-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
109-
System.assertEquals(1, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 1 on waiting list');
120+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
121+
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 1 on waiting list');
110122
}
111123

112124
@isTest
@@ -120,8 +132,8 @@ public with sharing class CourseRegistrationHandlerTest {
120132
Test.StopTest();
121133

122134
Course__c courseAfter = fetchCourse('Testkurs');
123-
System.assertEquals(1, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 1 participant');
124-
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
135+
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 1 participant');
136+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
125137
}
126138
@isTest
127139
private static void updateOneWaiting_toOneNotAttending() {
@@ -134,8 +146,8 @@ public with sharing class CourseRegistrationHandlerTest {
134146
Test.StopTest();
135147

136148
Course__c courseAfter = fetchCourse('Testkurs');
137-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
138-
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
149+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
150+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
139151
}
140152

141153
@isTest
@@ -151,7 +163,7 @@ public with sharing class CourseRegistrationHandlerTest {
151163
Test.StopTest();
152164

153165
Course__c courseAfter = fetchCourse('Testkurs');
154-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
166+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
155167
}
156168

157169
@isTest
@@ -167,7 +179,7 @@ public with sharing class CourseRegistrationHandlerTest {
167179
Test.StopTest();
168180

169181
Course__c courseAfter = fetchCourse('Testkurs');
170-
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
182+
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
171183
}
172184

173185
@isTest
@@ -183,8 +195,8 @@ public with sharing class CourseRegistrationHandlerTest {
183195
Test.StopTest();
184196

185197
Course__c courseAfter = fetchCourse('Testkurs');
186-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
187-
System.assertEquals(2, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 2 on waiting list');
198+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
199+
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 2 on waiting list');
188200
}
189201

190202
@isTest
@@ -200,8 +212,8 @@ public with sharing class CourseRegistrationHandlerTest {
200212
Test.StopTest();
201213

202214
Course__c courseAfter = fetchCourse('Testkurs');
203-
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
204-
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
215+
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
216+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
205217
}
206218

207219
@isTest
@@ -217,8 +229,8 @@ public with sharing class CourseRegistrationHandlerTest {
217229
Test.StopTest();
218230

219231
Course__c courseAfter = fetchCourse('Testkurs');
220-
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
221-
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
232+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
233+
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
222234
}
223235

224236
@isTest
@@ -236,8 +248,8 @@ public with sharing class CourseRegistrationHandlerTest {
236248

237249
Course__c course1After = fetchCourse('Testkurs');
238250
Course__c course2After = fetchCourse('Testkurs2');
239-
System.assertEquals(0, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 0 participants');
240-
System.assertEquals(0, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 0 participants');
251+
System.assertEquals(0, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 0 participants');
252+
System.assertEquals(0, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 0 participants');
241253
}
242254

243255
@isTest
@@ -255,8 +267,8 @@ public with sharing class CourseRegistrationHandlerTest {
255267

256268
Course__c course1After = fetchCourse('Testkurs');
257269
Course__c course2After = fetchCourse('Testkurs2');
258-
System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
259-
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
270+
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
271+
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
260272
}
261273

262274
@isTest
@@ -280,15 +292,15 @@ public with sharing class CourseRegistrationHandlerTest {
280292
Course__c course2After = fetchCourse('Testkurs2');
281293
String cr2IdStatus = [SELECT Id, Status__c FROM CourseRegistration__c WHERE Id = :cr2.Id LIMIT 1].Status__c;
282294
String cr4IdStatus = [SELECT Id, Status__c FROM CourseRegistration__c WHERE Id = :cr4.Id LIMIT 1].Status__c;
283-
System.debug('1 after >>' + course1After.NumberOfParticipants__c);
284-
System.debug('c after >>' + course2After.NumberOfParticipants__c);
295+
System.debug('1 after >>' + course1After.RegistrationSignupsCount__c);
296+
System.debug('c after >>' + course2After.RegistrationSignupsCount__c);
285297
System.debug('c after >>' + cr2IdStatus);
286298
System.debug('c after >>' + cr4IdStatus);
287299

288-
System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
289-
System.assertEquals(0, Integer.valueOf(course1After.WaitingList__c), 'Should be 0 on waiting list');
290-
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
291-
System.assertEquals(1, Integer.valueOf(course2After.WaitingList__c), 'Should be 1 on waiting list');
300+
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
301+
System.assertEquals(0, Integer.valueOf(course1After.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
302+
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
303+
System.assertEquals(1, Integer.valueOf(course2After.RegistrationWaitlistedCount__c), 'Should be 1 on waiting list');
292304
System.assertEquals('Påmeldt', cr2IdStatus, 'cr2 should have Påmeldt status');
293305
System.assertEquals('Påmeldt', cr4IdStatus, 'cr4 should have Påmeldt status');
294306
}
@@ -300,7 +312,8 @@ public with sharing class CourseRegistrationHandlerTest {
300312
ContactPhone__c = '99887766',
301313
ContactEmail__c = 'per.hansen@test.no',
302314
Course__c = courseId,
303-
Status__c = status
315+
Status__c = status,
316+
NumberOfParticipants__c = 1
304317
);
305318
insert cr;
306319
return cr;
@@ -329,11 +342,11 @@ public with sharing class CourseRegistrationHandlerTest {
329342

330343
public static Course__c fetchCourse(String courseName) {
331344
Course__c course = [
332-
SELECT Id, NumberOfParticipants__c, WaitingList__c
345+
SELECT Id, RegistrationSignupsCount__c, RegistrationWaitlistedCount__c
333346
FROM Course__c
334347
WHERE Name = :courseName
335348
LIMIT 1
336349
];
337350
return course;
338351
}
339-
}
352+
}

0 commit comments

Comments
 (0)