Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions force-app/main/default/classes/CourseHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ global with sharing class CourseHandler {
Theme__c,
AvailableSeats__c,
MaxNumberOfParticipants__c,
NumberOfParticipants__c,
RegistrationSignupsCount__c,
PublishWithoutRegistrationForm__c
FROM Course__c
WHERE Active__c = TRUE
Expand All @@ -45,7 +45,7 @@ global with sharing class CourseHandler {
wrapper.ShowInActivityList = course.Active__c ? 1 : 0;
wrapper.AvailableSeats = course.AvailableSeats__c;
wrapper.MaxNumberOfParticipants = course.MaxNumberOfParticipants__c;
wrapper.NumberOfParticipants = course.NumberOfParticipants__c;
wrapper.NumberOfParticipants = course.RegistrationSignupsCount__c;
wrapper.PublishWithoutRegistrationForm = course.PublishWithoutRegistrationForm__c;

wrapper.configurable_custom = new CourseApiModel.Configurable_custom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public without sharing class CourseRegistrationController {
Course__c = courseId
);

Decimal current = (course.NumberOfParticipants__c != null) ? course.NumberOfParticipants__c : 0;
Decimal current = (course.RegistrationSignupsCount__c != null) ? course.RegistrationSignupsCount__c : 0;
Decimal maxCap = (course.MaxNumberOfParticipants__c != null) ? course.MaxNumberOfParticipants__c : 0;
Decimal avail = maxCap - current;

Expand Down Expand Up @@ -126,8 +126,8 @@ public without sharing class CourseRegistrationController {
RegistrationPlaceName__c,
Type__c,
MaxNumberOfParticipants__c,
NumberOfParticipants__c,
Waitinglist__c,
RegistrationSignupsCount__c,
RegistrationWaitlistedCount__c,
ShowCompany__c,
ShowCounty__c,
ShowRole__c,
Expand Down Expand Up @@ -170,7 +170,7 @@ public without sharing class CourseRegistrationController {
}
try {
Course__c course = [
SELECT Name, NumberOfParticipants__c, MaxNumberOfParticipants__c, Cancel__c
SELECT Name, RegistrationSignupsCount__c, MaxNumberOfParticipants__c, Cancel__c
FROM Course__c
WHERE Id = :courseId
LIMIT 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,19 @@ private with sharing class CourseRegistrationControllerTest {

@isTest
static void testWaitlistLogic() {
Course__c c = new Course__c(Name = 'Full', MaxNumberOfParticipants__c = 1, NumberOfParticipants__c = 1);
Course__c c = new Course__c(Name = 'Full', MaxNumberOfParticipants__c = 1);
insert c;

CourseRegistration__c existing = new CourseRegistration__c(
ContactFirstName__c = 'Existing',
ContactLastName__c = 'Attendee',
ContactEmail__c = 'existing@nav.no',
Course__c = c.Id,
Status__c = 'Påmeldt',
NumberOfParticipants__c = 1
);
insert existing;

CourseRegistrationModel mw = new CourseRegistrationModel();
mw.firstName = 'M';
mw.lastName = 'W';
Expand Down Expand Up @@ -160,22 +170,31 @@ private with sharing class CourseRegistrationControllerTest {
RegistrationToDateTime__c = toDT,
Type__c = 'Kurs',
MaxNumberOfParticipants__c = 50,
Waitinglist__c = 1,
ShowCompany__c = true,
ShowCounty__c = true,
ShowRole__c = true,
Cancel__c = false
);
insert c;

CourseRegistration__c waitlisted = new CourseRegistration__c(
ContactFirstName__c = 'Wait',
ContactLastName__c = 'List',
ContactEmail__c = 'wait@nav.no',
Course__c = c.Id,
Status__c = 'Venteliste',
NumberOfParticipants__c = 1
);
insert waitlisted;

Course__c f = CourseRegistrationController.getCourseFields(c.Id);
System.assertEquals(c.Name, f.Name);
System.assertEquals(c.Type__c, f.Type__c);
System.assertEquals(c.MaxNumberOfParticipants__c, f.MaxNumberOfParticipants__c);
System.assertEquals(c.RegistrationDeadline__c, f.RegistrationDeadline__c);
System.assertEquals(c.RegistrationFromDateTime__c, f.RegistrationFromDateTime__c);
System.assertEquals(c.RegistrationToDateTime__c, f.RegistrationToDateTime__c);
System.assertEquals(c.Waitinglist__c, f.Waitinglist__c);
System.assertEquals(1, Integer.valueOf(f.RegistrationWaitlistedCount__c));
}

@IsTest
Expand All @@ -202,4 +221,4 @@ private with sharing class CourseRegistrationControllerTest {

System.assertEquals(0, accounts.size(), 'No accounts should be returned when the organization number is not found');
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<status>Active</status>
Expand Down
5 changes: 0 additions & 5 deletions force-app/main/default/classes/CourseRegistrationHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ global class CourseRegistrationHandler extends MyTriggers {

global override void onAfterDelete() {
List<CourseRegistration__c> deletedRegistrations = (List<CourseRegistration__c>) records;
if (deletedRegistrations != null && !deletedRegistrations.isEmpty()) {
CourseRegistrationHelper.getCourseIdToReduce(deletedRegistrations);
}
Set<Id> courseIdsToCheckForPromotion = new Set<Id>();
if (deletedRegistrations != null) {
for (CourseRegistration__c reg : deletedRegistrations) {
Expand All @@ -46,10 +43,8 @@ global class CourseRegistrationHandler extends MyTriggers {
}
}
global override void onAfterUndelete() {
CourseRegistrationHelper.getCourseIdToIncrease((List<CourseRegistration__c>) records);
}
global override void onAfterInsert() {
CourseRegistrationHelper.getCourseIdToIncrease((List<CourseRegistration__c>) records);
}

global override void onAfterUpdate(Map<Id, sObject> triggerOldMap) {
Expand Down
85 changes: 49 additions & 36 deletions force-app/main/default/classes/CourseRegistrationHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ public with sharing class CourseRegistrationHandlerTest {
Course__c course1 = getCourse('Testkurs');
Course__c course2 = getCourse('Testkurs2');

System.assertEquals(null, course1.NumberOfParticipants__c, 'Should be 0 participants');
System.assertEquals(null, course2.NumberOfParticipants__c, 'Should be 0 participants');
System.assertEquals(
0,
course1.RegistrationSignupsCount__c == null
? 0
: course1.RegistrationSignupsCount__c.intValue(),
'Should be 0 participants'
);
System.assertEquals(
0,
course2.RegistrationSignupsCount__c == null
? 0
: course2.RegistrationSignupsCount__c.intValue(),
'Should be 0 participants'
);

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

System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.WaitingList__c), 'Should be 1 on waitinglist');
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.RegistrationWaitlistedCount__c), 'Should be 1 on waitinglist');
}
@isTest
private static void testDelete() {
Expand All @@ -43,7 +55,7 @@ public with sharing class CourseRegistrationHandlerTest {
System.assertEquals(0, crListDel.size(), 'Should be 0 registrations');

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(1, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 1 participant');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(1, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 1 on waiting list');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 1 on waiting list');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(1, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
System.assertEquals(1, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
}
@isTest
private static void updateOneWaiting_toOneNotAttending() {
Expand All @@ -134,8 +146,8 @@ public with sharing class CourseRegistrationHandlerTest {
Test.StopTest();

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(2, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 2 on waiting list');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 2 on waiting list');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(2, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 2 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
System.assertEquals(2, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 2 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
}

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

Course__c courseAfter = fetchCourse('Testkurs');
System.assertEquals(0, Integer.valueOf(courseAfter.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.WaitingList__c), 'Should be 0 on waiting list');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationSignupsCount__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(courseAfter.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
}

@isTest
Expand All @@ -236,8 +248,8 @@ public with sharing class CourseRegistrationHandlerTest {

Course__c course1After = fetchCourse('Testkurs');
Course__c course2After = fetchCourse('Testkurs2');
System.assertEquals(0, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 0 participants');
System.assertEquals(0, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 0 participants');
}

@isTest
Expand All @@ -255,8 +267,8 @@ public with sharing class CourseRegistrationHandlerTest {

Course__c course1After = fetchCourse('Testkurs');
Course__c course2After = fetchCourse('Testkurs2');
System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
}

@isTest
Expand All @@ -280,15 +292,15 @@ public with sharing class CourseRegistrationHandlerTest {
Course__c course2After = fetchCourse('Testkurs2');
String cr2IdStatus = [SELECT Id, Status__c FROM CourseRegistration__c WHERE Id = :cr2.Id LIMIT 1].Status__c;
String cr4IdStatus = [SELECT Id, Status__c FROM CourseRegistration__c WHERE Id = :cr4.Id LIMIT 1].Status__c;
System.debug('1 after >>' + course1After.NumberOfParticipants__c);
System.debug('c after >>' + course2After.NumberOfParticipants__c);
System.debug('1 after >>' + course1After.RegistrationSignupsCount__c);
System.debug('c after >>' + course2After.RegistrationSignupsCount__c);
System.debug('c after >>' + cr2IdStatus);
System.debug('c after >>' + cr4IdStatus);

System.assertEquals(1, Integer.valueOf(course1After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(0, Integer.valueOf(course1After.WaitingList__c), 'Should be 0 on waiting list');
System.assertEquals(1, Integer.valueOf(course2After.NumberOfParticipants__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.WaitingList__c), 'Should be 1 on waiting list');
System.assertEquals(1, Integer.valueOf(course1After.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(0, Integer.valueOf(course1After.RegistrationWaitlistedCount__c), 'Should be 0 on waiting list');
System.assertEquals(1, Integer.valueOf(course2After.RegistrationSignupsCount__c), 'Should be 1 participant');
System.assertEquals(1, Integer.valueOf(course2After.RegistrationWaitlistedCount__c), 'Should be 1 on waiting list');
System.assertEquals('Påmeldt', cr2IdStatus, 'cr2 should have Påmeldt status');
System.assertEquals('Påmeldt', cr4IdStatus, 'cr4 should have Påmeldt status');
}
Expand All @@ -300,7 +312,8 @@ public with sharing class CourseRegistrationHandlerTest {
ContactPhone__c = '99887766',
ContactEmail__c = 'per.hansen@test.no',
Course__c = courseId,
Status__c = status
Status__c = status,
NumberOfParticipants__c = 1
);
insert cr;
return cr;
Expand Down Expand Up @@ -329,11 +342,11 @@ public with sharing class CourseRegistrationHandlerTest {

public static Course__c fetchCourse(String courseName) {
Course__c course = [
SELECT Id, NumberOfParticipants__c, WaitingList__c
SELECT Id, RegistrationSignupsCount__c, RegistrationWaitlistedCount__c
FROM Course__c
WHERE Name = :courseName
LIMIT 1
];
return course;
}
}
}
Loading