contentful-scheduler-custom 1.5.2 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f49b54660734e1d99de423774a5704df42900639
4
- data.tar.gz: dbefa3a1295ef8255342ae9de0a3b06f74c1f8d2
3
+ metadata.gz: e0b82b5e275d4c0dae01a44780318417ab6f87e3
4
+ data.tar.gz: 42719ffbdc3ccf8d5575b48142a715f4bb8c13d7
5
5
  SHA512:
6
- metadata.gz: 6ef18cffb5aa64b4e11884bba9f95f9bfc32e67c09038941fc0d624ba4f6e7acf166552ece511a1cb208ea41913e47b3686e6ee80bda233cf4f8331d5e63883f
7
- data.tar.gz: 4c56e55d8e087c7c8fb1f0615f07d3cc90fcbf089a0e5a23161d36c9f0d4e63ded599f69e49884202e0e029b12214cee6d906be569df7afe8726eec2c2203261
6
+ metadata.gz: 9a05d4921b687ca48b7e4cb52201756c227d736fa27bcc152b5f01b7eb7ed15a6da47df2b0ffe51eeccf52d9515bd1ae14fa4fc066f751cf7067829f67f00398
7
+ data.tar.gz: ad89cfde974e0ade192c67809a281cb59f03feee3b024db99155ad07dde51e178d54211f204cfcd3ae40952f4dac3abf5682a0a76722355f2211b9023ddd5182
@@ -20,7 +20,7 @@ module Contentful
20
20
  end
21
21
 
22
22
  if unpublishable?(webhook)
23
- success = update_or_create_for_unpublish(webhook) && success
23
+ success = update_or_create_for_unpublish(webhook)
24
24
  log_event_success(webhook, success, 'unpublish', 'added to')
25
25
  end
26
26
 
@@ -1,5 +1,5 @@
1
1
  module Contentful
2
2
  module Scheduler
3
- VERSION = "1.5.2"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
@@ -1,67 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- class WebhookDouble
4
- attr_reader :id, :space_id, :sys, :fields
5
- def initialize(id, space_id, sys = {}, fields = {})
6
- @id = id
7
- @space_id = space_id
8
- @sys = sys
9
- @fields = fields
10
- end
11
- end
12
-
13
3
  describe Contentful::Scheduler::Queue do
14
- let(:config) {
15
- {
16
- logger: ::Contentful::Scheduler::DEFAULT_LOGGER,
17
- endpoint: ::Contentful::Scheduler::DEFAULT_ENDPOINT,
18
- port: ::Contentful::Scheduler::DEFAULT_PORT,
19
- redis: {
20
- host: 'localhost',
21
- port: 12341,
22
- password: 'foobar'
23
- },
24
- spaces: {
25
- 'foo' => {
26
- publish_field: 'my_field',
27
- management_token: 'foo'
28
- }
29
- }
30
- }
31
- }
32
-
4
+ let(:config) { base_config }
33
5
  subject { described_class.instance }
34
6
 
35
7
  before :each do
36
8
  allow(Resque).to receive(:redis=)
37
9
  described_class.class_variable_set(:@@instance, nil)
38
- ::Contentful::Scheduler.config = config
10
+
11
+ ::Contentful::Scheduler.class_variable_set(:@@config, base_config)
39
12
  end
40
13
 
41
14
  describe 'singleton' do
42
15
  it 'creates an instance if not initialized' do
43
- queue = described_class.instance
44
- expect(queue).to be_a described_class
16
+ expect(subject).to be_a described_class
45
17
  end
46
18
 
47
19
  it 'reuses same instance' do
48
- queue = described_class.instance
49
-
50
- expect(queue).to eq described_class.instance
51
- end
52
- end
53
-
54
- describe 'attributes' do
55
- it '.config' do
56
- expect(subject.config).to eq config
20
+ expect(subject).to eq described_class.instance
57
21
  end
58
22
  end
59
23
 
60
24
  describe 'instance methods' do
61
- it '#spaces' do
62
- expect(subject.spaces).to eq config[:spaces]
63
- end
64
-
65
25
  it '#webhook_publish_field?' do
