@@ -261,12 +261,16 @@ func TestGmailSendCmd_RunJSON_WithFrom(t *testing.T) {
261261 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
262262 path := strings .TrimPrefix (r .URL .Path , "/gmail/v1" )
263263 switch {
264- case r .Method == http .MethodGet && path == "/users/me/settings/sendAs/alias@example.com " :
264+ case r .Method == http .MethodGet && path == "/users/me/settings/sendAs" :
265265 w .Header ().Set ("Content-Type" , "application/json" )
266266 _ = json .NewEncoder (w ).Encode (map [string ]any {
267- "sendAsEmail" : "alias@example.com" ,
268- "displayName" : "Alias" ,
269- "verificationStatus" : "accepted" ,
267+ "sendAs" : []map [string ]any {
268+ {
269+ "sendAsEmail" : "alias@example.com" ,
270+ "displayName" : "Alias" ,
271+ "verificationStatus" : "accepted" ,
272+ },
273+ },
270274 })
271275 return
272276 case r .Method == http .MethodPost && path == "/users/me/messages/send" :
@@ -323,17 +327,8 @@ func TestGmailSendCmd_RunJSON_WithFromDisplayNameFallbackToList(t *testing.T) {
323327 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
324328 path := strings .TrimPrefix (r .URL .Path , "/gmail/v1" )
325329 switch {
326- case r .Method == http .MethodGet && path == "/users/me/settings/sendAs/alias@example.com" :
327- // Return send-as settings with empty display name but valid verification.
328- w .Header ().Set ("Content-Type" , "application/json" )
329- _ = json .NewEncoder (w ).Encode (map [string ]any {
330- "sendAsEmail" : "alias@example.com" ,
331- "displayName" : "" ,
332- "verificationStatus" : "accepted" ,
333- })
334- return
335330 case r .Method == http .MethodGet && path == "/users/me/settings/sendAs" :
336- // Fallback list endpoint returns the alias with a populated display name .
331+ // List endpoint provides verification + display name (works for service-account impersonation too) .
337332 w .Header ().Set ("Content-Type" , "application/json" )
338333 _ = json .NewEncoder (w ).Encode (map [string ]any {
339334 "sendAs" : []map [string ]any {
@@ -377,7 +372,7 @@ func TestGmailSendCmd_RunJSON_WithFromDisplayNameFallbackToList(t *testing.T) {
377372
378373 cmd := & GmailSendCmd {
379374 To : "a@example.com" ,
380- From : "alias@example.com" ,
375+ From : " alias@example.com " ,
381376 Subject : "Hello" ,
382377 Body : "Body" ,
383378 }
@@ -399,13 +394,18 @@ func TestGmailSendCmd_RunJSON_PrimaryAccountDisplayName(t *testing.T) {
399394 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
400395 path := strings .TrimPrefix (r .URL .Path , "/gmail/v1" )
401396 switch {
402- case r .Method == http .MethodGet && path == "/users/me/settings/sendAs/a@b.com " :
403- // Return send-as settings with display name for primary account
397+ case r .Method == http .MethodGet && path == "/users/me/settings/sendAs" :
398+ // List endpoint returns the primary entry with display name.
404399 w .Header ().Set ("Content-Type" , "application/json" )
405400 _ = json .NewEncoder (w ).Encode (map [string ]any {
406- "sendAsEmail" : "a@b.com" ,
407- "displayName" : "Primary User" ,
408- "verificationStatus" : "accepted" ,
401+ "sendAs" : []map [string ]any {
402+ {
403+ "sendAsEmail" : "a@b.com" ,
404+ "displayName" : "Primary User" ,
405+ "verificationStatus" : "accepted" ,
406+ "isPrimary" : true ,
407+ },
408+ },
409409 })
410410 return
411411 case r .Method == http .MethodPost && path == "/users/me/messages/send" :
@@ -463,21 +463,17 @@ func TestGmailSendCmd_RunJSON_PrimaryAccountDisplayNameFallbackToList(t *testing
463463 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
464464 path := strings .TrimPrefix (r .URL .Path , "/gmail/v1" )
465465 switch {
466- case r .Method == http .MethodGet && path == "/users/me/settings/sendAs/a@b.com" :
467- // Simulate missing display name in get response.
468- w .Header ().Set ("Content-Type" , "application/json" )
469- _ = json .NewEncoder (w ).Encode (map [string ]any {
470- "sendAsEmail" : "a@b.com" ,
471- "displayName" : "" ,
472- "verificationStatus" : "accepted" ,
473- })
474- return
475466 case r .Method == http .MethodGet && path == "/users/me/settings/sendAs" :
476467 w .Header ().Set ("Content-Type" , "application/json" )
477468 _ = json .NewEncoder (w ).Encode (map [string ]any {
478469 "sendAs" : []map [string ]any {
479470 {
480471 "sendAsEmail" : "a@b.com" ,
472+ "displayName" : "" ,
473+ "verificationStatus" : "accepted" ,
474+ },
475+ {
476+ "sendAsEmail" : "primary@example.com" ,
481477 "displayName" : "Primary User" ,
482478 "verificationStatus" : "accepted" ,
483479 "isPrimary" : true ,
@@ -661,11 +657,15 @@ func TestGmailSendCmd_Run_FromUnverified(t *testing.T) {
661657
662658 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
663659 path := strings .TrimPrefix (r .URL .Path , "/gmail/v1" )
664- if r .Method == http .MethodGet && path == "/users/me/settings/sendAs/alias@example.com " {
660+ if r .Method == http .MethodGet && path == "/users/me/settings/sendAs" {
665661 w .Header ().Set ("Content-Type" , "application/json" )
666662 _ = json .NewEncoder (w ).Encode (map [string ]any {
667- "sendAsEmail" : "alias@example.com" ,
668- "verificationStatus" : "pending" ,
663+ "sendAs" : []map [string ]any {
664+ {
665+ "sendAsEmail" : "alias@example.com" ,
666+ "verificationStatus" : "pending" ,
667+ },
668+ },
669669 })
670670 return
671671 }
0 commit comments