apidae 1.3.18 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,164 @@ require 'test_helper'
3
3
  module Apidae
4
4
  class ObjTest < ActiveSupport::TestCase
5
5
 
6
- test "populate empty booking desc" do
7
- objects_json = File.read('test/data/hot_fr_en.json')
6
+ test 'populate empty booking desc' do
7
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
8
+
9
+ assert_nil obj.booking_desc
10
+ end
11
+
12
+ test 'archive short_desc previous value' do
13
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
14
+
15
+ obj.short_desc = 'short desc fr modif'
16
+
17
+ assert obj.save
18
+ assert_equal({'fr' => {'prev' => 'short desc fr', 'ts' => Time.current.to_i}}, obj.prev_data['short_desc'])
19
+ end
20
+
21
+ test 'archive short_desc localized previous value' do
22
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR, Apidae::LOCALE_EN])
23
+
24
+ obj.set_short_desc('fr' => 'short desc fr modif', 'en' => 'short desc en modif')
25
+
26
+ assert obj.save
27
+ assert_equal({
28
+ 'fr' => {'prev' => 'short desc fr', 'ts' => Time.current.to_i},
29
+ 'en' => {'prev' => 'short desc en', 'ts' => Time.current.to_i}
30
+ }, obj.prev_data['short_desc'])
31
+ end
32
+
33
+ test 'archive existing telephone value' do
34
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
35
+
36
+ obj.telephone['36504392']['value'] = '01 02 03 04 05'
37
+ obj.save
38
+
39
+ assert_equal({'36504392' => { 'prev' => { 'value' => '04 71 49 09 09', 'description' => nil}, 'ts' => Time.current.to_i}}, obj.prev_data['telephone'])
40
+ end
41
+
42
+ test 'archive email addition' do
43
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
44
+
45
+ obj.email['99999999'] = {'value' => '01 02 03 04 05', 'description' => nil}
46
+ obj.save
47
+
48
+ assert_equal({'36504394' => {'prev' => {"value" => "chatelleraie@wanadoo.fr", "description" => nil}, 'ts' => Time.current.to_i}}, obj.prev_data['email'])
49
+ end
50
+
51
+ test 'archive address value' do
52
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
53
+
54
+ obj.address = ['Test', "Château de La Devèze", nil]
55
+ obj.save
56
+
57
+ assert_equal({'prev' => [nil, "Château de La Devèze", nil], 'ts' => Time.current.to_i}, obj.prev_data['address'])
58
+ end
59
+
60
+ test 'archive geolocation value' do
61
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
62
+
63
+ obj.latitude = 1.2345
64
+ obj.save
65
+
66
+ assert_equal({'prev' => 44.715026, 'ts' => Time.current.to_i}, obj.prev_data['latitude'])
67
+ end
68
+
69
+ test 'archive references list update' do
70
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
71
+
72
+ obj.services -= [1115]
73
+ obj.equipments += [1059]
74
+ obj.save
75
+
76
+ assert_equal({'prev' => [687, 1115, 1172], 'ts' => Time.current.to_i}, obj.prev_data['services'])
77
+ assert_equal({'prev' => [655, 723, 821, 972, 1058, 1064, 1089, 1093, 1106, 1323], 'ts' => Time.current.to_i}, obj.prev_data['equipments'])
78
+ end
79
+
80
+ test 'archive contacts list update' do
81
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
82
+
83
+ obj.contacts[0]['nom'] = 'test'
84
+ obj.save
85
+
86
+ assert_equal({'prev' => [12954222], 'ts' => Time.current.to_i}, obj.prev_data['contacts'])
87
+ end
88
+
89
+ test 'archive openings list update' do
90
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
91
+
92
+ obj.openings += [{"id" => 123456, "start_date" => "2018-04-01", "end_date" => "2018-10-14"}]
93
+ obj.save
94
+
95
+ assert_equal({'prev' => [14375379], 'ts' => Time.current.to_i}, obj.prev_data['openings'])
96
+ end
97
+
98
+ test 'archive rates list update' do
99
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
100
+
101
+ obj.rates += [{"id" => 123456, "start_date" => "2018-04-01", "end_date" => "2018-10-14"}]
102
+ obj.save
103
+
104
+ assert_equal({'prev' => [8605788], 'ts' => Time.current.to_i}, obj.prev_data['rates'])
105
+ end
106
+
107
+ test 'archive pictures list update' do
108
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
109
+
110
+ obj.pictures.delete_if {|p| p['id'] == 1890699}
111
+ obj.save
112
+
113
+ assert_equal({'fr' => {'prev' => [1890696, 1890697, 1890698, 1890699, 1890700, 1890701, 1890702, 1890703, 1890704, 1890705, 1890706], 'ts' => Time.current.to_i}}, obj.prev_data['pictures'])
114
+ end
115
+
116
+ test 'archive capacity field update' do
117
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
118
+
119
+ obj.capacity['nombreChambresFamiliales'] = 2
120
+ obj.save
121
+
122
+ assert_equal({'prev' => 1, 'ts' => Time.current.to_i}, obj.prev_data['capacity']['nombreChambresFamiliales'])
123
+ end
124
+
125
+ test 'archive versioned short_desc field update' do
126
+ obj = setup_obj('test/data/cos_winter.json', [Apidae::LOCALE_FR], [Apidae::STANDARD_VERSION, Apidae::WINTER_VERSION])
127
+
128
+ obj = obj.in_version(Apidae::WINTER_VERSION)
129
+ obj.short_desc = 'short desc winter fr modif'
130
+ obj.save
131
+
132
+ assert_equal({'fr' => {'prev' => 'short desc winter fr', 'ts' => Time.current.to_i}}, obj.prev_data['short_desc'])
133
+ end
134
+
135
+ test 'archive versioned localized short_desc field update' do
136
+ obj = setup_obj('test/data/cos_winter.json', [Apidae::LOCALE_FR, Apidae::LOCALE_DE], [Apidae::STANDARD_VERSION, Apidae::WINTER_VERSION])
137
+
138
+ obj = obj.in_version(Apidae::WINTER_VERSION).in_locale(Apidae::LOCALE_DE)
139
+ obj.short_desc = 'short desc winter de modif'
140
+ obj.save
141
+
142
+ assert_equal({'prev' => 'short desc standard de', 'ts' => Time.current.to_i}, obj.prev_data['short_desc']['de'])
143
+ end
144
+
145
+ test 'archive type_data subfield without updating others' do
146
+ obj = setup_obj('test/data/hot_fr_en.json', [Apidae::LOCALE_FR])
147
+
148
+ obj.categories -= [1610]
149
+ obj.save
150
+
151
+ assert_nil(obj.prev_data['capacity'])
152
+ end
153
+
154
+ private
155
+
156
+ def setup_obj(json_file, locales, versions = nil)
157
+ objects_json = File.read(json_file)
8
158
  obj_data = JSON.parse(objects_json, symbolize_names: true).first
9
159
 
10
160
  obj = Apidae::Obj.new
11
- Apidae::Obj.populate_fields(obj, obj_data, [Apidae::LOCALE_FR])
12
-
13
- assert_nil obj.booking_desc
161
+ Apidae::Obj.update_object(obj, obj_data, locales, versions)
162
+ obj.save
163
+ obj
14
164
  end
15
165
  end
16
166
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.18
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-16 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -191,6 +191,7 @@ files:
191
191
  - db/migrate/20200528101957_add_is_active_to_apidae_references.rb
192
192
  - db/migrate/20201112080847_create_apidae_territories.rb
193
193
  - db/migrate/20210607214647_add_apidae_type_to_apidae_territories.rb
194
+ - db/migrate/20230206113335_add_prev_data_to_apidae_objs.rb
194
195
  - lib/apidae.rb
195
196
  - lib/apidae/engine.rb
196
197
  - lib/apidae/version.rb