-
Notifications
You must be signed in to change notification settings - Fork 16
/
manager_report_test.go
110 lines (88 loc) · 3.02 KB
/
manager_report_test.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package proton_test
import (
"bytes"
"context"
"mime"
"mime/multipart"
"testing"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-proton-api/server"
"github.com/stretchr/testify/require"
)
func TestReportBug(t *testing.T) {
s := server.New()
defer s.Close()
m := proton.New(
proton.WithHostURL(s.GetHostURL()),
proton.WithTransport(proton.InsecureTransport()),
)
defer m.Close()
var calls []server.Call
s.AddCallWatcher(func(call server.Call) {
calls = append(calls, call)
})
res, err := m.ReportBug(context.Background(), proton.ReportBugReq{
OS: "linux",
OSVersion: "5.4.0-42-generic",
Browser: "firefox",
ClientType: proton.ClientTypeEmail,
})
require.NoError(t, err)
require.Equal(t, (*string)(nil), res.Token)
mimeType, mimeParams, err := mime.ParseMediaType(calls[0].RequestHeader.Get("Content-Type"))
require.NoError(t, err)
require.Equal(t, "multipart/form-data", mimeType)
form, err := multipart.NewReader(bytes.NewReader(calls[0].RequestBody), mimeParams["boundary"]).ReadForm(0)
require.NoError(t, err)
require.Len(t, form.Value, 5)
require.Equal(t, "linux", form.Value["OS"][0])
require.Equal(t, "5.4.0-42-generic", form.Value["OSVersion"][0])
require.Equal(t, "firefox", form.Value["Browser"][0])
require.Equal(t, "1", form.Value["ClientType"][0])
require.Equal(t, "0", form.Value["AsyncAttachments"][0])
}
func TestReportBugAsync(t *testing.T) {
s := server.New()
defer s.Close()
m := proton.New(
proton.WithHostURL(s.GetHostURL()),
proton.WithTransport(proton.InsecureTransport()),
)
defer m.Close()
var calls []server.Call
s.AddCallWatcher(func(call server.Call) {
calls = append(calls, call)
})
res, err := m.ReportBug(context.Background(), proton.ReportBugReq{
OS: "linux",
OSVersion: "5.4.0-42-generic",
Browser: "firefox",
ClientType: proton.ClientTypeEmail,
AsyncAttachments: proton.AttachmentTypeAsync,
})
require.NoError(t, err)
require.NotEmpty(t, res.Token)
mimeType, mimeParams, err := mime.ParseMediaType(calls[0].RequestHeader.Get("Content-Type"))
require.NoError(t, err)
require.Equal(t, "multipart/form-data", mimeType)
form, err := multipart.NewReader(bytes.NewReader(calls[0].RequestBody), mimeParams["boundary"]).ReadForm(0)
require.NoError(t, err)
require.Len(t, form.Value, 5)
require.Equal(t, "linux", form.Value["OS"][0])
require.Equal(t, "5.4.0-42-generic", form.Value["OSVersion"][0])
require.Equal(t, "firefox", form.Value["Browser"][0])
require.Equal(t, "1", form.Value["ClientType"][0])
require.Equal(t, "1", form.Value["AsyncAttachments"][0])
err = m.ReportBugAttachement(context.Background(), proton.ReportBugAttachmentReq{
Product: proton.ClientTypeEmail,
Body: "Comment without any attachment",
Token: *res.Token,
})
require.NoError(t, err)
err = m.ReportBugAttachement(context.Background(), proton.ReportBugAttachmentReq{
Product: proton.ClientTypeEmail,
Body: "Comment without any attachment",
Token: "not a good token",
})
require.Error(t, err)
}