@@ -7,6 +7,98 @@ import (
77 "github.com/basecamp/fizzy-cli/internal/errors"
88)
99
10+ func TestIdentityTimezoneUpdate (t * testing.T ) {
11+ t .Run ("updates timezone" , func (t * testing.T ) {
12+ mock := NewMockClient ()
13+ mock .PatchResponse = & client.APIResponse {
14+ StatusCode : 200 ,
15+ Data : map [string ]any {
16+ "timezone_name" : "America/New_York" ,
17+ "updated_at" : "2026-06-03T21:15:00Z" ,
18+ },
19+ }
20+
21+ result := SetTestModeWithSDK (mock )
22+ SetTestConfig ("token" , "account" , "https://api.example.com" )
23+ identityTimezoneUpdateTimezone = "America/New_York"
24+ defer func () {
25+ identityTimezoneUpdateTimezone = ""
26+ resetTest ()
27+ }()
28+
29+ err := identityTimezoneUpdateCmd .RunE (identityTimezoneUpdateCmd , []string {})
30+ assertExitCode (t , err , 0 )
31+
32+ if err != nil {
33+ t .Fatalf ("unexpected error: %v" , err )
34+ }
35+ if len (mock .PatchCalls ) != 1 {
36+ t .Fatalf ("expected 1 patch call, got %d" , len (mock .PatchCalls ))
37+ }
38+ if mock .PatchCalls [0 ].Path != "/my/timezone.json" {
39+ t .Errorf ("expected path '/my/timezone.json', got %q" , mock .PatchCalls [0 ].Path )
40+ }
41+ body , ok := mock .PatchCalls [0 ].Body .(map [string ]any )
42+ if ! ok {
43+ t .Fatalf ("expected map body, got %#v" , mock .PatchCalls [0 ].Body )
44+ }
45+ if body ["timezone_name" ] != "America/New_York" {
46+ t .Errorf ("expected timezone_name body, got %#v" , body )
47+ }
48+ if result .Response .Summary != "Timezone updated" {
49+ t .Errorf ("expected timezone summary, got %q" , result .Response .Summary )
50+ }
51+ if got := responseDataMap (t , result )["updated_at" ]; got != "2026-06-03T21:15:00Z" {
52+ t .Errorf ("expected timezone response body updated_at, got %#v" , got )
53+ }
54+ })
55+
56+ t .Run ("falls back to requested timezone for empty response" , func (t * testing.T ) {
57+ mock := NewMockClient ()
58+ mock .PatchResponse = & client.APIResponse {StatusCode : 204 , Data : nil }
59+
60+ result := SetTestModeWithSDK (mock )
61+ SetTestConfig ("token" , "account" , "https://api.example.com" )
62+ identityTimezoneUpdateTimezone = "America/New_York"
63+ defer func () {
64+ identityTimezoneUpdateTimezone = ""
65+ resetTest ()
66+ }()
67+
68+ err := identityTimezoneUpdateCmd .RunE (identityTimezoneUpdateCmd , []string {})
69+ assertExitCode (t , err , 0 )
70+
71+ if got := responseDataMap (t , result )["timezone_name" ]; got != "America/New_York" {
72+ t .Errorf ("expected fallback timezone_name, got %#v" , got )
73+ }
74+ })
75+
76+ t .Run ("requires timezone" , func (t * testing.T ) {
77+ mock := NewMockClient ()
78+ SetTestModeWithSDK (mock )
79+ SetTestConfig ("token" , "account" , "https://api.example.com" )
80+ identityTimezoneUpdateTimezone = ""
81+ defer resetTest ()
82+
83+ err := identityTimezoneUpdateCmd .RunE (identityTimezoneUpdateCmd , []string {})
84+ assertExitCode (t , err , errors .ExitInvalidArgs )
85+ })
86+
87+ t .Run ("requires account" , func (t * testing.T ) {
88+ mock := NewMockClient ()
89+ SetTestModeWithSDK (mock )
90+ SetTestConfig ("token" , "" , "https://api.example.com" )
91+ identityTimezoneUpdateTimezone = "America/New_York"
92+ defer func () {
93+ identityTimezoneUpdateTimezone = ""
94+ resetTest ()
95+ }()
96+
97+ err := identityTimezoneUpdateCmd .RunE (identityTimezoneUpdateCmd , []string {})
98+ assertExitCode (t , err , errors .ExitInvalidArgs )
99+ })
100+ }
101+
10102func TestIdentityShow (t * testing.T ) {
11103 t .Run ("shows identity" , func (t * testing.T ) {
12104 mock := NewMockClient ()
0 commit comments