//3.2.0 @isTest private class RainbowConnectorTest { static testMethod void testGetUserEmail() { // Create User User usr = new User(); usr.ProfileId = [SELECT Id FROM Profile WHERE Name != 'System Administrator' limit 1].Id; usr.LastName = 'Test'; usr.Email = 'test@test.com'; usr.Username = 'test@test.com' + System.currentTimeMillis(); usr.CompanyName = 'Salesforce'; usr.Title = 'Title'; usr.Alias = 'AliasT'; usr.TimeZoneSidKey = 'America/Los_Angeles'; usr.EmailEncodingKey = 'UTF-8'; usr.LanguageLocaleKey = 'en_US'; usr.LocaleSidKey = 'en_US'; try { System.runAs(usr) { String userEmail = RainbowConnector.getUserEmail(); System.debug('RainbowConnector.getUserEmail: email ' + userEmail); if (userEmail == usr.Email) { System.assert(true, 'userEmail is correct'); } else { System.assert(false, 'userEmail should contain test@test.com'); } } } finally { } } static testMethod void testGetMainURL() { try { String mainURL = RainbowConnector.getMainURL(); if (mainURL != '') { System.assert(true, 'userEmail is correct'); } else { System.assert(false, 'userEmail should contain test@test.com'); } } finally { } } static testMethod void testFormatPhoneNumber(){ // phone number to format // by default the method "formatPhoneNumber" has no conversion. // in each test the variable must be modified according the conversion. String phoneNumber = '+10123456789'; String formatedPhoneNumber = '+10123456789'; try { // Test testFormatPhoneNumber query method String resultFormat = RainbowConnector.formatPhoneNumber(phoneNumber); System.debug('RainbowConnector.formatPhoneNumber: ====> ' + resultFormat); if (phoneNumber == resultFormat) { System.debug('RainbowConnector.formatPhoneNumber: phoneNumber ' + phoneNumber + ' == resultFormat ' + resultFormat); System.assert(true, 'no format phone number'); } else { System.assert(false, 'bad format phone number'); } } finally { } } static testMethod void testGetAccountsByPhoneNumber() { // phone number to search on String phoneNumber = '0298100000'; String formatedPhoneNumber = '0298100000'; try { // get formatPhoneNumber query method formatedPhoneNumber = RainbowConnector.formatPhoneNumber(phoneNumber); } finally { // Delete Contact formatedPhoneNumber = phoneNumber; } // Create Account Account accountTest = new Account(Name = 'AccountTest'); accountTest.Phone = formatedPhoneNumber; insert accountTest; try { // Test getAccountsByPhoneNumber query method String result = RainbowConnector.getAccountsByPhoneNumber('298100000'); System.debug('RainbowConnector.getAccount: ====> ' + result); System.assert(RainbowConnector.getAccountsByPhoneNumber(phoneNumber).contains(formatedPhoneNumber), 'Result should contain at least one account with 0298100000'); } finally { // Delete Account delete accountTest; } } static testMethod void testGetAccountsByFirstLastName() { // name to search on String firstlastname = 'testAccount First LastName'; // Create Account Account accountTest = new Account(); accountTest.Name = firstlastname; accountTest.Phone = '+33298100000'; insert accountTest; try { // Test getAccountsByFirstLastName query method System.assert(RainbowConnector.getAccountsByFirstLastName(firstlastname).contains(firstlastname), 'Result should contain at least one account with firstlastname'); } finally { // Delete Account delete accountTest; } } static testMethod void testGetAccountsByCorrelatorData() { // correlator to search String accountCorrelatorData = 'my correlator data'; // Create Account Account accountTest = new Account(); accountTest.Name = 'AccountTest'; accountTest.Phone = '+33298100000'; accountTest.CorrelatorData__c = 'my correlator data'; insert accountTest; try { // Test getAccountsByCorrelatorData query method System.assert(!RainbowConnector.getAccountsByCorrelatorData(accountCorrelatorData).contains(accountCorrelatorData), 'Result should find the correlator data at least one account with my correlator data'); } finally { // Delete Account delete accountTest; } } static testMethod void testGetContactsByPhoneNumber() { // phone number to search on String phoneNumber = '0298100000'; String formatedPhoneNumber = '0298100000'; try { // get formatPhoneNumber query method formatedPhoneNumber = RainbowConnector.formatPhoneNumber(phoneNumber); } finally { // Delete Contact formatedPhoneNumber = phoneNumber; } // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactFirstName' + DateTime.now(); contactTest.LastName = 'ContactLastName'; contactTest.Phone = formatedPhoneNumber; insert contactTest; try { // Test getContactsByPhoneNumber query method String result = RainbowConnector.getContactsByPhoneNumber(phoneNumber); System.debug('RainbowConnector.getContactsByPhoneNumber: ====> ' + result); System.assert(RainbowConnector.getContactsByPhoneNumber(phoneNumber).contains(formatedPhoneNumber), 'Result should contain one contact with (012)345-6789'); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetContactsByPhoneNumberWithMobilePhone() { // phone number to search on String phoneNumber = '0298100000'; String formatedPhoneNumber = '0298100000'; try { // get formatPhoneNumber query method formatedPhoneNumber = RainbowConnector.formatPhoneNumber(phoneNumber); } finally { // Delete Contact formatedPhoneNumber = phoneNumber; } // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactFirstName' + DateTime.now(); contactTest.LastName = 'ContactLastName'; contactTest.mobilePhone = formatedPhoneNumber; insert contactTest; try { // Test getContactsByPhoneNumber query method String result = RainbowConnector.getContactsByPhoneNumber(phoneNumber); System.debug('RainbowConnector.getContactsByPhoneNumber: ====> ' + result); System.assert(RainbowConnector.getContactsByPhoneNumber(phoneNumber).contains(formatedPhoneNumber), 'Result should contain one contact with mobile phone 0298100000'); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetContactsByFirstLastName() { // name to search on String name = 'LastNameContactTest'; // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactFirstName' + DateTime.now(); contactTest.LastName = name; contactTest.email = 'test@test.com'; contactTest.phone = '123456'; insert contactTest; try { // Test getContactsByFirstLastName query method String result = RainbowConnector.getContactsByFirstLastName(name); System.debug('RainbowConnector.getContactsByFirstLastName: ====> ' + result); System.assert(RainbowConnector.getContactsByFirstLastName(name).contains(name), 'Result should contain one contact with LastNameContactTest'); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetContactsByCorrelatorData() { // correlator to search String contactCorrelatorData = 'my correlator data'; // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactFirstName' + DateTime.now(); contactTest.LastName = 'LastNameContactTest'; contactTest.email = 'test@test.com'; contactTest.phone = '123456'; contactTest.CorrelatorData__c = 'my correlator data'; insert contactTest; try { // Test getContactsByCorrelatorData query method System.assert(!RainbowConnector.getContactsByCorrelatorData(contactCorrelatorData).contains(contactCorrelatorData), 'Result should find the correlator data at least one contact with my correlator data'); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetContactsByEmail() { // email to search on String email = 'test@test.com'; // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactEmail' + DateTime.now(); contactTest.LastName = 'ContactLastName'; contactTest.email = email; contactTest.phone = '123456'; insert contactTest; try { // Test getContactsByFirstLastName query method String result = RainbowConnector.getContactsByEmail(email); System.debug('RainbowConnector.getContactsByEmail: ====> ' + result); System.assert(RainbowConnector.getContactsByEmail(email).contains(email), 'Result should contain one contact with test@test.com'); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetContactByRecordId() { // Create Contact Contact contactTest = new Contact(); contactTest.FirstName = 'ContactEmail' + DateTime.now(); contactTest.LastName = 'ContactLastName'; contactTest.phone = '123456'; insert contactTest; String recordId = contactTest.Id; try { // Test getContactByRecordId query method String result = RainbowConnector.getContactByRecordId(recordId); System.debug('RainbowConnector.getContactByRecordId: ====> ' + result); System.assert(RainbowConnector.getContactByRecordId(recordId).contains(recordId), 'Result should contain one contact with ' + recordId); } finally { // Delete Contact delete contactTest; } } static testMethod void testGetLeadsByPhoneNumber() { // phone number to search on String phoneNumber = '0298100000'; String formatedPhoneNumber = '0298100000'; try { // get formatPhoneNumber query method formatedPhoneNumber = RainbowConnector.formatPhoneNumber(phoneNumber); } finally { // Delete Contact formatedPhoneNumber = phoneNumber; } // Create Lead Lead leadTest = new Lead(); leadTest.FirstName = 'LeadFirstName' + DateTime.now(); leadTest.LastName = 'LeadLastName'; leadTest.Company = 'LeadCompany'; leadTest.Phone = formatedPhoneNumber; insert leadTest; try { // Test getLeadsByPhoneNumber query method String result = RainbowConnector.getLeadsByPhoneNumber(phoneNumber); System.debug('RainbowConnector.getLeadsByPhoneNumber: ====> ' + result); System.assert(RainbowConnector.getLeadsByPhoneNumber(phoneNumber).contains(formatedPhoneNumber), 'Result should contain one Lead with 0298100000'); } finally { // Delete Lead delete leadTest; } } static testMethod void testGetRainbowConnectorProfile() { // Create User User usr = new User(); usr.ProfileId = [SELECT Id FROM Profile WHERE Name != 'System Administrator' limit 1].Id; usr.LastName = 'Test'; usr.Email = 'test@test.com'; usr.Username = 'test@test.com' + System.currentTimeMillis(); usr.CompanyName = 'Salesforce'; usr.Title = 'Title'; usr.Alias = 'AliasT'; usr.TimeZoneSidKey = 'America/Los_Angeles'; usr.EmailEncodingKey = 'UTF-8'; usr.LanguageLocaleKey = 'en_US'; usr.LocaleSidKey = 'en_US'; usr.RainbowConnectorProfile__c = 'testConnectorProfile'; try { System.runAs(usr) { System.assert(RainbowConnector.getRainbowConnectorProfile().contains('testConnectorProfile'), 'userConnectorProfile should contain testConnectorProfile'); } } finally { } } static testMethod void testSetRainbowConnectorProfile() { // Create User User usr = new User(); usr.ProfileId = [SELECT Id FROM Profile WHERE Name != 'System Administrator' limit 1].Id; usr.LastName = 'Test'; usr.Email = 'test@test.com'; usr.Username = 'test@test.com' + System.currentTimeMillis(); usr.CompanyName = 'Salesforce'; usr.Title = 'Title'; usr.Alias = 'AliasT'; usr.TimeZoneSidKey = 'America/Los_Angeles'; usr.EmailEncodingKey = 'UTF-8'; usr.LanguageLocaleKey = 'en_US'; usr.LocaleSidKey = 'en_US'; try { System.runAs(usr) { RainbowConnector.setRainbowConnectorProfile('testConnectorProfile'); User userUpdated = [select Id, RainbowConnectorProfile__c from User where Id =: UserInfo.getUserId()]; if (userUpdated.RainbowConnectorProfile__c == 'testConnectorProfile') { System.assert(true, 'setRainbowConnectorProfile correct value'); } else { System.assert(false, 'setRainbowConnectorProfile bad value'); } } } finally { } } static testMethod void testGetTaskByCallId() { Account accountTest = new Account(Name = 'Sample Account'); insert accountTest; //create Task Task task = new Task(WhatId = accountTest.Id, Subject = 'Test Subject', Status = 'In Progress', CallObject = 'callidTest'); insert task; try { // Test getTaskByCallId query method String resultTask = RainbowConnector.getTaskByCallId('callidTest'); if (resultTask != '[]') { System.assert(true, 'Result should contain one task with callidTest'); } else { System.assert(false, 'Result callid is empty '); } } finally { // Delete Account delete accountTest; } } //////////////////////////new functions static testMethod void testFormatPhoneNumberwithoutSpace(){ // phone number to format // by default the method "formatPhoneNumber" has no conversion. // in each test the variable must be modified according the conversion. String phoneNumber = '+10123456789'; String formatedPhoneNumber = '+10123456789'; try { // Test testFormatPhoneNumber query method String resultFormat = RainbowConnector.formatPhoneNumberwithoutspace(phoneNumber); System.debug('RainbowConnector.formatPhoneNumberwithoutspace: ====> ' + resultFormat); if (phoneNumber == resultFormat) { System.debug('RainbowConnector.formatPhoneNumberwithoutspace: phoneNumber ' + phoneNumber + ' == resultFormat ' + resultFormat); System.assert(true, 'no format phone number'); } else { System.assert(false, 'bad format phone number'); } } finally { } } static testMethod void testGetCasesByPhoneNumber() { // correlator to search String resultFormat = RainbowConnector.getCasesByPhoneNumber('123456'); System.debug('RainbowConnector.formatPhoneNumberwithoutspace: ====> ' + resultFormat); System.debug('RainbowConnector.formatPhoneNumberwithoutspace: phoneNumber ' + ' == resultFormat ' + resultFormat); System.assert(true, 'no format phone number'); } static testMethod void testGetCasesByContactPhone() { // correlator to search String resultFormat = RainbowConnector.getCasesByContactPhone('123456'); System.debug('RainbowConnector.formatPhoneNumberwithoutspace: ====> ' + resultFormat); System.debug('RainbowConnector.formatPhoneNumberwithoutspace: phoneNumber ' + ' == resultFormat ' + resultFormat); if (resultFormat != '[]') { System.assert(true, 'no format phone number'); } try {} finally { // Delete Contact } } static testMethod void testGetAllRecordTypes() { // correlator to search String resultFormat = RainbowConnector.getAllRecordTypes(); if (resultFormat != '[]') { System.assert(true, 'RecordTypes found'); } else { System.assert(true, 'RecordTypes not found'); } try {} finally { // Delete Contact } } static testMethod void testGetProfileRecordTypesCase() { // correlator to search try { String resultFormat = RainbowConnector.getProfileRecordTypesCase(); if (resultFormat != '[]') { System.assert(true, 'RecordTypes found'); } else { System.assert(true, 'RecordTypes not found'); } } finally { // Delete Contact } } static testMethod void testGetProfileRecordTypesContact() { // correlator to search try { String resultFormat = RainbowConnector.getProfileRecordTypesContact(); if (resultFormat != '[]') { System.assert(true, 'RecordTypes found'); } else { System.assert(true, 'RecordTypes not found'); } } finally { // Delete Contact } } static testMethod void testGetProfileRecordTypesAccount() { // correlator to search try { String resultFormat = RainbowConnector.getProfileRecordTypesAccount(); if (resultFormat != '[]') { System.assert(true, 'RecordTypes found'); } else { System.assert(true, 'RecordTypes not found'); } } finally { // Delete Contact } } }