opencode_theme 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,9 @@ require_relative '../spec_helper'
3
3
  describe OpencodeTheme::Cli, :functional do
4
4
  STORE_ID = '430692'
5
5
  FILE_NAME = 'layouts/default.html'
6
- API_KEY = 'abe14f7154762dd43c3e499bab004abd'
7
- PASSWORD = '2ff62ce74b4d9b7da6e09e1a7d0767c7'
8
6
  THEME_NAME = 'TA Test Theme'
7
+ API_KEY = '87da1d507c775c346275861e7a1891b3'
8
+ PASSWORD = '19909a6b50ca912afd4daf3a70025624'
9
9
 
10
10
  before(:all) do
11
11
  # clearing generated and downloaded files
@@ -14,98 +14,123 @@ describe OpencodeTheme::Cli, :functional do
14
14
  end
15
15
 
16
16
  after(:all) do
17
- # deleting created theme
18
- FileUtils.cd THEME_NAME
19
- config = YAML.load_file 'config.yml'
20
- res = OpencodeTheme.theme_delete(config[:theme_id])
21
- if res[:success]
22
- puts " deleted theme #{config[:theme_id]}"
23
- else
24
- puts " THEME #{config[:theme_id]} NOT DELETED! DELETE MANUALLY!"
25
- end
26
- FileUtils.cd '..'
27
- # clearing generated and downloaded files
28
- FileUtils.rm_rf 'config.yml'
29
- FileUtils.rm_rf THEME_NAME
17
+ VCR.use_cassette("delete/valid") do
18
+ # deleting created theme
19
+ FileUtils.cd THEME_NAME if File.exist?(THEME_NAME)
20
+ config = YAML.load_file 'config.yml' if File.exist?('config.yml')
21
+ if config || THEME_NAME
22
+ res = OpencodeTheme.theme_delete(config[:theme_id])
23
+ if res[:success]
24
+ puts " deleted theme #{config[:theme_id]}"
25
+ else
26
+ puts " THEME #{config[:theme_id]} NOT DELETED! DELETE MANUALLY!"
27
+ end
28
+ FileUtils.cd '..'
29
+ # clearing generated and downloaded files
30
+ FileUtils.rm_rf 'config.yml' if File.exist?('config.yml')
31
+ FileUtils.rm_rf THEME_NAME if File.exist?(THEME_NAME)
32
+ end
33
+ end
30
34
  end
31
35
 
32
36
  context 'Invalid or Inexistent Configuration' do
33
37
  it 'does not list when the config is invalid' do
34
- output = capture(:stdout) { subject.list }
35
- expect(File.exist? 'config.yml').to eq false
36
- expect(output).to include 'config.yml does not exist!'
37
- expect(output).to include 'Error: Configuration [FAIL]'
38
- expect(output).to include 'Error Details: necessário autenticação'
38
+ VCR.use_cassette("list/invalid") do
39
+ output = capture(:stdout) { subject.list }
40
+ expect(File.exist? 'config.yml').to eq false
41
+ expect(output).to include 'config.yml does not exist!'
42
+ expect(output).to include 'Error: Configuration [FAIL]'
43
+ expect(output).to include 'Error Details: necessário autenticação'
44
+ end
39
45
  end
40
46
 
41
47
  it 'does not clean cache when the config is invalid' do
42
- output = capture(:stdout) { subject.clean }
43
- expect(File.exist? 'config.yml').to eq false
44
- expect(output).to include 'Clean cache [FAIL]'
48
+ VCR.use_cassette("clean/invalid") do
49
+ output = capture(:stdout) { subject.clean }
50
+ expect(File.exist? 'config.yml').to eq false
51
+ expect(output).to include 'Clean cache [FAIL]'
52
+ end
45
53
  end
46
54
 
47
55
  it 'does not upload any file when the config is invalid' do
