var twilio = require('../index');

describe('The Twilio REST Client Calls resource', function () {
    var client = new twilio.RestClient('AC123', '123');

    beforeEach(function() {
        spyOn(client, 'request');
    });

    it('initiates a call from a purchased twilio number', function() {
        client.calls.create({
            to:'+14158675309',
            from:'+16517779311',
            url:'https://demo.twilio.com/welcome/voice'
        });
        expect(client.request).toHaveBeenCalledWith({
            url:'/Accounts/AC123/Calls',
            method:'POST',
            form:{
                To:'+14158675309',
                From:'+16517779311',
                Url:'https://demo.twilio.com/welcome/voice'
            }
        }, undefined);
    });

    it('gets information about a specific call', function() {
        client.calls('CA123').get();
        expect(client.request).toHaveBeenCalledWith({
            url:'/Accounts/AC123/Calls/CA123',
            method:'GET',
            qs:{}
        }, undefined);
    });

    it('uses shorthand to make a call', function() {
        client.makeCall({
            to:'+14158675309',
            from:'+16517779311',
            url:'https://demo.twilio.com/welcome/voice'
        });
        expect(client.request).toHaveBeenCalledWith({
            url:'/Accounts/AC123/Calls',
            method:'POST',
            form:{
                To:'+14158675309',
                From:'+16517779311',
                Url:'https://demo.twilio.com/welcome/voice'
            }
        }, undefined);
    });

    it('gets a list of calls for a specific number', function() {
        client.calls.list({
            from:'+14158675309'
        });
        expect(client.request).toHaveBeenCalledWith({
            url:'/Accounts/AC123/Calls',
            method:'GET',
            qs:{
                From:'+14158675309'
            }
        }, undefined);
    });

    it('can create call feedback', function() {
        spyOn(client, 'request');
        client.calls(instanceSid).feedback.create({
            qualityScore:3,
            issue:['imperfect-audio', 'dropped-call']
        });
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/' + instanceSid + '/Feedback',
            'method': 'POST',
            'form': {
                'QualityScore': 3,
                'Issue': ['imperfect-audio', 'dropped-call']
            }
        }, undefined);
    });

    it('can get call feedback', function() {
        spyOn(client, 'request');
        client.calls(instanceSid).feedback.get();
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/' + instanceSid + '/Feedback',
            'method': 'GET',
            'qs': {}
        }, undefined);
    });

    it('can delete call feedback', function() {
        spyOn(client, 'request');
        client.calls(instanceSid).feedback.delete();
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/' + instanceSid + '/Feedback',
            'method': 'DELETE',
            'form': {}
        }, undefined);
    });

    it('can create a call feedback summary', function () {
        spyOn(client, 'request');
        client.calls.feedbackSummary.create({
            startDate: '2014-01-01',
            endDate: '2014-01-31',
            includeSubaccounts: true,
            statusCallback: 'http://www.example.com/feedback'
        });
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/FeedbackSummary',
            'method': 'POST',
            'form': {
                'StartDate': '2014-01-01',
                'EndDate': '2014-01-31',
                'IncludeSubaccounts': true,
                'StatusCallback': 'http://www.example.com/feedback'
            }
        }, undefined);
    });

    it('can get a call feedback summary', function () {
        spyOn(client, 'request');
        client.calls.feedbackSummary('FS123').get();
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/FeedbackSummary/FS123',
            'method': 'GET',
            'qs': {}
        }, undefined);
    });

    it('can delete a call feedback summary', function () {
        spyOn(client, 'request');
        client.calls.feedbackSummary('FS123').delete();
        expect(client.request).toHaveBeenCalled();
        expect(client.request).toHaveBeenCalledWith({
            'url': '/Accounts/' + config.accountSid + '/Calls/FeedbackSummary/FS123',
            'method': 'DELETE',
            'form': {}
        }, undefined);
    });
});

@@ -88,24 +88,85 @@
 nction () %7B%0A
+    var accountSid = 'AC123';%0A    var instanceSid = 'CA123';%0A
     var clie
@@ -192,23 +192,26 @@
 tClient(
-'AC123'
+accountSid
 , '123')
@@ -2052,42 +2052,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -2325,39 +2325,32 @@
  '/Accounts/' + 
-config.
 accountSid + '/C
@@ -2628,42 +2628,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -2805,39 +2805,32 @@
  '/Accounts/' + 
-config.
 accountSid + '/C
@@ -2999,42 +2999,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -3179,39 +3179,32 @@
  '/Accounts/' + 
-config.
 accountSid + '/C
@@ -3389,42 +3389,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -3746,39 +3746,32 @@
  '/Accounts/' + 
-config.
 accountSid + '/C
@@ -4147,42 +4147,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -4327,39 +4327,32 @@
  '/Accounts/' + 
-config.
 accountSid + '/C
@@ -4525,42 +4525,8 @@
 ) %7B%0A
-        spyOn(client, 'request');%0A
     
@@ -4674,32 +4674,32 @@
 eenCalledWith(%7B%0A
+
             'url
@@ -4720,15 +4720,8 @@
 ' + 
-config.
 acco

Fix undef variable errors in feedback tests