twilio / twilio-salesforce

A Salesforce/Force.com library for communicating with the Twilio REST API and generating TwiML. Need help? Post your questions to http://getsatisfaction.com/twilio or email us at help@twilio.com
http://www.twilio.com/salesforce
MIT License
189 stars 136 forks source link

ant deployment failure #48

Open EmilioGalicia opened 9 years ago

EmilioGalicia commented 9 years ago

Hi, I'm getting the following errors when I try to deploy to a dev org using ANT:

All Test Failures:

  1. Twilio_TestApplication.testTwilioAplications_filter -- TwilioRestException: Script-thrown exception Stack trace: Class.TwilioRestClient: line 591, column 1 Class.TwilioResource: line 82, column 1 Class.TwilioResource.ListResource: line 463, column 1 Class.TwilioApplicationList: line 80, column 1 Class.Twilio_TestApplication.testTwilioAplications_filter: line 139, column 1
  2. Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter -- Tw ilioRestException: Script-thrown exception Stack trace: Class.TwilioRestClient: line 591, column 1 Class.TwilioResource: line 82, column 1 Class.TwilioResource.ListResource: line 463, column 1 Class.TwilioAvailablePhoneNumberList: line 106, column 1 Class.Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter : line 274, column 1
  3. TwilioCapability.testGenerateParamString -- System.AssertException: Assertio n Failed: Expected: cat=dog&foo=bar, Actual: foo=bar&cat=dog Stack trace: Class.TwilioCapability.testGenerateParamString: line 273, colum n 1

I have traced the error by running just the Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter method. What I found is the following message:

"Did not find Resource for GET https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json"

And that's because the uri passed to the Twilio_TestHTTPMock Reponse is not contained in the resourceMap.keySet();

Params: (uri:)HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON

(resourceMap().keySet()) Keys :{HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON?AREACODE=510&CONTAINS=51034*****

Need help!

EmilioGalicia commented 9 years ago

I forgot to say, I have this code working in other dev orgs and tests run fine, this is when I try to deploy to a new dev org, is there something I need to update/change with new Salesforce releases?

hhai commented 9 years ago

https://help.salesforce.com/apex/HTViewSolution?id=000213516&language=en_US

If you have accepted the critical update on those orgs for "Predictable Iteration Order for Apex Unordered Collections", then the test classes will fail because the order no longer matches what is returned. In these cases I would re-order the parameters in the MAP in most of the cases, until we can patch the code.

This is re-ordered to match the URL.

        map<string,string> params=new map<string,string>();
        params.put('AreaCode','510');
        params.put('Contains','51034*****');
EmilioGalicia commented 9 years ago

Thanks for your response it helped us alot, we followed your steps and the errors are gone

EmilioGalicia commented 9 years ago

I need to add that we had to add a validation for the orgs that hasn't accepted the update yet in order to work in both scenarios.

static testMethod void testGenerateParamString() {
    Boolean firstKey = true;
    Boolean isOrdered = false;
    Map<String, String> ordMap = new Map<String, String>{'a' => 'b', 'c' => 'd'};
    for(String key: ordMap.keySet()){
        if(ordMap.get(key) == 'b' && firstKey){ isOrdered = true; }
        firstKey = false;
    }

    if(isOrdered){
                    //Update accepted
        System.assertEquals('', generateParamString(new Map<String,String>()));
        System.assertEquals('a=b', generateParamString(new Map<String,String> {'a'=>'b'} ));
        System.assertEquals('foo=bar&cat=dog', generateParamString(new Map<String,String> {'foo'=>'bar', 'cat' => 'dog'} ));
        System.assertEquals('a=b&c=d&e=f', generateParamString(new Map<String,String> {'a'=>'b', 'c'=>'d', 'e'=>'f' } ));
        System.assertEquals('split+key1=split+val1&split+key2=split+val2', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split key2'=>'split val2'} ));
    }else{
                    //Update not accepted
        System.assertEquals('', generateParamString(new Map<String,String>()));
        System.assertEquals('a=b', generateParamString(new Map<String,String> {'a'=>'b'} ));
        System.assertEquals('cat=dog&foo=bar', generateParamString(new Map<String,String> {'foo'=>'bar', 'cat' => 'dog'} ));
        System.assertEquals('e=f&c=d&a=b', generateParamString(new Map<String,String> {'a'=>'b', 'c'=>'d', 'e'=>'f' } ));
        System.assertEquals('split+key2=split+val2&split+key1=split+val1', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split key2'=>'split val2'} ));
    }
}
dschach commented 9 years ago

Please reopen this and change

if(ordMap.get(key) == 'b' && firstKey)isOrdered = true;

to

if(ordMap.get(key) == 'b' && firstKey){ isOrdered = true; }

This is the error that created a major security hole in OSX, and best-practice is to use curly brackets for every if statement, even on one line.

skimbrel commented 9 years ago

I'd be happy to review a pull request for that :)

EmilioGalicia commented 9 years ago

re-opened issue and updated the comment and our code, thanks for the heads up

EmilioGalicia commented 9 years ago

I have sent the request

dschach commented 9 years ago

Thank you. Apologies for asking someone else to make the change (faux pas, I know) but I wasn't at a machine that would let me do it myself. Go team!

EmilioGalicia commented 9 years ago

no prob, I just haven't had enough time to figure out how to remove whitespacing and indentation :P

Harishgudipudi commented 9 years ago

Hi,

I'm new to this twilio stuff but when I'm trying to deploy I'm getting the same errors in the salesforce production and also we have the update our org with critical updates.

Can you pls let me know on which class I have to update these Lines:

map<string,string> params=new map<string,string>(); params.put('AreaCode','510'); params.put('Contains','51034*****');

Harishgudipudi commented 9 years ago

Here is the test class failures: twilio errors

EmilioGalicia commented 9 years ago

Hi,

You need to modify both files: Twilio_TestApplication and Twilio_TestPhoneNumbers

kushkella commented 9 years ago

Is it possible if we can get an updated managed package with this bug fix?

hhai commented 9 years ago

We currently aren't releasing managed packages for salesforce.

kushkella commented 9 years ago

Sorry, I meant unmanaged package. Is v4.0.0 with this bug fix?

hhai commented 9 years ago

The latest version has many updates in it, including support for some of our new APIs, and re-ordering the test data expected to the Salesforce Unordered Lists patch which is auto activated on 6/5 by salesforce. However, it also has some restructuring of classes so if you have already installed and are leveraging an older version I would advise you to update the test class yourself versus using v4.0.

saamabbas commented 9 years ago

To Fix the issue quickly:

1) Re - Order Map values in Twilio_TestApplication class near line no. 130 and 219 as given below: params.put('VoiceMethod','POST'); params.put('FriendlyName','Testapp1');

2) Re - Order Map values in Twilio_TestPhoneNumbers class near line no. 264 as given below: params.put('AreaCode','510'); params.put('Contains','51034*****');

3) Comment the 5 line code from line no. 271 to 275 in TwilioCapability class and all the error will be gone.

crashdebit commented 9 years ago

@saamabbas very clear on the directions listed above, wanted to comment that this fix worked perfectly.