-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsenderid_test.go
115 lines (103 loc) · 3.19 KB
/
senderid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package termiigo
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
)
const apiKey = "TL2yxYKBgewEkKMNWlcIGVkkfAITCqLHc8VE4zTEcdpZGwGzC7lhwHn3I6AYjc"
//var client = NewClient(os.Getenv("TERMII_API_KEY"), nil)
func TestGetSenderId(t *testing.T) {
// Mock HTTP server for testing
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Validate request parameters
assert.Equal(t, "/sender-id", r.URL.Path)
assert.Equal(t, "GET", r.Method)
assert.Equal(t, apiKey, r.URL.Query().Get("api_key"))
// Respond with a mock JSON response
mockResponse := map[string]interface{}{
"current_page": 1,
"data": []interface{}{
map[string]interface{}{
"sender_id": "ACME Key",
"status": "unblock",
"company": "",
"usecase": "",
"country": "",
"created_at": "2021-03-29 16:51:53",
},
map[string]interface{}{
"sender_id": "ACME Alert",
"status": "unblock",
"company": "",
"usecase": "",
"country": "",
"created_at": "2021-03-29 16:51:09",
},
},
"first_page_url": "https://termii.com/api/sender-id?page=1",
"from": 1,
"last_page": 47,
"last_page_url": "https://termii.com/api/sender-id?page=47",
"next_page_url": "https://termii.com/api/sender-id?page=2",
"path": "https://termii.com/api/sender-id",
"per_page": 10,
"prev_page_url": "",
"to": 15,
"total": 704,
}
responseJSON, _ := json.Marshal(mockResponse)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(responseJSON)
}))
defer mockServer.Close()
// Set TERMII_API_KEY to a mock API key for testing
os.Setenv("TERMII_API_KEY", apiKey)
defer os.Unsetenv("TERMII_API_KEY")
// Create a client with the mock server's URL
client := NewClient(apiKey, nil)
client.SenderIDServiceR.client.baseUrl, _ = url.Parse(mockServer.URL)
// Call the GetSenderId method
senderIdResponse, err := client.SenderIDServiceR.GetSenderId()
//fmt.Println(senderIdResponse)
// Assert that there is no error
assert.NoError(t, err)
// Assert the expected response
expectedResponse := map[string]interface{}{
"current_page": 1,
"data": []interface{}{
map[string]interface{}{
"sender_id": "ACME Key",
"status": "unblock",
"company": "",
"usecase": "",
"country": "",
"created_at": "2021-03-29 16:51:53",
},
map[string]interface{}{
"sender_id": "ACME Alert",
"status": "unblock",
"company": "",
"usecase": "",
"country": "",
"created_at": "2021-03-29 16:51:09",
},
},
"first_page_url": "https://termii.com/api/sender-id?page=1",
"from": 1,
"last_page": 47,
"last_page_url": "https://termii.com/api/sender-id?page=47",
"next_page_url": "https://termii.com/api/sender-id?page=2",
"path": "https://termii.com/api/sender-id",
"per_page": 10,
"prev_page_url": "",
"to": 15,
"total": 704,
}
//responseJSON, _ := json.Marshal(senderIdResponse)
assert.Equal(t, expectedResponse, senderIdResponse)
}