48
- output = capture(:stdout) { subject.upload }
49
- expect(output).not_to include 'Uploaded'
50
- expect(output).to include 'Done.'
56
+ VCR.use_cassette("upload/invalid") do
57
+ output = capture(:stdout) { subject.upload }
58
+ expect(output).not_to include 'Uploaded'
59
+ expect(output).to include 'Done.'
60
+ end
51
61
  end
52
62
  end
53
63
 
54
64
  context 'Configure' do
55
65
  it 'fails to create config.yml file when called with no arguments' do
56
- output = capture(:stdout) { subject.configure }
57
- expect(output).to include 'Configuration [FAIL]'
58
- expect(File.exist? 'config.yml').to eq false
66
+ VCR.use_cassette("configure/invalid1") do
67
+ output = capture(:stdout) { subject.configure }
68
+ expect(output).to include 'Configuration [FAIL]'
69
+ expect(File.exist? 'config.yml').to eq false
70
+ end
59
71
  end
60
72
 
61
73
  it 'fails to create config.yml file when called with inexistent theme_id' do
62
- output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 214_748_364_7 }
63
- expect(output).to include 'Configuration [FAIL]'
64
- expect(File.exist? 'config.yml').to eq false
74
+ VCR.use_cassette("configure/invalid2") do
75
+ output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 214_748_364_7 }
76
+ expect(output).to include 'Configuration [FAIL]'
77
+ expect(File.exist? 'config.yml').to eq false
78
+ end
65
79
  end
66
80
 
67
81
  it 'fails to create config.yml file when called with invalid theme_id' do
68
- output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 'aaa' }
69
- expect(output).to include 'Configuration [FAIL]'
70
- expect(File.exist? 'config.yml').to eq false
82
+ VCR.use_cassette("configure/invalid3") do
83
+ output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 'aaa' }
84
+ expect(output).to include 'Configuration [FAIL]'
85
+ expect(File.exist? 'config.yml').to eq false
86
+ end
71
87
  end
72
88
 
73
89
  it 'creates config.yml when called with valid theme_id' do
74
- output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 1 }
75
- expect(output).to include 'Configuration [OK]'
76
- expect(File.exist? 'config.yml').to eq true
90
+ VCR.use_cassette("configure/valid") do
91
+ output = capture(:stdout) { subject.configure API_KEY, PASSWORD, 233 }
92
+ expect(output).to include 'Configuration [OK]'
93
+ expect(File.exist? 'config.yml').to eq true
94
+ end
77
95
  end
78
96
  end
79
97
 
80
98
  context 'Bootstrap' do
81
99
  it 'create new theme' do
82
- output = capture(:stdout) { subject.bootstrap API_KEY, PASSWORD, THEME_NAME }
83
- FileUtils.cd '..'
84
- expect(output).to include 'Configuration [OK]'
85
- expect(output).to include "Create #{THEME_NAME} theme on store"
86
- expect(output).to include "Saving configuration to #{THEME_NAME}"
87
- expect(output).to include "Downloading #{THEME_NAME} assets from Opencode"
88
- expect(output).to include "Downloaded: #{FILE_NAME}"
89
- expect(output).to include 'Done.'
100
+
101
+ VCR.use_cassette("bootstrap/valid") do
102
+ output = capture(:stdout) { subject.bootstrap API_KEY, PASSWORD, THEME_NAME }
103
+ FileUtils.cd '..'
104
+ expect(output).to include 'Configuration [OK]'
105
+ expect(output).to include "Create #{THEME_NAME} theme on store"
106
+ expect(output).to include "Saving configuration to #{THEME_NAME}"
107
+ expect(output).to include "Downloading #{THEME_NAME} assets from Opencode"
108
+ expect(output).to include "Downloaded: #{FILE_NAME}"
109
+ expect(output).to include 'Done.'
110
+ end
90
111
  end
91
112
  end
92
113
 
93
114
  context 'List' do
94
115
  it 'lists all the themes from the store' do
