feat: initialize shared tenant workbench data
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package imworkbench
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPostForTenantAddsTenantHeaders(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if got := r.Header.Get("X-Tenant-ID"); got != "23" {
|
||||
t.Fatalf("X-Tenant-ID = %q, want 23", got)
|
||||
}
|
||||
if got := r.Header.Get("X-Tenant-Code"); got != "merchant-23" {
|
||||
t.Fatalf("X-Tenant-Code = %q, want merchant-23", got)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"code":0,"data":{"tenant_id":23}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := &Client{
|
||||
conf: Config{BaseURL: server.URL, ServiceName: "test", Secret: "secret", Timeout: time.Second},
|
||||
http: server.Client(),
|
||||
}
|
||||
var response struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
if err := client.PostForTenant(context.Background(), "/initialize", map[string]any{"tenant_id": 23}, 23, "merchant-23", &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.TenantID != 23 {
|
||||
t.Fatalf("tenant_id = %d, want 23", response.TenantID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user