github.com/subosito/twilio@v0.0.1/sms_test.go (about) 1 package twilio 2 3 import ( 4 "net/http" 5 "testing" 6 ) 7 8 func TestTwilioInvalidAccountForSendingSMS(t *testing.T) { 9 w := NewTwilio(accountSid, "abc") 10 _, err := w.SimpleSendSMS(from, to, body) 11 e := err.(*Exception) 12 13 if e.Status != http.StatusUnauthorized { 14 t.Errorf("e.Status: %d != %d", e.Status, http.StatusUnauthorized) 15 } 16 17 if code := 20003; e.Code != code { 18 t.Errorf("e.Code: %d != %d", e.Code, code) 19 } 20 } 21 22 func TestTwilioUnableSendSMS(t *testing.T) { 23 w := NewTwilio(accountSid, authToken) 24 _, err := w.SimpleSendSMS(from, "abc", body) 25 e := err.(*Exception) 26 27 if e.Status != http.StatusBadRequest { 28 t.Errorf("e.Status: %d != %d", e.Status, http.StatusBadRequest) 29 } 30 31 if code := 21211; e.Code != code { 32 t.Errorf("e.Code: %d != %d", e.Code, code) 33 } 34 } 35 36 func TestTwilioSendSMS(t *testing.T) { 37 w := NewTwilio(accountSid, authToken) 38 s, _ := w.SendSMS(from, to, body, SMSParams{}) 39 40 if s.AccountSid != accountSid { 41 t.Errorf("s.AccountSid: %s != %s", s.AccountSid, accountSid) 42 } 43 44 if s.ApiVersion != apiVersion { 45 t.Errorf("s.ApiVersion: %s != %s", s.ApiVersion, apiVersion) 46 } 47 } 48 49 func TestTwilioGetSMS(t *testing.T) { 50 w := NewTwilio(accountSid, authToken) 51 w.Transport = &RecordingTransport{ 52 Transport: http.DefaultTransport, 53 Status: 200, 54 Body: response["SMS"], 55 } 56 57 r, _ := w.GetSMS("SM800f449d0399ed014aae2bcc0cc2f2ec") 58 59 if r.AccountSid != accountSid { 60 t.Errorf("s.AccountSid: %s != %s", r.AccountSid, accountSid) 61 } 62 63 if r.ApiVersion != apiVersion { 64 t.Errorf("s.ApiVersion: %s != %s", r.ApiVersion, apiVersion) 65 } 66 } 67 68 func TestTwilioListSMS(t *testing.T) { 69 w := NewTwilio(accountSid, authToken) 70 w.Transport = &RecordingTransport{ 71 Transport: http.DefaultTransport, 72 Status: 200, 73 Body: response["SMSList"], 74 } 75 76 r, _ := w.ListSMS(map[string]string{}) 77 78 if start := 0; r.Start != start { 79 t.Errorf("r.Start: %s != %s", r.Start, start) 80 } 81 }