a9d81a1094
remove parallel to stabilize ci/cd
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package test
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateDetectDocumentTextExpectation(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
server := &MockServer{
|
|
Client: ts.Client(),
|
|
External: Address(ts.URL),
|
|
}
|
|
expectation := CreateDetectDocumentTextExpectation(t, server, "HI")
|
|
blocks, ok := expectation.Response.Body.(map[string]interface{})["Blocks"].([]map[string]interface{})
|
|
require.True(t, ok)
|
|
assert.Equal(
|
|
t,
|
|
"PAGE",
|
|
blocks[0]["BlockType"],
|
|
)
|
|
relationship, ok := blocks[0]["Relationships"].([]map[string]interface{})
|
|
require.True(t, ok)
|
|
assert.Equal(
|
|
t,
|
|
"CHILD",
|
|
relationship[0]["Type"],
|
|
)
|
|
ids, ok := relationship[0]["Ids"].([]string)
|
|
require.True(t, ok)
|
|
assert.Equal(
|
|
t,
|
|
ids[0],
|
|
blocks[1]["Id"],
|
|
)
|
|
assert.Equal(
|
|
t,
|
|
"HI",
|
|
blocks[1]["Text"],
|
|
)
|
|
}
|
|
|
|
func TestWaitForMockEndpoint(t *testing.T) {
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
|
|
server := CreateMockServer(t)
|
|
|
|
body := strings.NewReader(`{"team":"hello"}`)
|
|
req, err := http.NewRequest("GET", string(server.External), body)
|
|
require.NoError(t, err)
|
|
req.Header.Add("Hidden", "here")
|
|
|
|
expectation := MockExpectation{
|
|
Request: MockRequest{
|
|
Method: "GET",
|
|
Path: "/",
|
|
Headers: MockHeaders{},
|
|
Query: MockQueries{},
|
|
Body: `{"team":"hello"}`,
|
|
},
|
|
Response: MockResponse{
|
|
Code: 200,
|
|
Headers: MockHeaders{},
|
|
Body: "byebye",
|
|
},
|
|
}
|
|
|
|
CreateMockExpectation(t, server, expectation)
|
|
|
|
resp, err := server.Client.Do(req)
|
|
require.NoError(t, err)
|
|
defer resp.Body.Close()
|
|
|
|
respStr, err := io.ReadAll(resp.Body)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []byte("byebye"), respStr)
|
|
|
|
request := WaitForMockEndpoint(t, server, expectation.Request)
|
|
assert.Equal(t, []string([]string{"here"}), request.Headers["Hidden"])
|
|
}
|