95
- output = capture(:stdout) { subject.list }
96
- expect(output).to include 'Theme name:'
97
- expect(output).to include 'Theme ID:'
98
- expect(output).to include 'Theme status:'
116
+ VCR.use_cassette("list/valid") do
117
+ output = capture(:stdout) { subject.list }
118
+ expect(output).to include 'Theme name:'
119
+ expect(output).to include 'Theme ID:'
120
+ expect(output).to include 'Theme status:'
121
+ end
99
122
  end
100
123
  end
101
124
 
102
125
  context 'Cleaning cache' do
103
126
  it 'cleans the cache' do
104
- expect(File.exist? THEME_NAME).to eq true
105
- FileUtils.cd THEME_NAME
106
- output = capture(:stdout) { subject.clean }
107
- FileUtils.cd '..'
108
- expect(output).to include 'Clean cache [OK]'
127
+ VCR.use_cassette("subject/valid") do
128
+ expect(File.exist? THEME_NAME).to eq true
129
+ FileUtils.cd THEME_NAME
130
+ output = capture(:stdout) { subject.clean }
131
+ FileUtils.cd '..'
132
+ expect(output).to include 'Clean cache [OK]'
133
+ end
109
134
  end
110
135
  end
111
136
 
@@ -113,52 +138,60 @@ describe OpencodeTheme::Cli, :functional do
113
138
  it 'downloads all files' do
114
139
  expect(File.exist? THEME_NAME).to eq true
115
140
  FileUtils.cd THEME_NAME
116
- output = capture(:stdout) { subject.download }
117
- FileUtils.cd '..'
118
- expect(output).to include 'Downloaded'
119
- expect(output).to include "Downloaded: #{FILE_NAME}"
120
- expect(output).not_to include 'Error'
121
- expect(output).not_to include 'Net::ReadTimeout'
122
- expect(output).to include 'Done.'
141
+
142
+ VCR.use_cassette("download/valid_theme") do
143
+ output = capture(:stdout) { subject.download }
144
+ FileUtils.cd '..'
145
+ expect(output).to include 'Downloaded'
146
+ expect(output).to include "Downloaded: #{FILE_NAME}"
147
+ expect(output).not_to include 'Error'
148
+ expect(output).not_to include 'Net::ReadTimeout'
149
+ expect(output).to include 'Done.'
150
+ end
123
151
  end
124
152
 
125
153
  it 'downloads a single file' do
126
- expect(File.exist? THEME_NAME).to eq true
127
- FileUtils.cd THEME_NAME
128
- output = capture(:stdout) { subject.download FILE_NAME }
129
- FileUtils.cd '..'
130
- expect(output).to include "Downloaded: #{FILE_NAME}"
131
- expect(output).to include 'Done.'
132
- expect(output).not_to include 'Error'
154
+ VCR.use_cassette("download/valid_single") do
155
+ expect(File.exist? THEME_NAME).to eq true
156
+ FileUtils.cd THEME_NAME
157
+ output = capture(:stdout) { subject.download FILE_NAME }
158
+ require 'pry'; binding.pry
159
+ FileUtils.cd '..'
160
+ expect(output).to include "Downloaded: #{FILE_NAME}"
161
+ expect(output).to include 'Done.'
162
+ expect(output).not_to include 'Error'
163
+ end
133
164
  end
134
165
  end
135
166
 
136
167
  context 'Upload' do
137
168
  it 'uploads all files' do
138
- expect(File.exist? THEME_NAME).to eq true
139
- FileUtils.cd THEME_NAME
140
-
141
- output = capture(:stdout) { subject.upload }
142
- FileUtils.cd '..'
143
- expect(output).to include "File uploaded: #{FILE_NAME}"
144
- expect(output).to include 'Done.'
145
- expect(output).not_to include 'Error'
169
+ VCR.use_cassette("upload/valid_theme") do
170
+ expect(File.exist? THEME_NAME).to eq true
171
+ FileUtils.cd THEME_NAME
172
+ output = capture(:stdout) { subject.upload }
173
+ FileUtils.cd '..'
174
+ expect(output).to include "File uploaded: #{FILE_NAME}"
175
+ expect(output).to include 'Done.'
176
+ expect(output).not_to include 'Error'
177
+ end
146
178
  end
