@@ -15,11 +15,13 @@ func TestArchive(t *testing.T) {
1515 mockClient := & resources.MockClient {
1616 Response : []byte (`{
1717 "key": "test-flag",
18- "name": "test flag"
18+ "name": "test flag",
19+ "kind": "boolean",
20+ "archived": true
1921 }` ),
2022 }
2123
22- t .Run ("succeeds with valid inputs " , func (t * testing.T ) {
24+ t .Run ("succeeds with plaintext output " , func (t * testing.T ) {
2325 args := []string {
2426 "flags" , "archive" ,
2527 "--access-token" , "abcd1234" ,
@@ -37,8 +39,122 @@ func TestArchive(t *testing.T) {
3739
3840 require .NoError (t , err )
3941 assert .Equal (t , `[{"op": "replace", "path": "/archived", "value": true}]` , string (mockClient .Input ))
40- assert .Equal (t , "Successfully updated test flag (test-flag)\n " , string (output ))
42+ assert .Contains (t , string (output ), "Successfully updated\n \n Key:" )
43+ assert .Contains (t , string (output ), "test-flag" )
44+ assert .Contains (t , string (output ), "Name:" )
45+ assert .Contains (t , string (output ), "test flag" )
46+ assert .NotContains (t , string (output ), "* " )
4147 })
48+
49+ t .Run ("succeeds with JSON output" , func (t * testing.T ) {
50+ args := []string {
51+ "flags" , "archive" ,
52+ "--access-token" , "abcd1234" ,
53+ "--flag" , "test-flag" ,
54+ "--project" , "test-proj" ,
55+ "--output" , "json" ,
56+ }
57+ output , err := cmd .CallCmd (
58+ t ,
59+ cmd.APIClients {
60+ ResourcesClient : mockClient ,
61+ },
62+ analytics.NoopClientFn {}.Tracker (),
63+ args ,
64+ )
65+
66+ require .NoError (t , err )
67+ assert .JSONEq (t , `{"key":"test-flag","name":"test flag","kind":"boolean","archived":true}` , string (output ))
68+ })
69+
70+ t .Run ("succeeds with --json shorthand" , func (t * testing.T ) {
71+ args := []string {
72+ "flags" , "archive" ,
73+ "--access-token" , "abcd1234" ,
74+ "--flag" , "test-flag" ,
75+ "--project" , "test-proj" ,
76+ "--json" ,
77+ }
78+ output , err := cmd .CallCmd (
79+ t ,
80+ cmd.APIClients {
81+ ResourcesClient : mockClient ,
82+ },
83+ analytics.NoopClientFn {}.Tracker (),
84+ args ,
85+ )
86+
87+ require .NoError (t , err )
88+ assert .JSONEq (t , `{"key":"test-flag","name":"test flag","kind":"boolean","archived":true}` , string (output ))
89+ })
90+
91+ t .Run ("filters JSON output with --fields" , func (t * testing.T ) {
92+ args := []string {
93+ "flags" , "archive" ,
94+ "--access-token" , "abcd1234" ,
95+ "--flag" , "test-flag" ,
96+ "--project" , "test-proj" ,
97+ "--output" , "json" ,
98+ "--fields" , "key,name" ,
99+ }
100+ output , err := cmd .CallCmd (
101+ t ,
102+ cmd.APIClients {
103+ ResourcesClient : mockClient ,
104+ },
105+ analytics.NoopClientFn {}.Tracker (),
106+ args ,
107+ )
108+
109+ require .NoError (t , err )
110+ assert .JSONEq (t , `{"key":"test-flag","name":"test flag"}` , string (output ))
111+ })
112+
113+ t .Run ("filters JSON output with --json and --fields" , func (t * testing.T ) {
114+ args := []string {
115+ "flags" , "archive" ,
116+ "--access-token" , "abcd1234" ,
117+ "--flag" , "test-flag" ,
118+ "--project" , "test-proj" ,
119+ "--json" ,
120+ "--fields" , "key,name" ,
121+ }
122+ output , err := cmd .CallCmd (
123+ t ,
124+ cmd.APIClients {
125+ ResourcesClient : mockClient ,
126+ },
127+ analytics.NoopClientFn {}.Tracker (),
128+ args ,
129+ )
130+
131+ require .NoError (t , err )
132+ assert .JSONEq (t , `{"key":"test-flag","name":"test flag"}` , string (output ))
133+ })
134+
135+ t .Run ("ignores --fields with plaintext output" , func (t * testing.T ) {
136+ args := []string {
137+ "flags" , "archive" ,
138+ "--access-token" , "abcd1234" ,
139+ "--flag" , "test-flag" ,
140+ "--project" , "test-proj" ,
141+ "--fields" , "key" ,
142+ }
143+ output , err := cmd .CallCmd (
144+ t ,
145+ cmd.APIClients {
146+ ResourcesClient : mockClient ,
147+ },
148+ analytics.NoopClientFn {}.Tracker (),
149+ args ,
150+ )
151+
152+ require .NoError (t , err )
153+ assert .Contains (t , string (output ), "Successfully updated" )
154+ assert .Contains (t , string (output ), "Key:" )
155+ assert .Contains (t , string (output ), "test-flag" )
156+ })
157+
42158 t .Run ("returns error with missing flags" , func (t * testing.T ) {
43159 args := []string {
44160 "flags" , "archive" ,
@@ -55,6 +171,6 @@ func TestArchive(t *testing.T) {
55171 )
56172
57173 assert .Error (t , err )
58- assert .Equal (t , " required flag(s) \ " project\ " not set. See `ldcli flags archive --help` for supported flags and usage." , err . Error () )
174+ assert .Contains (t , err . Error (), ` required flag(s) "project" not set` )
59175 })
60176}
0 commit comments