mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
Fixed local exchange importer to enqueue job
Necessary to ensure a job is scheduled once the exchange is created so data is immeidately fetched. This includes refactoring of the dependencies injected. Milestone: patch
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "initable"
|
||||
|
||||
module Terminus
|
||||
module Aspects
|
||||
module Extensions
|
||||
@@ -9,6 +11,7 @@ module Terminus
|
||||
# Creates exchange.
|
||||
class Exchange
|
||||
include Deps[:logger, repository: "repositories.extension_exchange"]
|
||||
include Initable[job: Terminus::Jobs::Extensions::ExchangeRefresh]
|
||||
|
||||
def initialize(schema: Schemas::Exchange, error_joiner: Errors::ResultJoiner, **)
|
||||
@schema = schema
|
||||
@@ -27,7 +30,12 @@ module Terminus
|
||||
|
||||
attr_reader :schema, :error_joiner
|
||||
|
||||
def create(attributes) = repository.create(attributes).tap { log it, attributes }
|
||||
def create attributes
|
||||
repository.create(attributes).tap do |exchange|
|
||||
log exchange, attributes
|
||||
job.perform_async exchange.id
|
||||
end
|
||||
end
|
||||
|
||||
def log exchange, attributes
|
||||
tags = [{extension_id: attributes[:extension_id], exchange_id: exchange.id}]
|
||||
|
||||
@@ -40,6 +40,16 @@ RSpec.describe Terminus::Aspects::Extensions::Importers::Local::Creators::Exchan
|
||||
)
|
||||
end
|
||||
|
||||
it "enqueues job" do
|
||||
Sidekiq::Testing.fake! do
|
||||
creator.call attributes
|
||||
|
||||
expect(Terminus::Jobs::Extensions::ExchangeRefresh.jobs).to contain_exactly(
|
||||
hash_including("args" => [kind_of(Integer)])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it "answers extension when success" do
|
||||
expect(creator.call(attributes)).to match(
|
||||
Success(kind_of(Terminus::Structs::ExtensionExchange))
|
||||
|
||||
Reference in New Issue
Block a user