147
179
 
148
180
  it 'uploads a single file' do
149
- expect(File.exist? THEME_NAME).to eq true
150
- FileUtils.cd THEME_NAME
151
- output = capture(:stdout) { subject.upload FILE_NAME }
152
- FileUtils.cd '..'
153
- expect(output).to include "File uploaded: #{FILE_NAME}"
154
- expect(output).to include 'Done.'
155
- expect(output).not_to include 'Error'
181
+ VCR.use_cassette("upload/valid_single") do
182
+ expect(File.exist? THEME_NAME).to eq true
183
+ FileUtils.cd THEME_NAME
184
+ output = capture(:stdout) { subject.upload FILE_NAME }
185
+ FileUtils.cd '..'
186
+ expect(output).to include "File uploaded: #{FILE_NAME}"
187
+ expect(output).to include 'Done.'
188
+ expect(output).not_to include 'Error'
189
+ end
156
190
  end
157
191
  end
158
192
 
159
193
  context 'System Information' do
160
194
  let(:output) { capture(:stdout) { subject.systeminfo } }
161
-
162
195
  it 'displays system information' do
163
196
  expect(output).not_to be_nil
164
197
  end
@@ -181,4 +214,54 @@ describe OpencodeTheme::Cli, :functional do
181
214
  expect(output).to include 'watch'
182
215
  end
183
216
  end
217
+
218
+ # context 'Components list' do
219
+ # it 'displays help about each command' do
220
+ # VCR.use_cassette("components/list/valid") do
221
+ # output = capture(:stdout) { subject.components 'list' }
222
+ # expect(output).to include 'Nome:'
223
+ # end
224
+ # end
225
+ # it 'displays help about each command' do
226
+ # VCR.use_cassette("components/list/valid") do
227
+ # output = capture(:stdout) { subject.components 'list' }
228
+ # expect(output).to include 'Descrição do projeto:'
229
+ # end
230
+ # end
231
+ # end
232
+
233
+ # context 'Components install variants' do
234
+ # it 'return sucess to install variants from github central of tray' do
235
+ # VCR.use_cassette("components/install/tray/variants") do
236
+ # FileUtils.cd THEME_NAME
237
+ # output = capture(:stdout) { subject.components 'install', 'variants' }
238
+ # expect(output).to include 'downloading...'
239
+ # expect(output).to include 'componente: opencode-components-variants'
240
+ # expect(output).to include 'extraindo arquivos...'
241
+ # end
242
+ # end
243
+
244
+ # it 'return success to install variants from user' do
245
+ # VCR.use_cassette("components/install/user/variants") do
246
+ # output = capture(:stdout) { subject.components 'install', 'variants', 'viniciustorves' }
247
+ # expect(output).to include 'downloading...'
248
+ # expect(output).to include 'componente: opencode-components-variants'
249
+ # expect(output).to include 'extraindo arquivos...'
250
+ # end
251
+ # end
252
+ # end
253
+
254
+ # context 'when exist manifest file' do
255
+ # it 'return success to repos exist' do
256
+ # opencode = { 'components' => { 'tray' => ['variants'], 'github'=> { 'viniciustorves' => 'variants' } } }
257
+ # File.open("opencode.yml", 'w+b') { |f| f.write opencode.to_yaml }
258
+ # VCR.use_cassette("components/install/components/manifest", :match_requests_on => [:host, :path]) do
259
+ # output = capture(:stdout) { subject.components_install }
260
+ # expect(output).to include 'downloading...'
261
+ # expect(output).to include 'componente: opencode-components-variants'
262
+ # expect(output).to include 'extraindo arquivos...'
263
+ # end
264
+ # end
265
+ # end
184
266
  end