66
26
  expect(subject.webhook_publish_field?(
67
27
  WebhookDouble.new('bar', 'foo', {}, {'my_field' => 'something'})
@@ -76,12 +36,32 @@ describe Contentful::Scheduler::Queue do
76
36
  )).to be_falsey
77
37
  end
78
38
 
39
+ it '#webhook_unpublish_field?' do
40
+ expect(subject.webhook_unpublish_field?(
41
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => 'something'})
42
+ )).to be_truthy
43
+
44
+ expect(subject.webhook_publish_field?(
45
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'not_unpublish_field' => 'something'})
46
+ )).to be_falsey
47
+
48
+ expect(subject.webhook_publish_field?(
49
+ WebhookDouble.new('bar', 'other_space', {}, {'not_my_field' => 'something'})
50
+ )).to be_falsey
51
+ end
52
+
79
53
  it '#webhook_publish_field' do
80
54
  expect(subject.webhook_publish_field(
81
55
  WebhookDouble.new('bar', 'foo', {}, {'my_field' => 'something'})
82
56
  )).to eq 'something'
83
57
  end
84
58
 
59
+ it '#webhook_unpublish_field' do
60
+ expect(subject.webhook_unpublish_field(
61
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => 'something'})
62
+ )).to eq 'something'
63
+ end
64
+
85
65
  describe '#publish_date' do
86
66
  it 'works if date field not localized' do
87
67
  expect(subject.publish_date(
@@ -100,6 +80,24 @@ describe Contentful::Scheduler::Queue do
100
80
  end
101
81
  end
102
82
 
83
+ describe '#unpublish_date' do
84
+ it 'works if date field not localized' do
85
+ expect(subject.unpublish_date(
86
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => '2011-04-04T22:00:00+00:00'})
87
+ )).to eq DateTime.new(2011, 4, 4, 22, 0, 0).to_time.utc
88
+ end
89
+
90
+ it 'works if date field localized by grabbing first available locale' do
91
+ expect(subject.unpublish_date(
92
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => {'en-US': '2011-04-04T22:00:00+00:00'}})
93
+ )).to eq DateTime.new(2011, 4, 4, 22, 0, 0).to_time.utc
94
+
95
+ expect(subject.unpublish_date(
96
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => {'en-CA': '2011-04-04T23:00:00Z'}})
97
+ )).to eq DateTime.new(2011, 4, 4, 23, 0, 0).to_time.utc
98
+ end
99
+ end
100
+
103
101
  describe '#publishable?' do
104
102
  it 'false if webhook space not present in config' do
105
103
  expect(subject.publishable?(
@@ -126,18 +124,60 @@ describe Contentful::Scheduler::Queue do
126
124
  end
127
125
  end
128
126
 
129
- describe '#in_queue?' do
127
+ describe '#unpublishable?' do
128
+ it 'false if webhook space not present in config' do
129
+ expect(subject.unpublishable?(
130
+ WebhookDouble.new('bar', 'not_foo')
131
+ )).to be_falsey
132
+ end
133
+
134
+ it 'false if unpublish_field is not found' do
135
+ expect(subject.unpublishable?(
136
+ WebhookDouble.new('bar', 'unpublish_space')
137
+ )).to be_falsey
138
+ end
139
+
140
+ it 'false if unpublish_field is nil' do
141
+ expect(subject.unpublishable?(
142
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => nil})
143
+ )).to be_falsey
144
+ end
145
+
146
+ it 'true if unpublish_field is populated' do
147
+ expect(subject.unpublishable?(
148
+ WebhookDouble.new('bar', 'unpublish_space', {}, {'unpublish_field' => '2111-04-04T22:00:00+00:00'})
149
+ )).to be_truthy
150
+ end
151
+ end
152
+
153
+ describe '#in_publish_queue?' do
130
154
  it 'false if not in queue' do
131
155
  allow(Resque).to receive(:peek) { [] }
