# typed: false # frozen_string_literal: true module Webmocks module Yetto SHA256_DIGEST = OpenSSL::Digest.new("sha256") def yetto_auth_header(payload) "sha256=#{OpenSSL::HMAC.hexdigest(SHA256_DIGEST, YETTO_PLUG_APP_TOKEN, payload.to_json)}" end def assert_requested_get_plug_installation(organization_id, inbox_id, plug_installation_id) assert_requested(:get, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{organization_id}/inboxes/#{inbox_id}/plug_installations/#{plug_installation_id}") end def stub_get_plug_installation(organization_id, inbox_id, plug_installation_id, response = nil, status: 200) response ||= { installed_on_inbox: { id: inbox_id, organization: { id: organization_id, status: "active", }, }, plug: { id: "plg_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}", }, settings: { from_email: "new@from.company", }, } stub_request(:get, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{@organization_id}/inboxes/#{@inbox_id}/plug_installations/#{plug_installation_id}") .to_return( status: status, headers: { content_type: "application/json; charset=utf-8" }, body: response.to_json, ) end def assert_requested_update_installation(organization_id, inbox_id, plug_installation_id) assert_requested(:patch, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{@organization_id}/inboxes/#{@inbox_id}/plug_installations/#{plug_installation_id}") end def stub_update_installation(organization_id, inbox_id, plug_installation_id, params, response: {}, status: 200) stub_request(:patch, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{@organization_id}/inboxes/#{@inbox_id}/plug_installations/#{plug_installation_id}") .with( body: params, ) .to_return( status: 200, headers: { content_type: "application/json; charset=utf-8" }, body: response.to_json, ) end def assert_requested_create_message(organization_id, inbox_id) assert_requested(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{organization_id}/inboxes/#{inbox_id}/messages") end def stub_create_message(organization_id, inbox_id, creator_id, payload) stub_request(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{organization_id}/inboxes/#{inbox_id}/messages") .with( body: payload, ) .to_return( status: 200, headers: { content_type: "application/json; charset=utf-8" }, body: {}.to_json, ) end def assert_requested_create_switch(organization_id, inbox_id) assert_requested(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{organization_id}/inboxes/#{inbox_id}/switches") end def stub_create_switch(organization_id, inbox_id, creator_id, params) payload = { name: "After install", creator: { id: creator_id }, } stub_request(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/organizations/#{organization_id}/inboxes/#{inbox_id}/switches") .with( body: payload, ) .to_return( status: 200, headers: { content_type: "application/json; charset=utf-8" }, body: {}.to_json, ) end end end