github.com/clerkinc/clerk-sdk-go@v1.49.1/clerk/proxy_checks_test.go (about)

     1  package clerk
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"net/http"
     7  	"reflect"
     8  	"testing"
     9  )
    10  
    11  func TestProxyChecksService_Create(t *testing.T) {
    12  	client, mux, _, teardown := setup("token")
    13  	defer teardown()
    14  	var params CreateProxyCheckParams
    15  	payload := `{
    16  	"proxy_url":"https://example.com/__clerk",
    17  	"domain_id": "dmn_1mebQggrD3xO5JfuHk7clQ94ysA"
    18  }`
    19  	_ = json.Unmarshal([]byte(payload), &params)
    20  
    21  	mux.HandleFunc("/proxy_checks", func(w http.ResponseWriter, req *http.Request) {
    22  		testHttpMethod(t, req, "POST")
    23  		testHeader(t, req, "Authorization", "Bearer token")
    24  		fmt.Fprint(w, dummyProxyCheckJSON)
    25  	})
    26  
    27  	got, err := client.ProxyChecks().Create(params)
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	var want ProxyCheck
    33  	err = json.Unmarshal([]byte(dummyProxyCheckJSON), &want)
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	if !reflect.DeepEqual(got, &want) {
    39  		t.Errorf("Response = %v, want %v", got, &want)
    40  	}
    41  }
    42  
    43  const dummyProxyCheckJSON = `{
    44  	"object": "proxy_check",
    45  	"id": "proxychk_1mebQggrD3xO5JfuHk7clQ94ysA",
    46  	"successful": true,
    47  	"domain_id": "dmn_1mebQggrD3xO5JfuHk7clQ94ysA",
    48  	"proxy_url": "https://example.com/__clerk",
    49  	"last_run_at": 1610783813,
    50  	"created_at": 1610783813,
    51  	"updated_at": 1610783813
    52  }`