Skip to content

Commit

Permalink
update openapi desc, rename automation job, revert deleted jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
celuchmarek committed Jul 23, 2024
1 parent e9c919d commit d33a342
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Automation
class EventTriggeredJob < ApplicationJob
class ApplyRulesForEventJob < ApplicationJob
queue_as :automation

def perform(event, thing)
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/automation/message_created_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Automation
class MessageCreatedJob < ApplicationJob
queue_as :default

def perform(message)
Automation.run_rules_for(message, :message_created)
end
end
end
9 changes: 9 additions & 0 deletions app/jobs/automation/message_thread_created_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Automation
class MessageThreadCreatedJob < ApplicationJob
queue_as :default

def perform(message_thread)
Automation.run_rules_for(message_thread, :message_thread_created)
end
end
end
2 changes: 1 addition & 1 deletion app/lib/event_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.reset!

# automation
[:message_thread_created, :message_created, :message_draft_submitted].each do |event|
EventBus.subscribe_job event, Automation::EventTriggeredJob
EventBus.subscribe_job event, Automation::ApplyRulesForEventJob
end

# notifications
Expand Down
2 changes: 1 addition & 1 deletion app/models/automation/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Webhook < ApplicationRecord

def fire!(message, event, timestamp, downloader: Faraday)
data = {
type: "#{message.class.name}.#{event}",
type: "#{message.class.name.underscore}.#{event}",
timestamp: timestamp,
data: {
message_id: message.id,
Expand Down
44 changes: 43 additions & 1 deletion public/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0

info:
title: GovBox Pro API
Expand Down Expand Up @@ -873,7 +873,49 @@ paths:
security:
- "Site_Admin_Token": []

webhooks:
automationWebhook:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/StandardWebhookRequestBody"
responses:
200:
description: OK

components:
schemas:
StandardWebhookRequestBody:
description: Telo requestu podľa [Standard Webhooks](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md) špecifikácie.
properties:
type:
type: string
description: Typ udalosti spúšťajúcej webhook. Je v tvare `[objekt].[event]`. Objekt môže byť `message` alebo `upvs/message_draft`. Event môže byť `message_created` alebo `message_draft_submitted`.
example: message.message_created
timestamp:
type: string
format: date-time
description: Čas udalosti spúštajúcej webhook
example: 2024-07-19T10:32:49.129+02:00
data:
type: object
description: Dáta o objekte spúšťajúcom webhook
properties:
message_id:
type: integer
description: Identifikátor správy
example: 725
message_thread_id:
type: integer
description: Identifikátor vlákna
example: 251
required:
- type
- timestamp
- data

securitySchemes:
Tenant_Token:
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require "test_helper"

class Automation::EventTriggeredJobTest < ActiveJob::TestCase
class Automation::ApplyRulesForEventJobTest < ActiveJob::TestCase
test "should call thing.automation_rules_for_event event" do
event = :event
thing = Minitest::Mock.new
rule = Minitest::Mock.new
rule.expect :run!, nil, [thing, event]
thing.expect :automation_rules_for_event, [rule], [event]

Automation::EventTriggeredJob.new.perform(event, thing)
Automation::ApplyRulesForEventJob.new.perform(event, thing)
assert_mock thing
assert_mock rule
end
Expand Down
2 changes: 1 addition & 1 deletion test/jobs/automation/fire_webhook_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Automation::FireWebhookJobTest < ActiveJob::TestCase
event = :event
timestamp = DateTime.now
data = {
type: "#{message1.class.name}.#{event}",
type: "#{message1.class.name.underscore}.#{event}",
timestamp: timestamp,
data: {
message_id: message1.id,
Expand Down
2 changes: 1 addition & 1 deletion test/models/automation/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Automation::WebhookTest < ActiveSupport::TestCase
event = :event
timestamp = DateTime.now
data = {
type: "#{message1.class.name}.#{event}",
type: "#{message1.class.name.underscore}.#{event}",
timestamp: timestamp,
data: {
message_id: message1.id,
Expand Down

0 comments on commit d33a342

Please sign in to comment.