Skip to content

Commit

Permalink
Merge pull request #350 from navikt/TOLK-2358
Browse files Browse the repository at this point in the history
TOLK-2358 Ikke lenger mulig å melde på flere på samme e-postadresse
  • Loading branch information
EdvardBrekke authored Sep 5, 2024
2 parents d84fae6 + 22ce5b1 commit e06796c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
28 changes: 13 additions & 15 deletions force-app/main/default/classes/CourseRegistrationController.cls
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
public with sharing class CourseRegistrationController {
public without sharing class CourseRegistrationController {
@AuraEnabled
public static String createRegistration(String fields, String courseId) {
try {
/* Boolean duplicate = checkForDuplicates( contactId, courseId );
if ( duplicate ) { return 'Du er allerede påmeldt dette kurset'; }
insertRegistration( contactId, courseId );*/
Boolean duplicate = checkForDuplicates(fields, courseId );
if ( duplicate ) {
return 'Du er allerede påmeldt dette kurset, vennligst bruk en annen e-postadresse.';
}
Boolean courseIsFull = checkIfCourseIsFull(courseId);

if (fields != null) {
insertRegistration(fields, courseId);
}
if (courseIsFull) {
return 'Registrering vellykket! Du er nå satt på venteliste og vil motta bekreftelse på e-post dersom du blir tildelt en plass.';
}

return 'Påmelding vellykket. Du vil om kort tid motta en bekreftelse på e-post';
} catch (Exception e) {
return 'Det oppsto en feil. Prøv igjen senere.';
}
}

@AuraEnabled
public static Course__c getCourseFields(String courseId) {
return [
Expand Down Expand Up @@ -86,17 +86,15 @@ public with sharing class CourseRegistrationController {
insert registration;
}
}

/*
public static Boolean checkForDuplicates( Id contactId, Id courseId ) {
public static Boolean checkForDuplicates( String fields, Id courseId ) {
CourseRegistrationModel model = CourseRegistrationModel.parse(fields);
List<CourseRegistration__c> existingRecord =
[SELECT Id, Course__c, CourseParticipant__c
[SELECT Id, Course__c, CourseParticipant__r.Email
FROM CourseRegistration__c
WHERE Course__c =: courseId
AND CourseParticipant__c =: contactId LIMIT 1];
Boolean exists = existingRecord.size() > 0 ? true : false;
AND CourseParticipant__r.Email =: model.email LIMIT 1];

return exists;
}*/
return existingRecord.size() > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,28 @@ private with sharing class CourseRegistrationControllerTest {
wrapper.email = '[email protected]';
wrapper.companyNumber = '677777';
wrapper.source = 'Kurs';

String fields = JSON.serialize(wrapper);

CourseRegistrationModel wrapperDuplicate = new CourseRegistrationModel();
wrapperDuplicate.firstName = 'test2';
wrapperDuplicate.lastName = 'etternavn2';
wrapperDuplicate.phone = '90080902';
wrapperDuplicate.email = '[email protected]';
wrapperDuplicate.companyNumber = '677777';
wrapperDuplicate.source = 'Kurs';
String fieldsOnDuplicate = JSON.serialize(wrapperDuplicate);

Test.StartTest();
String result = CourseRegistrationController.createRegistration(fields, courseId);
String resultOfInitialReg = CourseRegistrationController.createRegistration(fields, courseId);
String result2 = CourseRegistrationController.createRegistration(fields, noCourseId);
String resultOfDuplicateReg = CourseRegistrationController.createRegistration(fieldsOnDuplicate, courseId);
Test.StopTest();
System.assertEquals(
'Påmelding vellykket. Du vil om kort tid motta en bekreftelse på e-post',
result,
resultOfInitialReg,
'Registration successfull'
);
System.assertEquals('Det oppsto en feil. Prøv igjen senere.', result2, 'Course id missing');
System.assertEquals('Du er allerede påmeldt dette kurset, vennligst bruk en annen e-postadresse.', resultOfDuplicateReg, 'Duplicate registration');
}
}

0 comments on commit e06796c

Please sign in to comment.