remove replace_timestamps helper
This commit is contained in:
@@ -26,11 +26,11 @@ RSpec.describe SendFormCompletedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.completed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -43,11 +43,11 @@ RSpec.describe SendFormCompletedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.completed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -26,11 +26,11 @@ RSpec.describe SendFormDeclinedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.declined',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -43,11 +43,11 @@ RSpec.describe SendFormDeclinedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.declined',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -26,11 +26,11 @@ RSpec.describe SendFormStartedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.started',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -43,11 +43,11 @@ RSpec.describe SendFormStartedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.started',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -26,11 +26,11 @@ RSpec.describe SendFormViewedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.viewed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -43,11 +43,11 @@ RSpec.describe SendFormViewedWebhookRequestJob do
|
||||
described_class.new.perform('submitter_id' => submitter.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'form.viewed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submitters::SerializeForWebhook.call(submitter.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submitters::SerializeForWebhook.call(submitter.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -23,11 +23,11 @@ RSpec.describe SendSubmissionArchivedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.archived',
|
||||
'timestamp' => Time.current,
|
||||
'data' => submission.reload.as_json(only: %i[id archived_at])
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(submission.reload.as_json(only: %i[id archived_at]).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -40,11 +40,11 @@ RSpec.describe SendSubmissionArchivedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.archived',
|
||||
'timestamp' => Time.current,
|
||||
'data' => submission.reload.as_json(only: %i[id archived_at])
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(submission.reload.as_json(only: %i[id archived_at]).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -23,11 +23,11 @@ RSpec.describe SendSubmissionCompletedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.completed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submissions::SerializeForApi.call(submission.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submissions::SerializeForApi.call(submission.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -40,11 +40,11 @@ RSpec.describe SendSubmissionCompletedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.completed',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submissions::SerializeForApi.call(submission.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submissions::SerializeForApi.call(submission.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -23,11 +23,11 @@ RSpec.describe SendSubmissionCreatedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.created',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submissions::SerializeForApi.call(submission.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submissions::SerializeForApi.call(submission.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -40,11 +40,11 @@ RSpec.describe SendSubmissionCreatedWebhookRequestJob do
|
||||
described_class.new.perform('submission_id' => submission.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'submission.created',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Submissions::SerializeForApi.call(submission.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Submissions::SerializeForApi.call(submission.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -22,11 +22,11 @@ RSpec.describe SendTemplateCreatedWebhookRequestJob do
|
||||
described_class.new.perform('template_id' => template.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'template.created',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Templates::SerializeForApi.call(template.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Templates::SerializeForApi.call(template.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -39,11 +39,11 @@ RSpec.describe SendTemplateCreatedWebhookRequestJob do
|
||||
described_class.new.perform('template_id' => template.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'template.created',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Templates::SerializeForApi.call(template.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Templates::SerializeForApi.call(template.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -22,11 +22,11 @@ RSpec.describe SendTemplateUpdatedWebhookRequestJob do
|
||||
described_class.new.perform('template_id' => template.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'template.updated',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Templates::SerializeForApi.call(template.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Templates::SerializeForApi.call(template.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook'
|
||||
@@ -39,11 +39,11 @@ RSpec.describe SendTemplateUpdatedWebhookRequestJob do
|
||||
described_class.new.perform('template_id' => template.id, 'webhook_url_id' => webhook_url.id)
|
||||
|
||||
expect(WebMock).to have_requested(:post, webhook_url.url).with(
|
||||
body: replace_timestamps({
|
||||
body: {
|
||||
'event_type' => 'template.updated',
|
||||
'timestamp' => Time.current,
|
||||
'data' => Templates::SerializeForApi.call(template.reload)
|
||||
}.deep_stringify_keys),
|
||||
'timestamp' => /.*/,
|
||||
'data' => JSON.parse(Templates::SerializeForApi.call(template.reload).to_json)
|
||||
},
|
||||
headers: {
|
||||
'Content-Type' => 'application/json',
|
||||
'User-Agent' => 'DocuSeal.com Webhook',
|
||||
|
||||
@@ -67,19 +67,3 @@ RSpec.configure do |config|
|
||||
Sidekiq::Testing.inline! if example.metadata[:sidekiq] == :inline
|
||||
end
|
||||
end
|
||||
|
||||
def replace_timestamps(data, replace = /.*/)
|
||||
timestamp_fields = %w[created_at updated_at completed_at sent_at opened_at timestamp]
|
||||
|
||||
data.each do |key, value|
|
||||
if timestamp_fields.include?(key) && (value.is_a?(String) || value.is_a?(Time))
|
||||
data[key] = replace
|
||||
elsif value.is_a?(Hash)
|
||||
replace_timestamps(value)
|
||||
elsif value.is_a?(Array)
|
||||
value.each { |item| replace_timestamps(item) if item.is_a?(Hash) }
|
||||
end
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user