Skip to content

Commit c1e8611

Browse files
committed
Improved unit test to include endpoint called
1 parent 2230127 commit c1e8611

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

voice/testdata/transcriptObject.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"data": [
3+
{
4+
"id": "00000000-1111-2222-3333-444444444444",
5+
"recordingId": "55555555-6666-7777-8888-999999999999",
6+
"error": null,
7+
"createdAt": "2011-01-01T02:03:04Z",
8+
"updatedAt": "2011-01-02T03:04:05Z"
9+
}
10+
]
11+
}

voice/transcription_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package voice
22

33
import (
4+
"fmt"
45
"net/http"
56
"testing"
7+
8+
"github.com/messagebird/go-rest-api/internal/mbtest"
69
)
710

11+
func TestMain(m *testing.M) {
12+
mbtest.EnableServer(m)
13+
}
14+
815
func TestTranscriptionGetContents(t *testing.T) {
916
text := "the quick brown fox jumps over the lazy dog"
1017
mbClient, stop := testRequest(http.StatusOK, []byte(text))
@@ -28,23 +35,14 @@ func TestTranscriptionGetContents(t *testing.T) {
2835
}
2936

3037
func TestCreateTranscription(t *testing.T) {
31-
mbClient, stop := testRequest(http.StatusOK, []byte(`{
32-
"data": [
33-
{
34-
"id": "00000000-1111-2222-3333-444444444444",
35-
"recordingId": "55555555-6666-7777-8888-999999999999",
36-
"error": null,
37-
"createdAt": "2011-01-01T02:03:04Z",
38-
"updatedAt": "2011-01-02T03:04:05Z"
39-
}
40-
]
41-
}`))
42-
defer stop()
38+
mbtest.WillReturnTestdata(t, "transcriptObject.json", http.StatusOK)
39+
client := mbtest.Client(t)
4340

4441
callID, legID, recordingID := "7777777", "88888888", "999999999"
45-
46-
_, err := CreateTranscription(mbClient, callID, legID, recordingID)
42+
_, err := CreateTranscription(client, callID, legID, recordingID)
4743
if err != nil {
4844
t.Fatal(err)
4945
}
46+
47+
mbtest.AssertEndpointCalled(t, http.MethodPost, fmt.Sprintf("/calls/%s/legs/%s/recordings/%s/transcriptions", callID, legID, recordingID))
5048
}

0 commit comments

Comments
 (0)