-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRakefile
88 lines (78 loc) · 3.26 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'colorize'
require 'algoliasearch'
require 'elasticsearch'
require 'json'
task :clear do
puts "\nClear partner generated from previous test\n".green
`psql -c "DELETE FROM shopinvader_partner WHERE record_id in (SELECT id FROM res_partner WHERE email ILIKE '%rspec%' OR name ILIKE '%RSPEC')"`
`psql -c "DELETE FROM res_partner WHERE email ILIKE '%rspec%' OR name ILIKE '%RSPEC'"`
end
task :export_algolia do
puts "\nExport Aloglia index\n".green
Algolia.init(application_id: ENV['ALGOLIA_APP_ID'], api_key: ENV['ALGOLIA_API_KEY'])
['ci_shopinvader_variant', 'ci_shopinvader_category'].each do | index_name |
['fr_FR', 'en_US'].each do | lang |
index_full_name = "#{index_name}_#{lang}"
puts "\nExport Aloglia index #{index_full_name}\n".green
index_out_name = index_full_name.sub('locomotive', 'ci').sub('product', 'variant')
index = Algolia::Index.new("#{index_full_name}")
records = []
index.browse do | record |
records << record
end
File.open("spec/integration/search-engine-data/#{index_out_name}.json","w") do |f|
f.write(JSON.pretty_generate(records))
end
setting = index.get_settings()
File.open("spec/integration/search-engine-data/#{index_out_name}_setting.json","w") do |f|
f.write(JSON.pretty_generate(setting))
end
end
end
end
task :configure_algolia do
puts "\nConfigure algolia indexes\n".green
Algolia.init(application_id: ENV['ALGOLIA_APP_ID'], api_key: ENV['ALGOLIA_API_KEY'])
['ci_shopinvader_variant', 'ci_shopinvader_category'].each do | index_name |
['fr_FR', 'en_US'].each do | lang |
index_full_name = "#{index_name}_#{lang}"
puts "\nConfigure Aloglia index #{index_full_name}\n".green
index = Algolia::Index.new("#{index_full_name}")
index.clear_index()
data = JSON.parse(File.read("spec/integration/data/#{index_full_name.downcase}.json"))
index.add_objects(data)
data = JSON.parse(File.read("spec/integration/data/#{index_name}_setting.json"))
index.set_settings(data)
end
end
end
task :configure_elastic do
puts "\nConfigure elastic indexes\n".green
`dockerize -timeout 180s -wait http://elastic:9200`
client = Elasticsearch::Client.new url: 'http://elastic:9200', log: true
['ci_shopinvader_variant', 'ci_shopinvader_category'].each do | index_name |
['fr_FR', 'en_US'].each do | lang |
index_full_name = "#{index_name}_#{lang}".downcase
puts "\nConfigure Elastic index #{index_full_name}\n".green
if client.indices.exists? index: index_full_name
client.indices.delete index: index_full_name
end
settings = JSON.parse(File.read("spec/integration/data/#{index_name}_elastic_setting.json"))
client.indices.create index: index_full_name, body: settings
data = JSON.parse(File.read("spec/integration/data/#{index_full_name}.json"))
body = []
data.each do | vals |
body << {index: { _index: index_full_name.downcase, _id: vals['id'], data: vals}}
end
client.bulk body: body
end
end
end
RSpec::Core::RakeTask.new(:spec) do
Rake::Task["clear"].invoke
Rake::Task["configure_algolia"].invoke
Rake::Task["configure_elastic"].invoke
end
task default: :spec