Skip to content
Open
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
9 changes: 8 additions & 1 deletion force-app/main/default/classes/Contact_Create.cls
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ global class Contact_Create extends MyTriggers {
cr.EncryptedId__c = EncodingUtil.urlEncode(CryptoService.encryptString(cr.Id), 'UTF-8');
recordsToUpdate.add(cr);
}
update recordsToUpdate;
try {
update recordsToUpdate;
} catch (Exception e) {
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ public without sharing class CourseEmailSubscribeHandler extends MyTriggers {
record.EncryptedId__c = EncodingUtil.urlEncode(CryptoService.encryptString(record.Id), 'UTF-8');
recordsToUpdate.add(record);
}
update recordsToUpdate;
try {
update recordsToUpdate;
} catch (Exception e) {
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
throw e;
}
}
}
107 changes: 57 additions & 50 deletions force-app/main/default/classes/CourseHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,71 @@
global with sharing class CourseHandler {
@HttpGet
global static void doGet() {
List<Course__c> courses = [
SELECT
Id,
Name,
RegistrationUrl2__c,
RegistrationFromDateTime__c,
RegistrationToDateTime__c,
RegistrationDeadline__c,
RegistrationPlaceName__c,
DescriptionFormatted__c,
DescriptionShort2__c,
Active__c,
Region2__c,
Type__c,
Sub_category__c,
Theme__c,
AvailableSeats__c,
MaxNumberOfParticipants__c,
RegistrationSignupsCount__c,
PublishWithoutRegistrationForm__c
FROM Course__c
WHERE Active__c = TRUE
];
try {
List<Course__c> courses = [
SELECT
Id,
Name,
RegistrationUrl2__c,
RegistrationFromDateTime__c,
RegistrationToDateTime__c,
RegistrationDeadline__c,
RegistrationPlaceName__c,
DescriptionFormatted__c,
DescriptionShort2__c,
Active__c,
Region2__c,
Type__c,
Sub_category__c,
Theme__c,
AvailableSeats__c,
MaxNumberOfParticipants__c,
RegistrationSignupsCount__c,
PublishWithoutRegistrationForm__c
FROM Course__c
WHERE Active__c = TRUE
];

List<CourseApiModel> wrapperList = new List<CourseApiModel>();
List<CourseApiModel> wrapperList = new List<CourseApiModel>();

for (Course__c course : courses) {
CourseApiModel wrapper = new CourseApiModel();
for (Course__c course : courses) {
CourseApiModel wrapper = new CourseApiModel();

wrapper.RegistrationID = course.Id;
wrapper.Title = course.Name;
wrapper.RegistrationUrl = course.RegistrationUrl2__c;
wrapper.RegistrationID = course.Id;
wrapper.Title = course.Name;
wrapper.RegistrationUrl = course.RegistrationUrl2__c;

wrapper.RegistrationFromDateTime = toOsloTimeZone(course.RegistrationFromDateTime__c);
wrapper.RegistrationToDateTime = toOsloTimeZone(course.RegistrationToDateTime__c);
wrapper.RegistrationDeadline = toOsloTimeZone(course.RegistrationDeadline__c);
// --------------------------------------------- //
wrapper.RegistrationPlaceName = course.RegistrationPlaceName__c;
wrapper.FrontPageDescription = course.DescriptionFormatted__c;
wrapper.Description = course.DescriptionShort2__c;
wrapper.ShowInActivityList = course.Active__c ? 1 : 0;
wrapper.AvailableSeats = course.AvailableSeats__c;
wrapper.MaxNumberOfParticipants = course.MaxNumberOfParticipants__c;
wrapper.NumberOfParticipants = course.RegistrationSignupsCount__c;
wrapper.PublishWithoutRegistrationForm = course.PublishWithoutRegistrationForm__c;
wrapper.RegistrationFromDateTime = toOsloTimeZone(course.RegistrationFromDateTime__c);
wrapper.RegistrationToDateTime = toOsloTimeZone(course.RegistrationToDateTime__c);
wrapper.RegistrationDeadline = toOsloTimeZone(course.RegistrationDeadline__c);
// --------------------------------------------- //
wrapper.RegistrationPlaceName = course.RegistrationPlaceName__c;
wrapper.FrontPageDescription = course.DescriptionFormatted__c;
wrapper.Description = course.DescriptionShort2__c;
wrapper.ShowInActivityList = course.Active__c ? 1 : 0;
wrapper.AvailableSeats = course.AvailableSeats__c;
wrapper.MaxNumberOfParticipants = course.MaxNumberOfParticipants__c;
wrapper.NumberOfParticipants = course.RegistrationSignupsCount__c;
wrapper.PublishWithoutRegistrationForm = course.PublishWithoutRegistrationForm__c;

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

wrapper.configurable_custom.Fylke = course.Region2__c;
wrapper.configurable_custom.Type = course.Type__c;
wrapper.configurable_custom.Tema = course.Theme__c;
wrapper.configurable_custom.Underkategori = course.Sub_category__c;
wrapper.configurable_custom.Fylke = course.Region2__c;
wrapper.configurable_custom.Type = course.Type__c;
wrapper.configurable_custom.Tema = course.Theme__c;
wrapper.configurable_custom.Underkategori = course.Sub_category__c;

wrapperList.add(wrapper);
}
wrapperList.add(wrapper);
}

RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(wrapperList));
RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(wrapperList));
} catch (Exception e) {
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
throw e;
}
}

