From 81d6f12074ea4cdfc94dbd34b474982ce5fe269d Mon Sep 17 00:00:00 2001 From: tnascimento Date: Tue, 28 May 2024 20:36:43 -0300 Subject: [PATCH] feat: testando json output e multi test classes no runspecifiedtests --- .github/workflows/developOnPR.yml | 6 +- force-app/main/default/classes/DummyClass.cls | 8 +- .../default/classes/DummyClass.cls-meta.xml | 2 +- .../main/default/classes/DummyClassTest.cls | 30 ++ .../classes/DummyClassTest.cls-meta.xml | 5 + .../classes/RiskAssessmentFlowController.cls | 278 ++++++++++++++++++ .../RiskAssessmentFlowController.cls-meta.xml | 5 + .../RiskAssessmentFlowControllerTest.cls | 98 ++++++ ...kAssessmentFlowControllerTest.cls-meta.xml | 5 + manifest/buildfile.json | 8 + manifest/package.xml | 44 +-- 11 files changed, 443 insertions(+), 46 deletions(-) create mode 100644 force-app/main/default/classes/DummyClassTest.cls create mode 100644 force-app/main/default/classes/DummyClassTest.cls-meta.xml create mode 100644 force-app/main/default/classes/RiskAssessmentFlowController.cls create mode 100644 force-app/main/default/classes/RiskAssessmentFlowController.cls-meta.xml create mode 100644 force-app/main/default/classes/RiskAssessmentFlowControllerTest.cls create mode 100644 force-app/main/default/classes/RiskAssessmentFlowControllerTest.cls-meta.xml diff --git a/.github/workflows/developOnPR.yml b/.github/workflows/developOnPR.yml index 7091872..3e3bc77 100644 --- a/.github/workflows/developOnPR.yml +++ b/.github/workflows/developOnPR.yml @@ -12,8 +12,6 @@ jobs: container: tnascimento013/latam_salesforcedx_industries_orgdevmodebuilds:latest environment: build steps: - - name: Installing missing CLIs / Plugins - run: echo "y" | sf plugins install sf-orgdevmode-builds - name: Checkout source code uses: actions/checkout@v3 @@ -22,4 +20,6 @@ jobs: run: 'echo "${{ secrets.JWT_KEY_NONPROD }}" > server.key' - name: Running the build & deploy - run: sf builds deploy --buildfile manifest/buildfile.json --client-id ${{ vars.CLIENT_ID }} --instance-url ${{ vars.INSTANCE_URL }} --username ${{ vars.USERNAME }} --jwt-key-file server.key + run: | + export HOME=/root + sf builds deploy --buildfile manifest/buildfile.json --client-id ${{ vars.CLIENT_ID }} --instance-url ${{ vars.INSTANCE_URL }} --username ${{ vars.USERNAME }} --jwt-key-file server.key diff --git a/force-app/main/default/classes/DummyClass.cls b/force-app/main/default/classes/DummyClass.cls index 7735567..10659e9 100644 --- a/force-app/main/default/classes/DummyClass.cls +++ b/force-app/main/default/classes/DummyClass.cls @@ -1,6 +1,6 @@ public with sharing class DummyClass { - public DummyClass() { - /* Do some comments here */ - } -} + public static void doSomething() { + System.debug('something'); + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/DummyClass.cls-meta.xml b/force-app/main/default/classes/DummyClass.cls-meta.xml index 45cccbd..754ecb1 100644 --- a/force-app/main/default/classes/DummyClass.cls-meta.xml +++ b/force-app/main/default/classes/DummyClass.cls-meta.xml @@ -2,4 +2,4 @@ 57.0 Active - \ No newline at end of file + diff --git a/force-app/main/default/classes/DummyClassTest.cls b/force-app/main/default/classes/DummyClassTest.cls new file mode 100644 index 0000000..e7b5962 --- /dev/null +++ b/force-app/main/default/classes/DummyClassTest.cls @@ -0,0 +1,30 @@ +/** + * This class contains unit tests for validating the behavior of Apex classes + * and triggers. + * + * Unit tests are class methods that verify whether a particular piece + * of code is working properly. Unit test methods take no arguments, + * commit no data to the database, and are flagged with the testMethod + * keyword in the method definition. + * + * All test methods in an org are executed whenever Apex code is deployed + * to a production org to confirm correctness, ensure code + * coverage, and prevent regressions. All Apex classes are + * required to have at least 75% code coverage in order to be deployed + * to a production org. In addition, all triggers must have some code coverage. + * + * The @isTest class annotation indicates this class only contains test + * methods. Classes defined with the @isTest annotation do not count against + * the org size limit for all Apex scripts. + * + * See the Apex Language Reference for more information about Testing and Code Coverage. + */ +@isTest +private class DummyClassTest { + + @isTest + static void myUnitTest() { + DummyClass.doSomething(); + Assert.isTrue(true); + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/DummyClassTest.cls-meta.xml b/force-app/main/default/classes/DummyClassTest.cls-meta.xml new file mode 100644 index 0000000..019e850 --- /dev/null +++ b/force-app/main/default/classes/DummyClassTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + \ No newline at end of file diff --git a/force-app/main/default/classes/RiskAssessmentFlowController.cls b/force-app/main/default/classes/RiskAssessmentFlowController.cls new file mode 100644 index 0000000..f5ef669 --- /dev/null +++ b/force-app/main/default/classes/RiskAssessmentFlowController.cls @@ -0,0 +1,278 @@ +/* author: Tiago Nascimento + APEX Controller of RiskAssessmentFlow LWC +*/ +public class RiskAssessmentFlowController { + + public static String HTML_ID_PREFIX = 'BS-COVID-19-'; + + /* + * Method responsible for executing the final component action - create or update the case + */ + @AuraEnabled + public static String createUpdateCase(CreateCaseRequest request) { + + BSC_Risk_Category__c categoria = + [SELECT Id, Name, Case_Record_Type__c, Case_Priority__c, Create_a_Case__c + FROM BSC_Risk_Category__c + WHERE Id = :request.riskCategoryId]; + + Id objectId = null; + + if (categoria.Create_a_Case__c) { + + // Account acct = null; + // try { + // // whenever the component is invoked from context unaware page - such as a home page + // if (request.idRegistro == null) { + // acct = [Select Id, FirstName, LastName, Phone, PersonEmail from Account WHERE Phone = :request.phone]; + // // whenever the component is invoked from context aware page - such as a record page + // } else { + // acct = [Select Id, FirstName, LastName, Phone, PersonEmail from Account WHERE Id = :request.idRegistro]; + // } + // } catch (QueryException ex) { + // // não faz nada, contato não existe + // } + + // if (acct == null) { + // acct = new Account(); + // } + + // // spliting name into first and last name + // if (request.nomeContato.contains(' ')) { + // String[] nomes = request.nomeContato.split(' '); + // acct.FirstName = nomes[0]; + // String nome = ''; + // for (Integer i = 0; i < nomes.size(); i++) { + // if (i != 0) { + // nome += nomes[i] + ' '; + // } + // } + // nome = nome.trim(); + // acct.LastName = nome; + // } else { + // acct.LastName = request.nomeContato; + // } + // acct.Phone = request.phone; + // acct.PersonEmail = request.email; + // acct.put('RecordTypeId', Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId()); + + + // if (acct.Id != null) { + // update acct; + // } else { + // insert acct; + // } + + // creating the case + Case caso = new Case(); + caso.Status = 'New'; + caso.Origin = 'Web-COVID19'; + caso.Subject = 'Formulário de Análise de Risco de COVID-19 - Paciente: ' + + request.nomeContato + ' Categoria de Risco: ' + categoria.Name; + caso.Priority = categoria.Case_Priority__c; + caso.Description = request.respostas; + // caso.AccountId = acct.Id; + + if (categoria.Case_Record_Type__c != null + && Schema.SObjectType.Case.getRecordTypeInfosByName().get(categoria.Case_Record_Type__c) != null) { + + caso.put('RecordTypeId', Schema.SObjectType.Case.getRecordTypeInfosByName().get(categoria.Case_Record_Type__c).getRecordTypeId()); + } + + insert caso; + + objectId = caso.Id; + } + + return objectId; + } + + /* + * Method responsible for calculating the final risk assessment category based on the questionaire answers. + * The method will return a wrapper inner class, defined down below. + */ + @AuraEnabled(cacheable=true) + public static Category getRiskAssessmentCategory(String defName, Double score, Id idRegistro) { + + Category catR = null; + + BSC_Risk_Assessment_Definition__c rad = + [SELECT Id + FROM BSC_Risk_Assessment_Definition__c + WHERE Name = :defName AND Active__c = TRUE + ORDER BY Initial_Date__c DESC + LIMIT 1]; + + List categories = + [SELECT Id, Name, Final_Message_To_Display__c, Create_a_Case__c, Case_Record_Type__c, Minimum_Score__c, Case_Priority__c + FROM BSC_Risk_Category__c + WHERE Risk_Assessment_Definition__c = :rad.Id + ORDER BY Minimum_Score__c DESC]; + + Account acct = null; + // if (idRegistro != null && 'Account'.equals(idRegistro.getSObjectType().getDescribe().getName())) { + // acct = [SELECT Name, PersonEmail, Phone FROM Account WHERE Id = :idRegistro]; + // } + + // calculating the category that has higher minimum score that fits in the questionaire responses + for (BSC_Risk_Category__c cat : categories) { + if (catR == null && cat.Minimum_Score__c <= score) { + catR = new Category(); + catR.categoryId = cat.Id; + catR.name = cat.Name; + if (Schema.SObjectType.Case.getRecordTypeInfosByName().get(cat.Case_Record_Type__c) != null) { + catR.caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get(cat.Case_Record_Type__c).getRecordTypeId(); + } + catR.casePriority = cat.Case_Priority__c; + catR.createACase = cat.Create_a_Case__c; + catR.textToDisplay = cat.Final_Message_To_Display__c; + // if (acct != null) { + // catR.nomeContato = acct.Name; + // catR.phone = acct.Phone; + // catR.email = acct.PersonEmail; + // } + break; + } + } + return catR; + } + + /* + * Method responsible for getting the questionaire as informed by the component. The method will return a list + * of sections - a wrapper inner class defined down below. + */ + @AuraEnabled(cacheable=true) + public static List
getRiskAssessmentQuestionaire(String defName) { + + List
sectionList = new List
(); + + BSC_Risk_Assessment_Definition__c rad = + [SELECT Id + FROM BSC_Risk_Assessment_Definition__c + WHERE Name = :defName AND Active__c = TRUE + ORDER BY Initial_Date__c DESC + LIMIT 1]; + + List sectionsc = + [SELECT Id, Name From BSC_Risk_Assessment_Section__c + WHERE Risk_Assessment_Definition__c = :rad.Id + ORDER BY Sequence__c]; + + Integer sectionNumber = 0; + Integer questionNumber = 0; + + for (BSC_Risk_Assessment_Section__c sectionc : sectionsc) { + Section sec = new Section(); + sec.Id = sectionc.Id; + sec.text = sectionc.Name; + sec.sectionHTMLId = HTML_ID_PREFIX + 'S-' + sectionNumber; + sec.questions = new List(); + + List questionsc = + [SELECT Id, Question_Text__c, Question_Type__c, Weight__c, Is_Required__c, Is_Last_Question__c, + (Select Id, Option_Value__c, Option_Score__c FROM Question_Options__r ORDER BY Option_Score__c) + FROM BSC_Question__c + WHERE Risk_Assessment_Section__c = :sectionc.Id + ORDER BY Sequence__c]; + + for (BSC_Question__c questionc : questionsc) { + Question qst = new Question(); + qst.id = questionc.Id; + qst.text = questionc.Question_Text__c; + qst.setType(questionc.Question_Type__c); + qst.weight = questionc.Weight__c; + qst.isRequired = questionc.Is_Required__c; + qst.isLast = questionc.Is_Last_Question__c; + qst.questionHTMLId = sec.sectionHTMLId + '-Q-' + questionNumber; + questionNumber += 1; + + if (sectionNumber + 1 < sectionsc.size()) { + qst.nextSectionHTMLId = HTML_ID_PREFIX + 'S-' + (sectionNumber + 1); + } + + if (questionNumber < questionsc.size()) { + qst.nextQuestionHTMLId = sec.sectionHTMLId + '-Q-' + questionNumber; + } else { + qst.nextQuestionHTMLId = qst.nextSectionHTMLId + '-Q-0'; + } + + qst.options = new List