-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebex_test.go
More file actions
159 lines (138 loc) · 4.82 KB
/
webex_test.go
File metadata and controls
159 lines (138 loc) · 4.82 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* SPDX-License-Identifier: MPL-2.0
* Copyright 2025 Tejus Pratap <tejzpr@gmail.com>
*
* See CONTRIBUTORS.md for full contributor list.
*/
package webex
import (
"testing"
"github.com/WebexCommunity/webex-go-sdk/v2/conversation"
"github.com/WebexCommunity/webex-go-sdk/v2/webexsdk"
)
func TestConversationReturnsSingletonWhenCached(t *testing.T) {
// Create a client with a valid token
client, err := NewClient("test-token", nil)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Pre-populate the conversationClient to simulate a previous successful init
core, _ := webexsdk.NewClient("test-token", nil)
preWired := conversation.New(core, nil)
client.conversationClient = preWired
// Subsequent calls should return the cached instance without error
result, err := client.Conversation()
if err != nil {
t.Fatalf("Expected no error from cached Conversation(), got: %v", err)
}
if result != preWired {
t.Error("Expected Conversation() to return the cached singleton instance")
}
// Call again to verify idempotency
result2, err := client.Conversation()
if err != nil {
t.Fatalf("Expected no error from second Conversation() call, got: %v", err)
}
if result2 != result {
t.Error("Expected repeated Conversation() calls to return the same instance")
}
}
func TestConversationReturnsErrorOnDeviceRegistrationFailure(t *testing.T) {
// Create a client with a dummy token -- device registration will fail
// because it can't reach the real WDM service
client, err := NewClient("invalid-token-for-testing", nil)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Conversation() should return a meaningful error wrapping device failure
_, err = client.Conversation()
if err == nil {
t.Fatal("Expected error from Conversation() when device registration fails")
}
// Verify the error mentions device registration
if got := err.Error(); got == "" {
t.Error("Expected non-empty error message")
}
}
func TestConversationConnectErrorsWithoutMercury(t *testing.T) {
// Create a bare conversation client with no mercury wired
core, _ := webexsdk.NewClient("test-token", nil)
convClient := conversation.New(core, nil)
// Connect should fail because no mercury client is set
err := convClient.Connect()
if err == nil {
t.Fatal("Expected error from Connect() without mercury client")
}
}
func TestConversationDisconnectErrorsWithoutMercury(t *testing.T) {
// Create a bare conversation client with no mercury wired
core, _ := webexsdk.NewClient("test-token", nil)
convClient := conversation.New(core, nil)
// Disconnect should fail because no mercury client is set
err := convClient.Disconnect()
if err == nil {
t.Fatal("Expected error from Disconnect() without mercury client")
}
}
func TestConversationConnectDelegatesToMercury(t *testing.T) {
// Create a conversation client and wire a mercury client (no device provider)
client, err := NewClient("test-token", nil)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
core, _ := webexsdk.NewClient("test-token", nil)
convClient := conversation.New(core, nil)
convClient.SetMercuryClient(client.Mercury())
// Connect will fail because mercury has no device provider with a valid URL,
// but the key assertion is that it does NOT return the "mercury client not set" error
err = convClient.Connect()
if err == nil {
t.Fatal("Expected error from Connect() (no device registration)")
}
// Verify it's a connection error, not a "mercury not set" error
if err.Error() == "mercury client not set; call SetMercuryClient or use the top-level webex.Client.Conversation() convenience method" {
t.Error("Connect() should delegate to mercury, not return 'not set' error")
}
}
func TestWebexClientAccessors(t *testing.T) {
client, err := NewClient("test-token", nil)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Verify Core() returns non-nil
if client.Core() == nil {
t.Error("Core() should not return nil")
}
// Verify lazy-init accessors return non-nil
if client.People() == nil {
t.Error("People() should not return nil")
}
if client.Messages() == nil {
t.Error("Messages() should not return nil")
}
if client.Rooms() == nil {
t.Error("Rooms() should not return nil")
}
if client.Mercury() == nil {
t.Error("Mercury() should not return nil")
}
if client.Device() == nil {
t.Error("Device() should not return nil")
}
if client.Meetings() == nil {
t.Error("Meetings() should not return nil")
}
if client.Transcripts() == nil {
t.Error("Transcripts() should not return nil")
}
// Verify Internal() returns populated struct
internal := client.Internal()
if internal == nil {
t.Fatal("Internal() should not return nil")
}
if internal.Mercury == nil {
t.Error("Internal().Mercury should not return nil")
}
if internal.Device == nil {
t.Error("Internal().Device should not return nil")
}
}