private static Datetime toOsloTimeZone(Datetime local) {
Expand Down
30 changes: 30 additions & 0 deletions force-app/main/default/classes/CourseHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,34 @@ private with sharing class CourseHandlerTest {
System.assert(result.contains('Testkurs'));
System.assert(result.contains('1'));
}

@isTest
private static void testCourseHandlerThrowsForCourseWithoutDates() {
insert new Course__c(
Name = 'Broken course',
DescriptionFormatted__c = 'Missing dates',
DescriptionShort__c = 'Missing dates',
Region2__c = 'Oslo',
Active__c = true,
MaxNumberOfParticipants__c = 10
);

RestRequest req = new RestRequest();
RestResponse res = new RestResponse();

req.requestURI = '/services/apexrest/Course';
req.httpMethod = 'GET';

RestContext.request = req;
RestContext.response = res;

Test.startTest();
try {
CourseHandler.doGet();
System.assert(false, 'Expected missing registration dates to throw');
} catch (Exception e) {
System.assertNotEquals(null, e, 'Expected exception to be rethrown');
}
Test.stopTest();
}
}
56 changes: 56 additions & 0 deletions force-app/main/default/classes/CourseLoggingCatchTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@isTest
private with sharing class CourseLoggingCatchTest {
@TestSetup
static void setupData() {
TestDataFactory.insertEncryptionKey();
}

@isTest
static void testContactCreateAddEncryptedStringThrowsForDeletedRegistration() {
Course__c course = new Course__c(
Name = 'Catch test course',
MaxNumberOfParticipants__c = 10,
DescriptionFormatted__c = 'Test course',
Active__c = true
);
insert course;

CourseRegistration__c registration = new CourseRegistration__c(
ContactFirstName__c = 'Catch',
ContactLastName__c = 'Test',
ContactEmail__c = 'catch.test@nav.no',
Course__c = course.Id,
Status__c = 'Påmeldt'
);
insert registration;
delete registration;

Test.startTest();
try {
Contact_Create.addEncryptedString(new List<CourseRegistration__c>{ registration });
System.assert(false, 'Expected update on deleted registration to throw');
} catch (Exception e) {
System.assertNotEquals(null, e, 'Expected exception to be rethrown');
}
Test.stopTest();
}

@isTest
static void testCourseEmailSubscribeHandlerThrowsForDeletedSubscriber() {
HOT_CourseSubscriber__c subscriber = new HOT_CourseSubscriber__c(
Email__c = 'deleted.subscriber@test.no',
SubCategories__c = 'Syn'
);
insert subscriber;
delete subscriber;

Test.startTest();
try {
CourseEmailSubscribeHandler.addEncryptedString(new List<HOT_CourseSubscriber__c>{ subscriber });
System.assert(false, 'Expected update on deleted subscriber to throw');
} catch (Exception e) {
System.assertNotEquals(null, e, 'Expected exception to be rethrown');
}
Test.stopTest();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public without sharing class CourseRegistrationController {
result.message = e.getMessage();
return result;
}
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
result.message = 'En uventet feil oppstod under registrering. Feilmelding: ' + e.getMessage();
return result;
}
Expand Down Expand Up @@ -177,6 +180,9 @@ public without sharing class CourseRegistrationController {
];
return course;
} catch (Exception e) {
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ private with sharing class CourseRegistrationControllerTest {
);
}

@isTest
static void testInvalidCourseIdReturnsUnavailableMessage() {
Course__c deletedCourse = new Course__c(
Name = 'Deleted course',
MaxNumberOfParticipants__c = 5,
DescriptionFormatted__c = 'Deleted course'
);
insert deletedCourse;
delete deletedCourse;

CourseRegistrationModel model = new CourseRegistrationModel();
model.firstName = 'Bad';
model.lastName = 'Id';
model.email = 'bad.id@test.no';

CourseRegistrationController.RegistrationResult res = CourseRegistrationController.createRegistration(
JSON.serialize(model),
deletedCourse.Id
);

System.assertEquals(false, res.success);
System.assert(
res.message.contains('Kunne ikke hente kursdetaljer'),
'Expected invalid course id to trigger unavailable course message'
);
}

@isTest
static void testCourseCancelled() {
Course__c c = new Course__c(Name = 'Cancelled', MaxNumberOfParticipants__c = 5, Cancel__c = true);
Expand Down Expand Up @@ -221,4 +248,4 @@ private with sharing class CourseRegistrationControllerTest {

System.assertEquals(0, accounts.size(), 'No accounts should be returned when the organization number is not found');
}
}
}
4 changes: 3 additions & 1 deletion force-app/main/default/classes/CourseRegistrationHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public class CourseRegistrationHelper {
try {
update registrationsToPromote;
} catch (Exception e) {
System.debug(LoggingLevel.ERROR, 'Error promoting waitlisted registrations: ' + e.getMessage());
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ public without sharing class CourseScheduledDeleteContacts {

crListToUpdate.add(cr);
}
update crListToUpdate;
try {
update crListToUpdate;
} catch (Exception e) {
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
throw e;
}
}

// ---------------------------------------------------------------------------------------------- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ public with sharing class CourseScheduledDeleteContactsTest {
);
}

@isTest
private static void testRemovePersonalDataFromCrThrowsForUnsavedRegistration() {
Test.startTest();
try {
CourseScheduledDeleteContacts.removePersonalDataFromCr(new List<CourseRegistration__c>{ new CourseRegistration__c() });
System.assert(false, 'Expected update on unsaved registration to throw');
} catch (Exception e) {
System.assertNotEquals(null, e, 'Expected exception to be rethrown');
}
Test.stopTest();
}

public static CourseRegistration__c getCourseRegistration(String courseId, String contactId) {
CourseRegistration__c cr = new CourseRegistration__c(
CourseParticipant__c = contactId,
Expand Down
Loading
Loading