267
+
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require 'rspec'
2
2
  require 'opencode_theme'
3
3
  require 'opencode_theme/cli'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |config|
7
+ config.cassette_library_dir = "spec/cassettes_local"
8
+ config.hook_into :webmock
9
+ end
4
10
 
5
11
  def capture(stream)
6
12
  begin
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Install, 'OpencodeTheme::Install' do
4
+
5
+ let(:install) { Install }
6
+
7
+ describe '#install_component' do
8
+ context 'when not exist valid params' do
9
+ it 'return nil to invalid' do
10
+ expect(install.install_component).to be_nil
11
+ end
12
+ it 'return array with opencode-components-variants to valid' do
13
+ VCR.use_cassette('units/components/list') do
14
+ expect(install.install_component('variants')).to eq ({:success=>true, :files=>["js/", "js/module/", "js/module/variants.js"]})
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#check_tag_install' do
21
+ context 'when not exist valid params' do
22
+ it 'return nil to invalid' do
23
+ VCR.use_cassette('units/components/list_tag/wrong') do
24
+ expect { install.check_tag_install('wrong', 'wrong') }.to raise_error StandardError, /404 - Not Found/
25
+ end
26
+ end
27
+ it 'return array with opencode-components-variants to valid' do
28
+ VCR.use_cassette('units/components/list') do
29
+ expect(install.install_component('variants')).to eq ({:success=>true, :files=>["js/", "js/module/", "js/module/variants.js"]})
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#install_component_from_url' do
36
+ context 'when not valid zip_component' do
37
+ it 'return nil' do
38
+ expect(install.install_component_from_url({ wrong: 'wrong'})).to be_nil
39
+ end
40
+ end
41
+ # pending 'Not implemented'
42
+ end
43
+
44
+ describe '#notice_invalid_name' do
45
+ context 'when not exist valid params' do
46
+ let(:output) { capture(:stdout) { install.notice_invalid_name } }
47
+ it 'return nil to invalid' do
48
+ expect(install.notice_invalid_name).to be_nil
49
+ end
50
+ it 'return message to user of invalid component' do
51
+ expect(output).to include('Use o comando: opencode component list')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe List, 'OpencodeTheme::List' do
4
+
5
+ let(:list) { List }
6
+ describe '#list' do
7
+ context 'when exist in github list' do
8
+ it 'return list of repos' do
9
+ VCR.use_cassette("components/list") do
10
+ expect(list.list_repos.body.class).to eq(Array)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ describe '#list_components' do
17
+ let(:response_body) { List.list_components }
18
+ context 'when exist' do
19
+ it 'return list' do
20
+ VCR.use_cassette("components/list") do
21
+ output = capture(:stdout) { response_body }
22
+ expect(output).to include "Nome:"
23
+ expect(output).to include "Descrição do projeto:"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ProcessInstall, 'OpencodeTheme::ProcessInstall' do
4
+
5
+ let(:process_install) { ProcessInstall }
6
+
7
+ describe '#tempfolder' do
8
+ context 'when component name be valid' do
9
+ it 'return success' do
10
+ expect(process_install.tempfolder('xpto')).to eq ('xpto')
11
+ end
12
+ end
13
+ end
14
+
15
+ describe '#download' do
16
+ context 'when exist zip_component' do
17
+ let(:zip_component) { { name: "opencode-components-variants",
18
+ version: 'v0.1',
19
+ zip: "https://api.github.com/repos/viniciustorves/opencode-components-variants/zipball/v0.1" } }
20
+ it 'return folder that be removed after download' do
21
+ VCR.use_cassette('process_install/download') do
22
+ expect(process_install.download(zip_component)).to eq(['opencode-components-variants'])
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+