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.
- checksums.yaml +4 -4
- data/bin/opencode +2 -2
- data/lib/opencode_theme.rb +3 -7
- data/lib/opencode_theme/base_service.rb +43 -22
- data/lib/opencode_theme/cli.rb +172 -155
- data/lib/opencode_theme/version.rb +1 -1
- data/opencode_theme.gemspec +7 -3
- data/spec/cassettes_local/bootstrap/valid.yml +4252 -0
- data/spec/cassettes_local/clean/invalid.yml +36 -0
- data/spec/cassettes_local/components/list.yml +1881 -0
- data/spec/cassettes_local/configure/invalid2.yml +36 -0
- data/spec/cassettes_local/configure/invalid3.yml +36 -0
- data/spec/cassettes_local/configure/valid.yml +36 -0
- data/spec/cassettes_local/delete/valid.yml +36 -0
- data/spec/cassettes_local/download/valid_single.yml +39 -0
- data/spec/cassettes_local/download/valid_theme.yml +4182 -0
- data/spec/cassettes_local/list/invalid.yml +36 -0
- data/spec/cassettes_local/list/valid.yml +297 -0
- data/spec/cassettes_local/process_install/download.yml +221 -0
- data/spec/cassettes_local/subject/valid.yml +38 -0
- data/spec/cassettes_local/units/components/list.yml +298 -0
- data/spec/cassettes_local/units/components/list_tag/wrong.yml +65 -0
- data/spec/cassettes_local/upload/valid_single.yml +39 -0
- data/spec/cassettes_local/upload/valid_theme.yml +4035 -0
- data/spec/functional/functional_spec.rb +168 -85
- data/spec/spec_helper.rb +6 -0
- data/spec/unit/components/install_spec.rb +55 -0
- data/spec/unit/components/list_spec.rb +29 -0
- data/spec/unit/components/process_install_spec.rb +28 -0
- metadata +79 -3
@@ -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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
@@ -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
|
+
|