Skip to content

TOLK-2358 Ikke lenger mulig å melde på flere på samme e-postadresse #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2024
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
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');
}
}
Loading