132
- expect(subject.in_queue?(
156
+ expect(subject.in_publish_queue?(
133
157
  WebhookDouble.new('bar', 'foo')
134
158
  )).to be_falsey
135
159
  end
136
160
 
137
161
  it 'true if in queue' do
138
162
  allow(Resque).to receive(:peek) { [{'args' => ['foo', 'bar']}] }
139
- expect(subject.in_queue?(
163
+ expect(subject.in_publish_queue?(
164
+ WebhookDouble.new('bar', 'foo')
165
+ )).to be_truthy
166
+ end
167
+ end
168
+
169
+ describe '#in_unpublish_queue?' do
170
+ it 'false if not in queue' do
171
+ allow(Resque).to receive(:peek) { [] }
172
+ expect(subject.in_unpublish_queue?(
140
173
  WebhookDouble.new('bar', 'foo')
174
+ )).to be_falsey
175
+ end
176
+
177
+ it 'true if in queue' do
178
+ allow(Resque).to receive(:peek) { [{'args' => ['unpublish_space', 'bar']}] }
179
+ expect(subject.in_unpublish_queue?(
180
+ WebhookDouble.new('bar', 'unpublish_space')
141
181
  )).to be_truthy
142
182
  end
143
183
  end
@@ -191,7 +231,7 @@ describe Contentful::Scheduler::Queue do
191
231
  'bar',
192
232
  'foo'
193
233
  ) { true }
194
- expect(subject).to receive(:remove)
234
+ expect(subject).to receive(:remove_publish)
195
235
 
196
236
  subject.update_or_create(WebhookDouble.new('bar', 'foo', {}, {'my_field' => '2099-04-04T22:00:00+00:00'}))
197
237
  end
@@ -220,4 +260,4 @@ describe Contentful::Scheduler::Queue do
220
260
  end
221
261
  end
222
262
  end
223
- end
263
+ end
@@ -21,13 +21,13 @@ describe Contentful::Scheduler::Tasks::Publish do
21
21
  let(:mock_entry) { MockEntry.new }
22
22
 
23
23
  before :each do
24
- ::Contentful::Scheduler.class_variable_set(:@@config, {management_token: 'foobar'})
24
+ ::Contentful::Scheduler.config = base_config
25
25
  end
26
26
 
27
27
  describe 'class methods' do
28
28
  it '::perform' do
29
29
  expect(::Contentful::Management::Client).to receive(:new).with(
30
- 'foobar',
30
+ 'foo',
31
31
  raise_errors: true,
32
32
  application_name: 'contentful-scheduler',
33
33
  application_version: Contentful::Scheduler::VERSION
@@ -36,7 +36,7 @@ describe Contentful::Scheduler::Tasks::Publish do
36
36
  expect(mock_entries).to receive(:find).with('foo', 'bar') { mock_entry }
37
37
  expect(mock_entry).to receive(:publish)
38
38
 
39
- described_class.perform('foo', 'bar', ::Contentful::Scheduler.config[:management_token])
39
+ described_class.perform('foo', 'bar', ::Contentful::Scheduler.config[:spaces]['foo'][:management_token])
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ class MockEntry
4
+ def publish
5
+ end
6
+ end
7
+
8
+ class MockClient
9
+ def entries
10
+ end
11
+ end
12
+
13
+ class MockEntries
14
+ def find
15
+ end
16
+ end
17
+
18
+ describe Contentful::Scheduler::Tasks::Unpublish do
19
+ let(:mock_client) { MockClient.new }
20
+ let(:mock_entries) { MockEntries.new }
21
+ let(:mock_entry) { MockEntry.new }
22
+
23
+ before :each do
24
+ ::Contentful::Scheduler.class_variable_set(:@@config, {management_token: 'foobar'})
25
+ end
26
+
27
+ describe 'class methods' do
28
+ it '::perform' do
29
+ expect(::Contentful::Management::Client).to receive(:new).with(
30
+ 'foobar',
31
+ raise_errors: true,
32
+ application_name: 'contentful-scheduler',
33
+ application_version: Contentful::Scheduler::VERSION
34
+ ) { mock_client }
35
+ expect(mock_client).to receive(:entries) { mock_entries }
36
+ expect(mock_entries).to receive(:find).with('foo', 'bar') { mock_entry }
37
+ expect(mock_entry).to receive(:unpublish)
38
+
39
+ described_class.perform('foo', 'bar', ::Contentful::Scheduler.config[:management_token])
40
+ end
41
+ end
42
+ end
data/spec/spec_helper.rb CHANGED
@@ -40,6 +40,17 @@ class RequestDummy
40
40
  end
41
41
  end
42
42
 
43
+ class WebhookDouble
44
+ attr_reader :id, :space_id, :sys, :fields, :raw_headers
45
+ def initialize(id, space_id, sys = {}, fields = {}, headers = {})
46
+ @id = id
47
+ @space_id = space_id
48
+ @sys = sys
49
+ @fields = fields
50
+ @raw_headers = headers
51
+ end
52
+ end
53
+
43
54
  class Contentful::Webhook::Listener::Controllers::Wait
44
55
  @@sleeping = false
45
56
 
@@ -54,7 +65,59 @@ class Contentful::Webhook::Listener::Controllers::Wait
54
65
  end
55
66
  end
56
67
 
68
+ def base_config
69
+ {
70
+ logger: ::Contentful::Scheduler::DEFAULT_LOGGER,
71
+ endpoint: ::Contentful::Scheduler::DEFAULT_ENDPOINT,
72
+ port: ::Contentful::Scheduler::DEFAULT_PORT,
73
+ redis: {
74
+ host: 'localhost',
75
+ port: 12341,
76
+ password: 'foobar'
77
+ },
78
+ spaces: {
79
+ 'foo' => {
80
+ publish_field: 'my_field',
81
+ management_token: 'foo'
82
+ },
83
+ 'unpublish_space' => {
84
+ publish_field: 'my_field',
85
+ unpublish_field: 'unpublish_field',
86
+ management_token: 'foo'
87
+ },
88
+ 'no_auth' => {
89
+ publish_field: 'my_field',
90
+ management_token: 'foo'
91
+ },
92
+ 'valid_token_array' => {
93
+ publish_field: 'my_field',
94
+ management_token: 'foo',
95
+ auth: {
96
+ key: 'auth',
97
+ valid_tokens: ['test_1']
98
+ }
99
+ },
100
+ 'valid_token_string' => {
101
+ publish_field: 'my_field',
102
+ management_token: 'foo',
103
+ auth: {
104
+ key: 'auth',
105
+ valid_tokens: 'test_2'
106
+ }
107
+ },
108
+ 'lambda_auth' => {
109
+ publish_field: 'my_field',
110
+ management_token: 'foo',
111
+ auth: {
112
+ key: 'auth',
113
+ validation: -> (value) { value.size == 4 }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ end
119
+
57
120
  RSpec.configure do |config|
58
121
  config.filter_run :focus => true
59
122
  config.run_all_when_everything_filtered = true
60
- end
123
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-scheduler-custom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (David Litvak Bruno0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contentful-webhook-listener
@@ -211,6 +211,7 @@ files:
211
211
  - spec/contentful/scheduler/controller_spec.rb
212
212
  - spec/contentful/scheduler/queue_spec.rb
213
213
  - spec/contentful/scheduler/tasks/publish_spec.rb
214
+ - spec/contentful/scheduler/tasks/unpublish_spec.rb
214
215
  - spec/contentful/scheduler_spec.rb
215
216
  - spec/spec_helper.rb
216
217
  homepage: https://www.contentful.com
@@ -241,5 +242,6 @@ test_files:
241
242
  - spec/contentful/scheduler/controller_spec.rb
242
243
  - spec/contentful/scheduler/queue_spec.rb
243
244
  - spec/contentful/scheduler/tasks/publish_spec.rb
245
+ - spec/contentful/scheduler/tasks/unpublish_spec.rb
244
246
  - spec/contentful/scheduler_spec.rb
245
247
  - spec/spec_helper.rb