-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_test.go
More file actions
59 lines (48 loc) · 1.29 KB
/
handler_test.go
File metadata and controls
59 lines (48 loc) · 1.29 KB
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
package webhook
import (
"bytes"
"encoding/json"
"fmt"
"github.com/aiteung/module/model"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetRandomString(t *testing.T) {
stringssss := GetRandomString(stringreply)
fmt.Println(stringssss)
}
func TestPostBalasan(t *testing.T) {
// Mock the request data
mockMsg := model.IteungMessage{
Message: "Hi, bro",
Phone_number: "123456789",
Latitude: 37.7749,
Longitude: -122.4194,
Alias_name: "Steven",
LiveLoc: false,
}
// Encode the mock message to JSON
jsonData, err := json.Marshal(mockMsg)
if err != nil {
t.Fatal(err)
}
// Create a request with the mock data
req, err := http.NewRequest("POST", "/post-balasan", bytes.NewBuffer(jsonData))
if err != nil {
t.Fatal(err)
}
// Set the Secret header
req.Header.Set("Secret", "bebas")
// Create a response recorder to capture the response
res := httptest.NewRecorder()
// Call the handler function
PostBalasan(res, req)
// Check the status code
if res.Code != http.StatusOK {
t.Errorf("Expected status 200; got %d", res.Code)
}
// You can add more assertions based on your specific use case
// For example, you can check the response body or headers.
}
// You can create similar test functions for other functions like Liveloc, GetRandomString, etc.