@@ -61,3 +61,56 @@ func TestBranch_PromoteCmd(t *testing.T) {
6161 c .Assert (svc .PromoteFnInvoked , qt .IsTrue )
6262 c .Assert (buf .String (), qt .JSONEquals , res )
6363}
64+
65+ func TestBranch_PromoteCmd_ServiceTokenPermissionError (t * testing.T ) {
66+ c := qt .New (t )
67+
68+ var buf bytes.Buffer
69+ format := printer .JSON
70+ p := printer .NewPrinter (& format )
71+ p .SetResourceOutput (& buf )
72+
73+ org := "planetscale"
74+ db := "planetscale"
75+ branch := "development"
76+
77+ // Mock service that returns 404 for branch promotion
78+ branchSvc := & mock.DatabaseBranchesService {
79+ PromoteFn : func (ctx context.Context , req * ps.PromoteRequest ) (* ps.DatabaseBranch , error ) {
80+ return nil , & ps.Error {Code : ps .ErrNotFound }
81+ },
82+ }
83+
84+ // Mock organization service that succeeds (simulating valid service token)
85+ orgSvc := & mock.OrganizationsService {
86+ ListFn : func (ctx context.Context ) ([]* ps.Organization , error ) {
87+ return []* ps.Organization {{Name : org }}, nil
88+ },
89+ }
90+
91+ ch := & cmdutil.Helper {
92+ Printer : p ,
93+ Config : & config.Config {
94+ Organization : org ,
95+ ServiceTokenID : "valid-token-id" ,
96+ ServiceToken : "valid-token" ,
97+ },
98+ Client : func () (* ps.Client , error ) {
99+ return & ps.Client {
100+ DatabaseBranches : branchSvc ,
101+ Organizations : orgSvc ,
102+ }, nil
103+ },
104+ }
105+
106+ cmd := PromoteCmd (ch )
107+ cmd .SetArgs ([]string {db , branch })
108+ err := cmd .Execute ()
109+
110+ c .Assert (err , qt .IsNotNil )
111+ c .Assert (err .Error (), qt .Contains , "does not exist" )
112+ c .Assert (err .Error (), qt .Contains , "service token for authentication" )
113+ c .Assert (err .Error (), qt .Contains , "connect_production_branch" )
114+ c .Assert (branchSvc .PromoteFnInvoked , qt .IsTrue )
115+ c .Assert (orgSvc .ListFnInvoked , qt .IsTrue )
116+ }
0 commit comments