diff --git a/README.md b/README.md index 7c7febc..48eb33b 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,14 @@ notifications to a Discord channel. A *Use Case* object, consists on 4 main components, having it's own responsibility: -### 1. Fetcher - Obtaining the data +### 1. Read - Obtaining the data -Specifically, a fetcher is an object in charged of bringing data from a data source. The gem already provides the base interface -for building your own fetcher for your specific data source, or rely on already built classes if they match your purpose. +Specifically, a reader is an object in charged of bringing data from a data source. The gem already provides the base interface +for building your own reader for your specific data source, or rely on already built classes if they match your purpose. -The base interface for a fetcher can be found under the `bas/fetcher/base.rb` class. Since this is a implementation of the `Fetcher::Base` +The base interface for a reader can be found under the `bas/read/base.rb` class. Since this is a implementation of the `Read::Base` for bringing data from a Notion database, it was created on a new namespace for that data source, it can be found under -`/bas/fetcher/notion/use_case/birthday_today.rb`. It implements specific logic for fetching the data and validating the response. +`/bas/read/notion/use_case/birthday_today.rb`. It implements specific logic for reading the data and validating the response. ### 2. Mapper - Shaping it @@ -139,7 +139,7 @@ filter = { } options = { - fetch_options: { + read_options: { base_url: "https://api.notion.com", database_id: NOTION_DATABASE_ID, secret: NOTION_API_INTEGRATION_SECRET, @@ -235,7 +235,7 @@ module Notifier # Service description class UseCaseName def self.notify(*) - options = { fetch_options:, dispatch_options: } + options = { read_options:, dispatch_options: } begin use_case = UseCases.use_case_build_function(options) @@ -246,18 +246,18 @@ module Notifier end end - def self.fetch_options + def self.read_options { base_url: NOTION_BASE_URL, database_id: NOTION_DATABASE_ID, secret: NOTION_SECRET, filter: { - filter: { "and": fetch_filter } + filter: { "and": read_filter } } } end - def self.fetch_filter + def self.read_filter today = Common::TimeZone.set_colombia_time_zone.strftime('%F').to_s [ diff --git a/lib/bas/fetcher/github/use_case/repo_issues.rb b/lib/bas/fetcher/github/use_case/repo_issues.rb deleted file mode 100644 index bb8dcaa..0000000 --- a/lib/bas/fetcher/github/use_case/repo_issues.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require_relative "../base" - -module Fetcher - module Github - ## - # This class is an implementation of the Fetcher::Github::Base interface, specifically designed - # for fetching issues from a Github repository. - # - class RepoIssues < Github::Base - def fetch - execute("list_issues", config[:repo]) - end - end - end -end diff --git a/lib/bas/fetcher/imap/use_case/support_emails.rb b/lib/bas/fetcher/imap/use_case/support_emails.rb deleted file mode 100644 index 520a954..0000000 --- a/lib/bas/fetcher/imap/use_case/support_emails.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require_relative "../base" - -module Fetcher - module Imap - ## - # This class is an implementation of the Fetcher::Imap::Base interface, specifically designed - # for fetching support email from a Google Gmail account. - # - class SupportEmails < Imap::Base - TOKEN_URI = "https://oauth2.googleapis.com/token" - EMAIL_DOMAIN = "imap.gmail.com" - EMAIL_PORT = 993 - - # Implements the data fetching filter for support emails from Google Gmail. - # - def fetch - yesterday = (Time.now - (60 * 60 * 24)).strftime("%e-%b-%Y") - query = ["TO", config[:search_email], "SINCE", yesterday] - - execute(EMAIL_DOMAIN, EMAIL_PORT, TOKEN_URI, query) - end - end - end -end diff --git a/lib/bas/mapper/base.rb b/lib/bas/mapper/base.rb index f530351..3733822 100644 --- a/lib/bas/mapper/base.rb +++ b/lib/bas/mapper/base.rb @@ -9,12 +9,12 @@ module Mapper # suitable for downstream formatting processes. # module Base - # An method meant to prepare or organize the data coming from an implementation of the Fetcher::Base interface. + # An method meant to prepare or organize the data coming from an implementation of the Read::Base interface. # Must be overridden by subclasses, with specific logic based on the use case. # #
# Params: - # * Fetcher::Notion::Types::Response response: Response produced by a fetcher. + # * Read::Notion::Types::Response response: Response produced by a reader. # #
# diff --git a/lib/bas/mapper/github/issues.rb b/lib/bas/mapper/github/issues.rb index 9181600..a5bb432 100644 --- a/lib/bas/mapper/github/issues.rb +++ b/lib/bas/mapper/github/issues.rb @@ -7,15 +7,15 @@ module Mapper module Github ## # This class implementats the methods of the Mapper::Base module, specifically designed for - # preparing or shaping Github issues data coming from a Fetcher::Base implementation. + # preparing or shaping Github issues data coming from a Read::Base implementation. class Issues include Base - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Github::Types::Response github_response: Array of github issues data. + # * Read::Github::Types::Response github_response: Array of github issues data. # #
# return List mapped github issues to be used by a diff --git a/lib/bas/mapper/imap/support_emails.rb b/lib/bas/mapper/imap/support_emails.rb index 6585c53..31ecfe9 100644 --- a/lib/bas/mapper/imap/support_emails.rb +++ b/lib/bas/mapper/imap/support_emails.rb @@ -7,15 +7,15 @@ module Mapper module Imap ## # This class implementats the methods of the Mapper::Base module, specifically designed for - # preparing or shaping support emails data coming from a Fetcher::Base implementation. + # preparing or shaping support emails data coming from a Read::Base implementation. class SupportEmails include Base - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Imap::Types::Response imap_response: Array of imap emails data. + # * Read::Imap::Types::Response imap_response: Array of imap emails data. # #
# return List support_emails_list, mapped support emails to be used by a diff --git a/lib/bas/mapper/notion/birthday_today.rb b/lib/bas/mapper/notion/birthday_today.rb index 30d9ddb..ca82ff5 100644 --- a/lib/bas/mapper/notion/birthday_today.rb +++ b/lib/bas/mapper/notion/birthday_today.rb @@ -7,17 +7,17 @@ module Mapper module Notion ## # This class implementats the methods of the Mapper::Base module, specifically designed for preparing or - # shaping birthdays data coming from a Fetcher::Base implementation. + # shaping birthdays data coming from a Read::Base implementation. class BirthdayToday include Base BIRTHDAY_PARAMS = ["Complete Name", "BD_this_year"].freeze - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Notion::Types::Response notion_response: Notion response object. + # * Read::Notion::Types::Response notion_response: Notion response object. # #
# return List birthdays_list, mapped birthdays to be used by a diff --git a/lib/bas/mapper/notion/pto_today.rb b/lib/bas/mapper/notion/pto_today.rb index 9ee99e6..101f662 100644 --- a/lib/bas/mapper/notion/pto_today.rb +++ b/lib/bas/mapper/notion/pto_today.rb @@ -7,18 +7,18 @@ module Mapper module Notion ## # This class implementats the methods of the Mapper::Base module, specifically designed for preparing or - # shaping PTO's data coming from a Fetcher::Base implementation. + # shaping PTO's data coming from a Read::Base implementation. # class PtoToday include Base - PTO_PARAMS = ["Person", "Desde?", "Hasta?"].freeze + PTO_PARAMS = ["Description", "Desde?", "Hasta?"].freeze - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Notion::Types::Response notion_response: Notion response object. + # * Read::Notion::Types::Response notion_response: Notion response object. # #
# returns List ptos_list, mapped PTO's to be used by a Formatter::Base @@ -30,7 +30,7 @@ def map(notion_response) normalized_notion_data = normalize_response(notion_response.results) normalized_notion_data.map do |pto| - Domain::Pto.new(pto["Person"], pto["Desde?"], pto["Hasta?"]) + Domain::Pto.new(pto["Description"], pto["Desde?"], pto["Hasta?"]) end end @@ -43,15 +43,17 @@ def normalize_response(response) pto_fields = value["properties"].slice(*PTO_PARAMS) { - "Person" => extract_person_field_value(pto_fields["Person"]), + "Description" => extract_description_field_value(pto_fields["Description"]), "Desde?" => extract_date_field_value(pto_fields["Desde?"]), "Hasta?" => extract_date_field_value(pto_fields["Hasta?"]) } end end - def extract_person_field_value(data) - data["people"][0]["name"] + def extract_description_field_value(data) + names = data["title"].map { |name| name["plain_text"] } + + names.join(" ") end def extract_date_field_value(date) diff --git a/lib/bas/mapper/notion/work_items_limit.rb b/lib/bas/mapper/notion/work_items_limit.rb index 20674b4..cb823db 100644 --- a/lib/bas/mapper/notion/work_items_limit.rb +++ b/lib/bas/mapper/notion/work_items_limit.rb @@ -7,17 +7,17 @@ module Mapper module Notion ## # This class implementats the methods of the Mapper::Base module, specifically designed - # for preparing or shaping work items data coming from a Fetcher::Base implementation. + # for preparing or shaping work items data coming from a Read::Base implementation. class WorkItemsLimit include Base WORK_ITEM_PARAMS = ["Responsible domain"].freeze - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Notion::Types::Response notion_response: Notion response object. + # * Read::Notion::Types::Response notion_response: Notion response object. # #
# return List work_items_list, mapped work items to be used by a diff --git a/lib/bas/mapper/postgres/pto_today.rb b/lib/bas/mapper/postgres/pto_today.rb index ce4aa99..e93d7e3 100644 --- a/lib/bas/mapper/postgres/pto_today.rb +++ b/lib/bas/mapper/postgres/pto_today.rb @@ -7,14 +7,14 @@ module Mapper module Postgres ## # This class implementats the methods of the Mapper::Base module, specifically designed for preparing or - # shaping PTO's data coming from the Fetcher::Postgres::Pto class. + # shaping PTO's data coming from the Read::Postgres::Pto class. # class PtoToday - # Implements the logic for shaping the results from a fetcher response. + # Implements the logic for shaping the results from a reader response. # #
# Params: - # * Fetcher::Postgres::Types::Response pg_response: Postgres response object. + # * Read::Postgres::Types::Response pg_response: Postgres response object. # #
# returns List ptos_list, mapped PTO's to be used by a Formatter::Base diff --git a/lib/bas/fetcher/base.rb b/lib/bas/read/base.rb similarity index 68% rename from lib/bas/fetcher/base.rb rename to lib/bas/read/base.rb index d080f25..4b45e50 100644 --- a/lib/bas/fetcher/base.rb +++ b/lib/bas/read/base.rb @@ -2,41 +2,41 @@ require_relative "../domain/exceptions/function_not_implemented" -module Fetcher +module Read ## - # The Fetcher::Base class serves as the foundation for implementing specific data fetchers within the Fetcher module. + # The Read::Base class serves as the foundation for implementing specific data readers within the Read module. # Operating as an interface, this class defines essential attributes and methods, providing a blueprint for creating - # custom fetchers tailored to different data sources. + # custom readers tailored to different data sources. # class Base attr_reader :config - # Initializes the fetcher with essential configuration parameters. + # Initializes the reader with essential configuration parameters. # def initialize(config) @config = config end - # A method meant to fetch data from an specific source depending on the implementation. + # A method meant to execute the read request from an specific source depending on the implementation. # Must be overridden by subclasses, with specific logic based on the use case. # #
# raises Domain::Exceptions::FunctionNotImplemented when missing implementation. # - def fetch + def execute raise Domain::Exceptions::FunctionNotImplemented end protected - # A method meant to execute the fetch request, retrieven the required data + # A method meant to read from the source, retrieven the required data # from an specific filter configuration depending on the use case implementation. # Must be overridden by subclasses, with specific logic based on the use case. # #
# raises Domain::Exceptions::FunctionNotImplemented when missing implementation. # - def execute + def read(*_filters) raise Domain::Exceptions::FunctionNotImplemented end end diff --git a/lib/bas/fetcher/github/base.rb b/lib/bas/read/github/base.rb similarity index 74% rename from lib/bas/fetcher/github/base.rb rename to lib/bas/read/github/base.rb index 071e5f3..6cea935 100644 --- a/lib/bas/fetcher/github/base.rb +++ b/lib/bas/read/github/base.rb @@ -7,23 +7,23 @@ require_relative "../base" require_relative "./types/response" -module Fetcher +module Read module Github ## - # This class is an implementation of the Fetcher::Base interface, specifically designed - # for fetching data from a GitHub repository. + # This class is an implementation of the Read::Base interface, specifically designed + # for reading data from a GitHub repository. # - class Base < Fetcher::Base + class Base < Read::Base protected - # Implements the data fetching logic to get data from a Github repository. + # Implements the data reading logic to get data from a Github repository. # It connects to Github using the octokit gem, authenticates with a github app, # request the data and returns a validated response. # - def execute(method, *filter) + def read(method, *filter) octokit_response = octokit.public_send(method, *filter) - Fetcher::Github::Types::Response.new(octokit_response) + Read::Github::Types::Response.new(octokit_response) end private diff --git a/lib/bas/fetcher/github/types/response.rb b/lib/bas/read/github/types/response.rb similarity index 97% rename from lib/bas/fetcher/github/types/response.rb rename to lib/bas/read/github/types/response.rb index 86a2cc9..3c3f7e6 100644 --- a/lib/bas/fetcher/github/types/response.rb +++ b/lib/bas/read/github/types/response.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Github module Types ## diff --git a/lib/bas/read/github/use_case/repo_issues.rb b/lib/bas/read/github/use_case/repo_issues.rb new file mode 100644 index 0000000..7920497 --- /dev/null +++ b/lib/bas/read/github/use_case/repo_issues.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require_relative "../base" + +module Read + module Github + ## + # This class is an implementation of the Read::Github::Base interface, specifically designed + # for reading issues from a Github repository. + # + class RepoIssues < Github::Base + def execute + read("list_issues", config[:repo]) + end + end + end +end diff --git a/lib/bas/fetcher/imap/base.rb b/lib/bas/read/imap/base.rb similarity index 79% rename from lib/bas/fetcher/imap/base.rb rename to lib/bas/read/imap/base.rb index d0bfa93..f395779 100644 --- a/lib/bas/fetcher/imap/base.rb +++ b/lib/bas/read/imap/base.rb @@ -6,25 +6,25 @@ require_relative "../base" require_relative "./types/response" -module Fetcher +module Read module Imap ## - # This class is an implementation of the Fetcher::Base interface, specifically designed - # for fetching data from an IMAP server. + # This class is an implementation of the Read::Base interface, specifically designed + # for reading data from an IMAP server. # - class Base < Fetcher::Base + class Base < Read::Base protected - # Implements the data fetching logic for emails data from an IMAP server. + # Implements the reading logic for emails data from an IMAP server. # It connects to an IMAP server inbox, request emails base on a filter, # and returns a validated response. # - def execute(email_domain, email_port, token_uri, query) + def read(email_domain, email_port, token_uri, query) access_token = refresh_token(token_uri) imap_fetch(email_domain, email_port, query, access_token) - Fetcher::Imap::Types::Response.new(@emails) + Read::Imap::Types::Response.new(@emails) end private diff --git a/lib/bas/fetcher/imap/types/response.rb b/lib/bas/read/imap/types/response.rb similarity index 97% rename from lib/bas/fetcher/imap/types/response.rb rename to lib/bas/read/imap/types/response.rb index 7f01eb5..b42881c 100644 --- a/lib/bas/fetcher/imap/types/response.rb +++ b/lib/bas/read/imap/types/response.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Imap module Types ## diff --git a/lib/bas/read/imap/use_case/support_emails.rb b/lib/bas/read/imap/use_case/support_emails.rb new file mode 100644 index 0000000..19ec1b6 --- /dev/null +++ b/lib/bas/read/imap/use_case/support_emails.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require_relative "../base" + +module Read + module Imap + ## + # This class is an implementation of the Read::Imap::Base interface, specifically designed + # for reading support email from a Google Gmail account. + # + class SupportEmails < Imap::Base + TOKEN_URI = "https://oauth2.googleapis.com/token" + EMAIL_DOMAIN = "imap.gmail.com" + EMAIL_PORT = 993 + + # Implements the data reading filter for support emails from Google Gmail. + # + def execute + yesterday = (Time.now - (60 * 60 * 24)).strftime("%d-%b-%Y") + query = ["TO", config[:search_email], "SINCE", yesterday] + + read(EMAIL_DOMAIN, EMAIL_PORT, TOKEN_URI, query) + end + end + end +end diff --git a/lib/bas/fetcher/notion/base.rb b/lib/bas/read/notion/base.rb similarity index 72% rename from lib/bas/fetcher/notion/base.rb rename to lib/bas/read/notion/base.rb index d415b0f..19a33ff 100644 --- a/lib/bas/fetcher/notion/base.rb +++ b/lib/bas/read/notion/base.rb @@ -8,18 +8,18 @@ require_relative "./types/response" require_relative "./helper" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Base interface, specifically designed - # for fetching data from Notion. + # This class is an implementation of the Read::Base interface, specifically designed + # for reading data from Notion. # - class Base < Fetcher::Base + class Base < Read::Base NOTION_BASE_URL = "https://api.notion.com" protected - # Implements the data fetching logic for data from Notion. It sends a POST + # Implements the read logic for data from Notion. It sends a POST # request to the Notion API to query the specified database and returns a validated response. # #
@@ -28,14 +28,14 @@ class Base < Fetcher::Base # raises Exceptions::Notion::InvalidDatabaseId if the Database id provided is incorrect # or invalid. # - def execute(filter) + def read(filter) url = "#{NOTION_BASE_URL}/v1/databases/#{config[:database_id]}/query" httparty_response = HTTParty.post(url, { body: filter.to_json, headers: headers }) - notion_response = Fetcher::Notion::Types::Response.new(httparty_response) + notion_response = Read::Notion::Types::Response.new(httparty_response) - Fetcher::Notion::Helper.validate_response(notion_response) + Read::Notion::Helper.validate_response(notion_response) end private diff --git a/lib/bas/fetcher/notion/exceptions/invalid_api_key.rb b/lib/bas/read/notion/exceptions/invalid_api_key.rb similarity index 100% rename from lib/bas/fetcher/notion/exceptions/invalid_api_key.rb rename to lib/bas/read/notion/exceptions/invalid_api_key.rb diff --git a/lib/bas/fetcher/notion/exceptions/invalid_database_id.rb b/lib/bas/read/notion/exceptions/invalid_database_id.rb similarity index 100% rename from lib/bas/fetcher/notion/exceptions/invalid_database_id.rb rename to lib/bas/read/notion/exceptions/invalid_database_id.rb diff --git a/lib/bas/fetcher/notion/helper.rb b/lib/bas/read/notion/helper.rb similarity index 96% rename from lib/bas/fetcher/notion/helper.rb rename to lib/bas/read/notion/helper.rb index f865377..53a3f92 100644 --- a/lib/bas/fetcher/notion/helper.rb +++ b/lib/bas/read/notion/helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Notion ## # Provides common fuctionalities along the Notion domain. diff --git a/lib/bas/fetcher/notion/types/response.rb b/lib/bas/read/notion/types/response.rb similarity index 97% rename from lib/bas/fetcher/notion/types/response.rb rename to lib/bas/read/notion/types/response.rb index f5df8e7..082602c 100644 --- a/lib/bas/fetcher/notion/types/response.rb +++ b/lib/bas/read/notion/types/response.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Notion module Types ## diff --git a/lib/bas/fetcher/notion/use_case/birthday_next_week.rb b/lib/bas/read/notion/use_case/birthday_next_week.rb similarity index 66% rename from lib/bas/fetcher/notion/use_case/birthday_next_week.rb rename to lib/bas/read/notion/use_case/birthday_next_week.rb index 71636cd..9a3e7bf 100644 --- a/lib/bas/fetcher/notion/use_case/birthday_next_week.rb +++ b/lib/bas/read/notion/use_case/birthday_next_week.rb @@ -2,18 +2,18 @@ require_relative "../base" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Notion::Base interface, specifically designed - # for fetching next week birthdays data from Notion. + # This class is an implementation of the Read::Notion::Base interface, specifically designed + # for reading next week birthdays data from Notion. # class BirthdayNextWeek < Notion::Base DAYS_BEFORE_NOTIFY = 8 - # Implements the data fetching filter for next week Birthdays data from Notion. + # Implements the data reading filter for next week Birthdays data from Notion. # - def fetch + def execute filter = { filter: { or: [ @@ -22,7 +22,7 @@ def fetch } } - execute(filter) + read(filter) end private diff --git a/lib/bas/fetcher/notion/use_case/birthday_today.rb b/lib/bas/read/notion/use_case/birthday_today.rb similarity index 56% rename from lib/bas/fetcher/notion/use_case/birthday_today.rb rename to lib/bas/read/notion/use_case/birthday_today.rb index e3d8620..09207b3 100644 --- a/lib/bas/fetcher/notion/use_case/birthday_today.rb +++ b/lib/bas/read/notion/use_case/birthday_today.rb @@ -2,16 +2,16 @@ require_relative "../base" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Notion::Base interface, specifically designed - # for fetching birthday data from Notion. + # This class is an implementation of the Read::Notion::Base interface, specifically designed + # for reading birthday data from Notion. # class BirthdayToday < Notion::Base - # Implements the data fetching filter for todays Birthdays data from Notion. + # Implements the reading filter for todays Birthdays data from Notion. # - def fetch + def execute today = Time.now.utc.strftime("%F").to_s filter = { @@ -22,7 +22,7 @@ def fetch } } - execute(filter) + read(filter) end end end diff --git a/lib/bas/fetcher/notion/use_case/pto_next_week.rb b/lib/bas/read/notion/use_case/pto_next_week.rb similarity index 81% rename from lib/bas/fetcher/notion/use_case/pto_next_week.rb rename to lib/bas/read/notion/use_case/pto_next_week.rb index c7088ce..5be1d07 100644 --- a/lib/bas/fetcher/notion/use_case/pto_next_week.rb +++ b/lib/bas/read/notion/use_case/pto_next_week.rb @@ -2,19 +2,19 @@ require_relative "../base" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Notion::Base interface, specifically designed - # for fetching next week Paid Time Off (PTO) data from Notion. + # This class is an implementation of the Read::Notion::Base interface, specifically designed + # for reading next week Paid Time Off (PTO) data from Notion. # class PtoNextWeek < Notion::Base - # Implements the data fetching filter for next week PTO's data from Notion. + # Implements the reading filter for next week PTO's data from Notion. # - def fetch + def execute filter = build_filter - execute(filter) + read(filter) end private diff --git a/lib/bas/fetcher/notion/use_case/pto_today.rb b/lib/bas/read/notion/use_case/pto_today.rb similarity index 60% rename from lib/bas/fetcher/notion/use_case/pto_today.rb rename to lib/bas/read/notion/use_case/pto_today.rb index 77271e1..3e4fac8 100644 --- a/lib/bas/fetcher/notion/use_case/pto_today.rb +++ b/lib/bas/read/notion/use_case/pto_today.rb @@ -2,16 +2,16 @@ require_relative "../base" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Notion::Base interface, specifically designed - # for fetching Paid Time Off (PTO) data from Notion. + # This class is an implementation of the Read::Notion::Base interface, specifically designed + # for reading Paid Time Off (PTO) data from Notion. # class PtoToday < Notion::Base - # Implements the data fetching filter for todays PTO's data from Notion. + # Implements the reading filter for todays PTO's data from Notion. # - def fetch + def execute today = Time.now.utc.strftime("%F").to_s filter = { @@ -23,7 +23,7 @@ def fetch } } - execute(filter) + read(filter) end end end diff --git a/lib/bas/fetcher/notion/use_case/work_items_limit.rb b/lib/bas/read/notion/use_case/work_items_limit.rb similarity index 73% rename from lib/bas/fetcher/notion/use_case/work_items_limit.rb rename to lib/bas/read/notion/use_case/work_items_limit.rb index c2b61c9..40a2115 100644 --- a/lib/bas/fetcher/notion/use_case/work_items_limit.rb +++ b/lib/bas/read/notion/use_case/work_items_limit.rb @@ -2,16 +2,16 @@ require_relative "../base" -module Fetcher +module Read module Notion ## - # This class is an implementation of the Fetcher::Notion::Base interface, specifically designed + # This class is an implementation of the Read::Notion::Base interface, specifically designed # for counting "in progress" work items from work item database in Notion. # class WorkItemsLimit < Notion::Base - # Implements the data fetching count of "in progress" work items from Notion. + # Implements the data reading count of "in progress" work items from Notion. # - def fetch + def execute filter = { filter: { "and": [ @@ -21,7 +21,7 @@ def fetch } } - execute(filter) + read(filter) end private diff --git a/lib/bas/fetcher/postgres/base.rb b/lib/bas/read/postgres/base.rb similarity index 62% rename from lib/bas/fetcher/postgres/base.rb rename to lib/bas/read/postgres/base.rb index 98529c8..685bc0d 100644 --- a/lib/bas/fetcher/postgres/base.rb +++ b/lib/bas/read/postgres/base.rb @@ -6,28 +6,28 @@ require_relative "./types/response" require_relative "./helper" -module Fetcher +module Read module Postgres ## - # This class is an implementation of the Fetcher::Base interface, specifically designed - # for fetching data from Postgres. + # This class is an implementation of the Read::Base interface, specifically designed + # for reading data from Postgres. # - class Base < Fetcher::Base + class Base < Read::Base protected - # Implements the data fetching logic from a Postgres database. It use the PG gem + # Implements the read logic from a Postgres database. It use the PG gem # to request data from a local or external database and returns a validated response. # # Gem: pg (https://rubygems.org/gems/pg) # - def execute(query) + def read(query) pg_connection = PG::Connection.new(config[:connection]) pg_result = execute_query(pg_connection, query) - postgres_response = Fetcher::Postgres::Types::Response.new(pg_result) + postgres_response = Read::Postgres::Types::Response.new(pg_result) - Fetcher::Postgres::Helper.validate_response(postgres_response) + Read::Postgres::Helper.validate_response(postgres_response) end private diff --git a/lib/bas/fetcher/postgres/helper.rb b/lib/bas/read/postgres/helper.rb similarity index 94% rename from lib/bas/fetcher/postgres/helper.rb rename to lib/bas/read/postgres/helper.rb index cc509fd..c90cb89 100644 --- a/lib/bas/fetcher/postgres/helper.rb +++ b/lib/bas/read/postgres/helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Postgres ## # Provides common fuctionalities along the Postgres domain. diff --git a/lib/bas/fetcher/postgres/types/response.rb b/lib/bas/read/postgres/types/response.rb similarity index 98% rename from lib/bas/fetcher/postgres/types/response.rb rename to lib/bas/read/postgres/types/response.rb index 49a7645..e85d6c9 100644 --- a/lib/bas/fetcher/postgres/types/response.rb +++ b/lib/bas/read/postgres/types/response.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Fetcher +module Read module Postgres module Types ## diff --git a/lib/bas/fetcher/postgres/use_case/pto_today.rb b/lib/bas/read/postgres/use_case/pto_today.rb similarity index 61% rename from lib/bas/fetcher/postgres/use_case/pto_today.rb rename to lib/bas/read/postgres/use_case/pto_today.rb index 137571a..9f9011a 100644 --- a/lib/bas/fetcher/postgres/use_case/pto_today.rb +++ b/lib/bas/read/postgres/use_case/pto_today.rb @@ -2,17 +2,17 @@ require_relative "../base" -module Fetcher +module Read module Postgres ## - # This class is an implementation of the Fetcher::Postgres::Base interface, specifically designed - # for fetching Paid Time Off (PTO) data from a Postgres Database. + # This class is an implementation of the Read::Postgres::Base interface, specifically designed + # for reading Paid Time Off (PTO) data from a Postgres Database. # class PtoToday < Base - # Implements the data fetching query for todays PTO data from a Postgres database. + # Implements the data reading query for todays PTO data from a Postgres database. # - def fetch - execute(build_query) + def execute + read(build_query) end private diff --git a/lib/bas/use_cases/types/config.rb b/lib/bas/use_cases/types/config.rb index 7942baa..cc2a0b5 100644 --- a/lib/bas/use_cases/types/config.rb +++ b/lib/bas/use_cases/types/config.rb @@ -6,10 +6,10 @@ module Types # Represents a the configuration composing the initial components required by a UseCases::UseCase implementation. # class Config - attr_reader :fetcher, :mapper, :formatter, :dispatcher + attr_reader :read, :mapper, :formatter, :dispatcher - def initialize(fetcher, mapper, formatter, dispatcher) - @fetcher = fetcher + def initialize(read, mapper, formatter, dispatcher) + @read = read @mapper = mapper @formatter = formatter @dispatcher = dispatcher diff --git a/lib/bas/use_cases/use_case.rb b/lib/bas/use_cases/use_case.rb index e39107c..b1abab2 100644 --- a/lib/bas/use_cases/use_case.rb +++ b/lib/bas/use_cases/use_case.rb @@ -6,7 +6,7 @@ module UseCases # logic flow by coordinating the execution of its components to fulfill a specific use case. # class UseCase - attr_reader :fetcher, :mapper, :formatter, :dispatcher + attr_reader :read, :mapper, :formatter, :dispatcher # Initializes the use case with the necessary components. # @@ -15,19 +15,19 @@ class UseCase # * Usecases::Types::Config config, The components required to instantiate a use case. # def initialize(config) - @fetcher = config.fetcher + @read = config.read @mapper = config.mapper @formatter = config.formatter @dispatcher = config.dispatcher end - # Executes the use case by orchestrating the sequential execution of the fetcher, mapper, formatter, and dispatcher. + # Executes the use case by orchestrating the sequential execution of the read, mapper, formatter, and dispatcher. # #
# returns Dispatcher::Discord::Types::Response # def perform - response = fetcher.fetch + response = read.execute mappings = mapper.map(response) diff --git a/lib/bas/use_cases/use_cases.rb b/lib/bas/use_cases/use_cases.rb index 497de15..683bb93 100644 --- a/lib/bas/use_cases/use_cases.rb +++ b/lib/bas/use_cases/use_cases.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -# fetcher -require_relative "../fetcher/notion/use_case/birthday_today" -require_relative "../fetcher/notion/use_case/birthday_next_week" -require_relative "../fetcher/notion/use_case/pto_today" -require_relative "../fetcher/notion/use_case/pto_next_week" -require_relative "../fetcher/notion/use_case/work_items_limit" -require_relative "../fetcher/postgres/use_case/pto_today" -require_relative "../fetcher/imap/use_case/support_emails" -require_relative "../fetcher/github/use_case/repo_issues" +# read +require_relative "../read/notion/use_case/birthday_today" +require_relative "../read/notion/use_case/birthday_next_week" +require_relative "../read/notion/use_case/pto_today" +require_relative "../read/notion/use_case/pto_next_week" +require_relative "../read/notion/use_case/work_items_limit" +require_relative "../read/postgres/use_case/pto_today" +require_relative "../read/imap/use_case/support_emails" +require_relative "../read/github/use_case/repo_issues" # mapper require_relative "../mapper/notion/birthday_today" @@ -41,7 +41,7 @@ module UseCases # Example # # options = { - # fetch_options: { + # read_options: { # database_id: NOTION_DATABASE_ID, # secret: NOTION_API_INTEGRATION_SECRET, # }, @@ -75,11 +75,11 @@ module UseCases # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_birthday_from_notion_to_discord(options) - fetcher = Fetcher::Notion::BirthdayToday.new(options[:fetch_options]) + read = Read::Notion::BirthdayToday.new(options[:read_options]) mapper = Mapper::Notion::BirthdayToday.new formatter = Formatter::Birthday.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end @@ -89,7 +89,7 @@ def self.notify_birthday_from_notion_to_discord(options) # Example # # options = { - # fetch_options: { + # read_options: { # database_id: NOTION_DATABASE_ID, # secret: NOTION_API_INTEGRATION_SECRET, # }, @@ -127,11 +127,11 @@ def self.notify_birthday_from_notion_to_discord(options) # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_next_week_birthday_from_notion_to_discord(options) - fetcher = Fetcher::Notion::BirthdayNextWeek.new(options[:fetch_options]) + read = Read::Notion::BirthdayNextWeek.new(options[:read_options]) mapper = Mapper::Notion::BirthdayToday.new formatter = Formatter::Birthday.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_cofig = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_cofig) end @@ -142,7 +142,7 @@ def self.notify_next_week_birthday_from_notion_to_discord(options) # Example # # options = { - # fetch_options: { + # read_options: { # database_id: NOTION_DATABASE_ID, # secret: NOTION_API_INTEGRATION_SECRET, # }, @@ -174,11 +174,11 @@ def self.notify_next_week_birthday_from_notion_to_discord(options) # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_pto_from_notion_to_discord(options) - fetcher = Fetcher::Notion::PtoToday.new(options[:fetch_options]) + read = Read::Notion::PtoToday.new(options[:read_options]) mapper = Mapper::Notion::PtoToday.new formatter = Formatter::Pto.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end @@ -189,7 +189,7 @@ def self.notify_pto_from_notion_to_discord(options) # Example # # options = { - # fetch_options: { + # read_options: { # database_id: NOTION_DATABASE_ID, # secret: NOTION_API_INTEGRATION_SECRET, # }, @@ -225,11 +225,11 @@ def self.notify_pto_from_notion_to_discord(options) # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_next_week_pto_from_notion_to_discord(options) - fetcher = Fetcher::Notion::PtoNextWeek.new(options[:fetch_options]) + read = Read::Notion::PtoNextWeek.new(options[:read_options]) mapper = Mapper::Notion::PtoToday.new formatter = Formatter::Pto.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end @@ -240,7 +240,7 @@ def self.notify_next_week_pto_from_notion_to_discord(options) # Example # # options = { - # fetch_options: { + # read_options: { # connection: { # host: "localhost", # port: 5432, @@ -279,11 +279,11 @@ def self.notify_next_week_pto_from_notion_to_discord(options) # https://api.slack.com/messaging/webhooks#create_a_webhook # def self.notify_pto_from_postgres_to_slack(options) - fetcher = Fetcher::Postgres::PtoToday.new(options[:fetch_options]) + read = Read::Postgres::PtoToday.new(options[:read_options]) mapper = Mapper::Postgres::PtoToday.new formatter = Formatter::Pto.new(options[:format_options]) dispatcher = Dispatcher::Slack::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end @@ -294,7 +294,7 @@ def self.notify_pto_from_postgres_to_slack(options) # Example # # options = { - # fetch_options: { + # read_options: { # database_id: NOTION_DATABASE_ID, # secret: NOTION_API_INTEGRATION_SECRET # }, @@ -326,11 +326,11 @@ def self.notify_pto_from_postgres_to_slack(options) # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_wip_limit_from_notion_to_discord(options) - fetcher = Fetcher::Notion::WorkItemsLimit.new(options[:fetch_options]) + read = Read::Notion::WorkItemsLimit.new(options[:read_options]) mapper = Mapper::Notion::WorkItemsLimit.new formatter = Formatter::WorkItemsLimit.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end @@ -341,7 +341,7 @@ def self.notify_wip_limit_from_notion_to_discord(options) # Example # # options = { - # fetch_options: { + # read_options: { # user: 'info@email.co', # refresh_token: REFRESH_TOKEN, # client_id: CLIENT_ID, @@ -368,11 +368,11 @@ def self.notify_wip_limit_from_notion_to_discord(options) # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks # def self.notify_support_email_from_imap_to_discord(options) - fetcher = Fetcher::Imap::SupportEmails.new(options[:fetch_options]) + read = Read::Imap::SupportEmails.new(options[:read_options]) mapper = Mapper::Imap::SupportEmails.new formatter = Formatter::SupportEmails.new(options[:format_options]) dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options]) - use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) + use_case_config = UseCases::Types::Config.new(read, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end diff --git a/spec/bas/fetcher/base_spec.rb b/spec/bas/fetcher/base_spec.rb deleted file mode 100644 index 626f556..0000000 --- a/spec/bas/fetcher/base_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Base do - before do - config = {} - @fetcher = described_class.new(config) - end - - describe "Arguments and methods" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "provides no implementation for the method" do - expect { @fetcher.fetch }.to raise_exception(Domain::Exceptions::FunctionNotImplemented) - end - end -end diff --git a/spec/bas/fetcher/notion/birthday_next_week_spec.rb b/spec/bas/fetcher/notion/birthday_next_week_spec.rb deleted file mode 100644 index efb81cb..0000000 --- a/spec/bas/fetcher/notion/birthday_next_week_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Notion::BirthdayNextWeek do - before do - @config = { - database_id: "5aebbdc871864f4fbab5596a41a81a01", - secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" - } - - @fetcher = described_class.new(@config) - end - - describe "attributes and arguments" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "fetch data from the given configured notion database" do - VCR.use_cassette("/notion/birthdays_next_week/fetch_with_filter") do - birthdays_fetcher = described_class.new(@config) - fetched_data = birthdays_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(1) - end - end - - it "fetch empty data from the given configured notion database" do - VCR.use_cassette("/notion/birthdays_next_week/fetch_with_empty_database") do - config = @config - config[:database_id] = "8187370982134ed099f9d14385aa81c9" - - birthday_fetcher = described_class.new(config) - fetched_data = birthday_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) - end - end - - it "raises an exception caused by invalid database_id provided" do - VCR.use_cassette("/notion/birthdays_next_week/fetch_with_invalid_database_id") do - config = @config - config[:database_id] = "c17e556d16c84272beb4ee73ab709631" - birthday_fetcher = described_class.new(@config) - - expected_exception = "Could not find database with ID: c17e556d-16c8-4272-beb4-ee73ab709631. " \ - "Make sure the relevant pages and databases are shared with your integration." - - expect do - birthday_fetcher.fetch - end.to raise_exception(expected_exception) - end - end - - it "raise an exception caused by invalid or incorrect api_key provided" do - VCR.use_cassette("/notion/birthdays_next_week/fetch_with_invalid_api_key") do - config = @config - config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - birthday_fetcher = described_class.new(config) - - expect { birthday_fetcher.fetch }.to raise_exception("API token is invalid.") - end - end - end -end diff --git a/spec/bas/fetcher/notion/birthday_today_spec.rb b/spec/bas/fetcher/notion/birthday_today_spec.rb deleted file mode 100644 index 026c358..0000000 --- a/spec/bas/fetcher/notion/birthday_today_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Notion::BirthdayToday do - before do - @config = { - database_id: "c17e556d16c84272beb4ee73ab709631", - secret: "secret_BELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51B" - } - - @fetcher = described_class.new(@config) - end - - describe "attributes and arguments" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "fetch data from the given configured notion database" do - VCR.use_cassette("/notion/birthdays/fetch_with_filter") do - birthdays_fetcher = described_class.new(@config) - fetched_data = birthdays_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(1) - end - end - - it "fetch empty data from the given configured notion database" do - VCR.use_cassette("/notion/birthdays/fetch_with_empty_database") do - config = @config - config[:database_id] = "a3de68d2848a4eceb9418ff6bf44d086" - - birthday_fetcher = described_class.new(config) - fetched_data = birthday_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) - end - end - - it "raises an exception caused by invalid database_id provided" do - VCR.use_cassette("/notion/birthdays/fetch_with_invalid_database_id") do - config = @config - config[:database_id] = "a17e556d16c84272beb4ee73ab709630" - birthday_fetcher = described_class.new(@config) - - expected_exception = "Could not find database with ID: c17e556d-16c8-4272-beb4-ee73ab709631. " \ - "Make sure the relevant pages and databases are shared with your integration." - - expect do - birthday_fetcher.fetch - end.to raise_exception(expected_exception) - end - end - - it "raise an exception caused by invalid or incorrect api_key provided" do - VCR.use_cassette("/notion/birthdays/fetch_with_invalid_api_key") do - config = @config - config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - birthday_fetcher = described_class.new(config) - - expect { birthday_fetcher.fetch }.to raise_exception("API token is invalid.") - end - end - end -end diff --git a/spec/bas/fetcher/notion/pto_next_week_spec.rb b/spec/bas/fetcher/notion/pto_next_week_spec.rb deleted file mode 100644 index 0b777af..0000000 --- a/spec/bas/fetcher/notion/pto_next_week_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Notion::PtoNextWeek do - before do - @config = { - database_id: "8187370982134ed099f9d14385aa81c9", - secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" - } - - @fetcher = described_class.new(@config) - end - - describe "attributes and arguments" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "fetch data from the given configured notion database" do - VCR.use_cassette("/notion/pto_next_week/fetch_with_filter") do - pto_fetcher = described_class.new(@config) - fetched_data = pto_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(3) - end - end - - it "fetch empty data from the given configured notion database" do - VCR.use_cassette("/notion/pto_next_week/fetch_with_empty_database") do - config = @config - config[:database_id] = "68bcbb5f76e14e5eb00ff6726bd90f6c" - - pto_fetcher = described_class.new(config) - fetched_data = pto_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) - end - end - - it "raises an exception caused by invalid database_id provided" do - VCR.use_cassette("/notion/pto_next_week/fetch_with_invalid_database_id") do - config = @config - config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" - pto_fetcher = described_class.new(config) - - expect do - pto_fetcher.fetch - end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ - "Make sure the relevant pages and databases are shared with your integration.") - end - end - - it "raises an exception caused by invalid or incorrect api_key provided" do - VCR.use_cassette("/notion/pto_next_week/fetch_with_invalid_api_key") do - config = @config - config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - pto_fetcher = described_class.new(config) - - expect { pto_fetcher.fetch }.to raise_exception("API token is invalid.") - end - end - end -end diff --git a/spec/bas/fetcher/notion/pto_today_spec.rb b/spec/bas/fetcher/notion/pto_today_spec.rb deleted file mode 100644 index 784c6f6..0000000 --- a/spec/bas/fetcher/notion/pto_today_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Notion::PtoToday do - before do - @config = { - database_id: "b68d11061aad43bd89f8f525ede2b598", - secret: "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - } - - @fetcher = described_class.new(@config) - end - - describe "attributes and arguments" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "fetch data from the given configured notion database" do - VCR.use_cassette("/notion/ptos/fetch_with_filter") do - pto_fetcher = described_class.new(@config) - fetched_data = pto_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(3) - end - end - - it "fetch empty data from the given configured notion database" do - VCR.use_cassette("/notion/ptos/fetch_with_empty_database") do - config = @config - config[:database_id] = "86772de276d24ed986713640919edf96" - - pto_fetcher = described_class.new(config) - fetched_data = pto_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) - end - end - - it "raises an exception caused by invalid database_id provided" do - VCR.use_cassette("/notion/ptos/fetch_with_invalid_database_id") do - config = @config - config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" - pto_fetcher = described_class.new(config) - - expect do - pto_fetcher.fetch - end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ - "Make sure the relevant pages and databases are shared with your integration.") - end - end - - it "raises an exception caused by invalid or incorrect api_key provided" do - VCR.use_cassette("/notion/ptos/fetch_with_invalid_api_key") do - config = @config - config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - pto_fetcher = described_class.new(config) - - expect { pto_fetcher.fetch }.to raise_exception("API token is invalid.") - end - end - end -end diff --git a/spec/bas/fetcher/notion/work_items_limit_spec.rb b/spec/bas/fetcher/notion/work_items_limit_spec.rb deleted file mode 100644 index 3a48256..0000000 --- a/spec/bas/fetcher/notion/work_items_limit_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe Fetcher::Notion::WorkItemsLimit do - before do - @config = { - database_id: "52e4040938e945ceb2e6895ce5a0d51e", - secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" - } - - @fetcher = described_class.new(@config) - end - - describe "attributes and arguments" do - it { expect(@fetcher).to respond_to(:config) } - - it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } - end - - describe ".fetch" do - it "fetch data from the given configured notion database" do - VCR.use_cassette("/notion/wip_limit/fetch_without_filter") do - wip_fetcher = described_class.new(@config) - fetched_data = wip_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(3) - end - end - - it "fetch empty data from the given configured notion database" do - VCR.use_cassette("/notion/wip_limit/fetch_with_empty_database") do - config = @config - config[:database_id] = "5aebbdc871864f4fbab5596a41a81a01" - - wip_fetcher = described_class.new(config) - fetched_data = wip_fetcher.fetch - - expect(fetched_data).to be_an_instance_of(Fetcher::Notion::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) - end - end - - it "raises an exception caused by invalid database_id provided" do - VCR.use_cassette("/notion/wip_limit/fetch_with_invalid_database_id") do - config = @config - config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" - wip_fetcher = described_class.new(config) - - expect do - wip_fetcher.fetch - end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ - "Make sure the relevant pages and databases are shared with your integration.") - end - end - - it "raises an exception caused by invalid or incorrect api_key provided" do - VCR.use_cassette("/notion/wip_limit/fetch_with_invalid_api_key") do - config = @config - config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" - wip_fetcher = described_class.new(config) - - expect { wip_fetcher.fetch }.to raise_exception("API token is invalid.") - end - end - end -end diff --git a/spec/bas/mapper/github/issues_spec.rb b/spec/bas/mapper/github/issues_spec.rb index 7adbf2d..9125c73 100644 --- a/spec/bas/mapper/github/issues_spec.rb +++ b/spec/bas/mapper/github/issues_spec.rb @@ -13,7 +13,7 @@ end before do - @imap_response = Fetcher::Github::Types::Response.new(issues) + @imap_response = Read::Github::Types::Response.new(issues) @mapper = described_class.new end diff --git a/spec/bas/mapper/imap/support_emails_spec.rb b/spec/bas/mapper/imap/support_emails_spec.rb index 654d43d..114fad5 100644 --- a/spec/bas/mapper/imap/support_emails_spec.rb +++ b/spec/bas/mapper/imap/support_emails_spec.rb @@ -5,7 +5,7 @@ let(:emails) { [double("email", date: "2024-03-13T12:00:00.000-05:00", subject: "subject", sender: sender)] } before do - @imap_response = Fetcher::Imap::Types::Response.new(emails) + @imap_response = Read::Imap::Types::Response.new(emails) @mapper = described_class.new end diff --git a/spec/bas/mapper/notion/birthday_today_spec.rb b/spec/bas/mapper/notion/birthday_today_spec.rb index 28488ad..356b58e 100644 --- a/spec/bas/mapper/notion/birthday_today_spec.rb +++ b/spec/bas/mapper/notion/birthday_today_spec.rb @@ -3,7 +3,7 @@ RSpec.describe Mapper::Notion::BirthdayToday do before do @mapper = described_class.new - fetcher_config = { + reader_config = { base_url: "https://api.notion.com", database_id: "c17e556d16c84272beb4ee73ab709631", secret: "secret_BELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51B", @@ -21,7 +21,7 @@ "sorts": [] } } - @fetcher = Fetcher::Notion::BirthdayToday.new(fetcher_config) + @read = Read::Notion::BirthdayToday.new(reader_config) end describe "attributes and arguments" do @@ -31,8 +31,8 @@ describe ".map" do it "maps the given data into a domain specific one" do - VCR.use_cassette("/notion/birthdays/fetch_with_filter") do - birthdays_response = @fetcher.fetch + VCR.use_cassette("/notion/birthdays/read_with_filter") do + birthdays_response = @read.execute mapped_data = @mapper.map(birthdays_response) diff --git a/spec/bas/mapper/notion/pto_spec.rb b/spec/bas/mapper/notion/pto_spec.rb index 3612c95..f2e141f 100644 --- a/spec/bas/mapper/notion/pto_spec.rb +++ b/spec/bas/mapper/notion/pto_spec.rb @@ -3,10 +3,10 @@ RSpec.describe Mapper::Notion::PtoToday do before do @mapper = described_class.new - fetcher_config = { + reader_config = { base_url: "https://api.notion.com", - database_id: "b68d11061aad43bd89f8f525ede2b598", - secret: "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C", + database_id: "8187370982134ed099f9d14385aa81c9", + secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC", filter: { "filter": { "and": [ @@ -27,7 +27,7 @@ "sorts": [] } } - @fetcher = Fetcher::Notion::PtoToday.new(fetcher_config) + @read = Read::Notion::PtoToday.new(reader_config) end describe "attributes and arguments" do @@ -37,8 +37,8 @@ describe ".map" do it "maps the given data into a domain specific one" do - VCR.use_cassette("/notion/ptos/fetch_with_filter") do - ptos_response = @fetcher.fetch + VCR.use_cassette("/notion/ptos/read_with_filter") do + ptos_response = @read.execute mapped_data = @mapper.map(ptos_response) are_ptos = mapped_data.all? { |element| element.is_a?(Domain::Pto) } diff --git a/spec/bas/mapper/notion/work_items_limit_spec.rb b/spec/bas/mapper/notion/work_items_limit_spec.rb index 4d6c8f6..48627f2 100644 --- a/spec/bas/mapper/notion/work_items_limit_spec.rb +++ b/spec/bas/mapper/notion/work_items_limit_spec.rb @@ -11,7 +11,7 @@ notion_result = { "results" => [item1, item2, item3] } - @notion_response = Fetcher::Notion::Types::Response.new(notion_result) + @notion_response = Read::Notion::Types::Response.new(notion_result) @mapper = described_class.new end diff --git a/spec/bas/mapper/postgres/pto_spec.rb b/spec/bas/mapper/postgres/pto_spec.rb index 5b7dad1..a5181b9 100644 --- a/spec/bas/mapper/postgres/pto_spec.rb +++ b/spec/bas/mapper/postgres/pto_spec.rb @@ -11,7 +11,7 @@ allow(pg_result).to receive(:fields).and_return(fields) allow(pg_result).to receive(:values).and_return(values) - @pg_response = Fetcher::Postgres::Types::Response.new(pg_result) + @pg_response = Read::Postgres::Types::Response.new(pg_result) @mapper = described_class.new end diff --git a/spec/bas/read/base_spec.rb b/spec/bas/read/base_spec.rb new file mode 100644 index 0000000..963c7a2 --- /dev/null +++ b/spec/bas/read/base_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +RSpec.describe Read::Base do + before do + config = {} + @read = described_class.new(config) + end + + describe "Arguments and methods" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".execute" do + it "provides no implementation for the method" do + expect { @read.execute }.to raise_exception(Domain::Exceptions::FunctionNotImplemented) + end + end +end diff --git a/spec/bas/fetcher/github/repo_issues_spec.rb b/spec/bas/read/github/repo_issues_spec.rb similarity index 55% rename from spec/bas/fetcher/github/repo_issues_spec.rb rename to spec/bas/read/github/repo_issues_spec.rb index 4220824..1b78312 100644 --- a/spec/bas/fetcher/github/repo_issues_spec.rb +++ b/spec/bas/read/github/repo_issues_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Fetcher::Github::RepoIssues do +RSpec.describe Read::Github::RepoIssues do before do config = { app_id: "123456", @@ -9,17 +9,17 @@ repo: "Organization/Repository" } - @fetcher = described_class.new(config) + @read = described_class.new(config) end describe "attributes and arguments" do it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:config) } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } + it { expect(@read).to respond_to(:config) } + it { expect(@read).to respond_to(:execute).with(0).arguments } end - describe ".fetch" do + describe ".execute" do let(:empty_response) { [] } let(:response) { [{ url: "repo_url" }] } @@ -38,24 +38,24 @@ allow(Octokit::Client).to receive(:new).and_return(octokit) end - it "fetch issues from the Github repo when there are no 'issues'" do + it "read issues from the Github repo when there are no 'issues'" do allow(octokit).to receive(:public_send).and_return(empty_response) - fetched_data = @fetcher.fetch + read_data = @read.execute - expect(fetched_data).to be_an_instance_of(Fetcher::Github::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(0) + expect(read_data).to be_an_instance_of(Read::Github::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) end - it "fetch issues from the Github repo when there are 'issues'" do + it "read issues from the Github repo when there are 'issues'" do allow(octokit).to receive(:public_send).and_return(response) - fetched_data = @fetcher.fetch + read_data = @read.execute - expect(fetched_data).to be_an_instance_of(Fetcher::Github::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(1) + expect(read_data).to be_an_instance_of(Read::Github::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(1) end end end diff --git a/spec/bas/fetcher/imap/support_email_spec.rb b/spec/bas/read/imap/support_email_spec.rb similarity index 64% rename from spec/bas/fetcher/imap/support_email_spec.rb rename to spec/bas/read/imap/support_email_spec.rb index 7e6746a..489bbd1 100644 --- a/spec/bas/fetcher/imap/support_email_spec.rb +++ b/spec/bas/read/imap/support_email_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Fetcher::Imap::SupportEmails do +RSpec.describe Read::Imap::SupportEmails do before do config = { user: "user@mail.co", @@ -11,17 +11,17 @@ search_email: "support@mail.co" } - @fetcher = described_class.new(config) + @read = described_class.new(config) end describe "attributes and arguments" do it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:config) } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } + it { expect(@read).to respond_to(:config) } + it { expect(@read).to respond_to(:execute).with(0).arguments } end - describe ".fetch" do + describe ".execute" do let(:body) { "{\"access_token\":\"ABCDEFG\"}" } let(:response) { double("http_respose", body: body) } @@ -43,12 +43,12 @@ allow(Net::IMAP).to receive(:new).and_return(imap) end - it "fetch emails from the IMAP when there are results" do - fetched_data = @fetcher.fetch + it "read emails from the IMAP when there are results" do + read_data = @read.execute - expect(fetched_data).to be_an_instance_of(Fetcher::Imap::Types::Response) - expect(fetched_data.results).to be_an_instance_of(Array) - expect(fetched_data.results.length).to eq(4) + expect(read_data).to be_an_instance_of(Read::Imap::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(4) end end end diff --git a/spec/bas/read/notion/birthday_next_week_spec.rb b/spec/bas/read/notion/birthday_next_week_spec.rb new file mode 100644 index 0000000..b177545 --- /dev/null +++ b/spec/bas/read/notion/birthday_next_week_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +RSpec.describe Read::Notion::BirthdayNextWeek do + before do + @config = { + database_id: "5aebbdc871864f4fbab5596a41a81a01", + secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" + } + + @read = described_class.new(@config) + end + + describe "attributes and arguments" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".execute" do + it "read data from the given configured notion database" do + VCR.use_cassette("/notion/birthdays_next_week/read_with_filter") do + birthdays_reader = described_class.new(@config) + read_data = birthdays_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(1) + end + end + + it "read empty data from the given configured notion database" do + VCR.use_cassette("/notion/birthdays_next_week/read_with_empty_database") do + config = @config + config[:database_id] = "8187370982134ed099f9d14385aa81c9" + + birthday_reader = described_class.new(config) + read_data = birthday_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) + end + end + + it "raises an exception caused by invalid database_id provided" do + VCR.use_cassette("/notion/birthdays_next_week/read_with_invalid_database_id") do + config = @config + config[:database_id] = "c17e556d16c84272beb4ee73ab709631" + birthday_reader = described_class.new(@config) + + expected_exception = "Could not find database with ID: c17e556d-16c8-4272-beb4-ee73ab709631. " \ + "Make sure the relevant pages and databases are shared with your integration." + + expect do + birthday_reader.execute + end.to raise_exception(expected_exception) + end + end + + it "raise an exception caused by invalid or incorrect api_key provided" do + VCR.use_cassette("/notion/birthdays_next_week/read_with_invalid_api_key") do + config = @config + config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + birthday_reader = described_class.new(config) + + expect { birthday_reader.execute }.to raise_exception("API token is invalid.") + end + end + end +end diff --git a/spec/bas/read/notion/birthday_today_spec.rb b/spec/bas/read/notion/birthday_today_spec.rb new file mode 100644 index 0000000..db2e4cc --- /dev/null +++ b/spec/bas/read/notion/birthday_today_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +RSpec.describe Read::Notion::BirthdayToday do + before do + @config = { + database_id: "c17e556d16c84272beb4ee73ab709631", + secret: "secret_BELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51B" + } + + @read = described_class.new(@config) + end + + describe "attributes and arguments" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".execute" do + it "read data from the given configured notion database" do + VCR.use_cassette("/notion/birthdays/read_with_filter") do + birthdays_reader = described_class.new(@config) + read_data = birthdays_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(1) + end + end + + it "read empty data from the given configured notion database" do + VCR.use_cassette("/notion/birthdays/read_with_empty_database") do + config = @config + config[:database_id] = "a3de68d2848a4eceb9418ff6bf44d086" + + birthday_reader = described_class.new(config) + read_data = birthday_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) + end + end + + it "raises an exception caused by invalid database_id provided" do + VCR.use_cassette("/notion/birthdays/read_with_invalid_database_id") do + config = @config + config[:database_id] = "a17e556d16c84272beb4ee73ab709630" + birthday_reader = described_class.new(@config) + + expected_exception = "Could not find database with ID: c17e556d-16c8-4272-beb4-ee73ab709631. " \ + "Make sure the relevant pages and databases are shared with your integration." + + expect do + birthday_reader.execute + end.to raise_exception(expected_exception) + end + end + + it "raise an exception caused by invalid or incorrect api_key provided" do + VCR.use_cassette("/notion/birthdays/read_with_invalid_api_key") do + config = @config + config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + birthday_reader = described_class.new(config) + + expect { birthday_reader.execute }.to raise_exception("API token is invalid.") + end + end + end +end diff --git a/spec/bas/read/notion/pto_next_week_spec.rb b/spec/bas/read/notion/pto_next_week_spec.rb new file mode 100644 index 0000000..2050ff3 --- /dev/null +++ b/spec/bas/read/notion/pto_next_week_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +RSpec.describe Read::Notion::PtoNextWeek do + before do + @config = { + database_id: "8187370982134ed099f9d14385aa81c9", + secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" + } + + @read = described_class.new(@config) + end + + describe "attributes and arguments" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".read" do + it "read data from the given configured notion database" do + VCR.use_cassette("/notion/pto_next_week/read_with_filter") do + pto_reader = described_class.new(@config) + read_data = pto_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(3) + end + end + + it "read empty data from the given configured notion database" do + VCR.use_cassette("/notion/pto_next_week/read_with_empty_database") do + config = @config + config[:database_id] = "68bcbb5f76e14e5eb00ff6726bd90f6c" + + pto_reader = described_class.new(config) + read_data = pto_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) + end + end + + it "raises an exception caused by invalid database_id provided" do + VCR.use_cassette("/notion/pto_next_week/read_with_invalid_database_id") do + config = @config + config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" + pto_reader = described_class.new(config) + + expect do + pto_reader.execute + end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ + "Make sure the relevant pages and databases are shared with your integration.") + end + end + + it "raises an exception caused by invalid or incorrect api_key provided" do + VCR.use_cassette("/notion/pto_next_week/read_with_invalid_api_key") do + config = @config + config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + pto_reader = described_class.new(config) + + expect { pto_reader.execute }.to raise_exception("API token is invalid.") + end + end + end +end diff --git a/spec/bas/read/notion/pto_today_spec.rb b/spec/bas/read/notion/pto_today_spec.rb new file mode 100644 index 0000000..6596f31 --- /dev/null +++ b/spec/bas/read/notion/pto_today_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +RSpec.describe Read::Notion::PtoToday do + before do + @config = { + database_id: "b68d11061aad43bd89f8f525ede2b598", + secret: "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + } + + @read = described_class.new(@config) + end + + describe "attributes and arguments" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".execute" do + it "read data from the given configured notion database" do + VCR.use_cassette("/notion/ptos/read_with_filter") do + pto_reader = described_class.new(@config) + read_data = pto_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(3) + end + end + + it "read empty data from the given configured notion database" do + VCR.use_cassette("/notion/ptos/read_with_empty_database") do + config = @config + config[:database_id] = "86772de276d24ed986713640919edf96" + + pto_reader = described_class.new(config) + read_data = pto_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) + end + end + + it "raises an exception caused by invalid database_id provided" do + VCR.use_cassette("/notion/ptos/read_with_invalid_database_id") do + config = @config + config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" + pto_reader = described_class.new(config) + + expect do + pto_reader.execute + end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ + "Make sure the relevant pages and databases are shared with your integration.") + end + end + + it "raises an exception caused by invalid or incorrect api_key provided" do + VCR.use_cassette("/notion/ptos/read_with_invalid_api_key") do + config = @config + config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + pto_reader = described_class.new(config) + + expect { pto_reader.execute }.to raise_exception("API token is invalid.") + end + end + end +end diff --git a/spec/bas/read/notion/work_items_limit_spec.rb b/spec/bas/read/notion/work_items_limit_spec.rb new file mode 100644 index 0000000..22020bf --- /dev/null +++ b/spec/bas/read/notion/work_items_limit_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +RSpec.describe Read::Notion::WorkItemsLimit do + before do + @config = { + database_id: "52e4040938e945ceb2e6895ce5a0d51e", + secret: "secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC" + } + + @read = described_class.new(@config) + end + + describe "attributes and arguments" do + it { expect(@read).to respond_to(:config) } + + it { expect(described_class).to respond_to(:new).with(1).arguments } + it { expect(@read).to respond_to(:execute).with(0).arguments } + end + + describe ".execute" do + it "read data from the given configured notion database" do + VCR.use_cassette("/notion/wip_limit/read_without_filter") do + wip_reader = described_class.new(@config) + read_data = wip_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(3) + end + end + + it "read empty data from the given configured notion database" do + VCR.use_cassette("/notion/wip_limit/read_with_empty_database") do + config = @config + config[:database_id] = "5aebbdc871864f4fbab5596a41a81a01" + + wip_reader = described_class.new(config) + read_data = wip_reader.execute + + expect(read_data).to be_an_instance_of(Read::Notion::Types::Response) + expect(read_data.results).to be_an_instance_of(Array) + expect(read_data.results.length).to eq(0) + end + end + + it "raises an exception caused by invalid database_id provided" do + VCR.use_cassette("/notion/wip_limit/read_with_invalid_database_id") do + config = @config + config[:database_id] = "b68d11061aad43bd89f8f525ede2b598" + wip_reader = described_class.new(config) + + expect do + wip_reader.execute + end.to raise_exception("Could not find database with ID: b68d1106-1aad-43bd-89f8-f525ede2b598. " \ + "Make sure the relevant pages and databases are shared with your integration.") + end + end + + it "raises an exception caused by invalid or incorrect api_key provided" do + VCR.use_cassette("/notion/wip_limit/read_with_invalid_api_key") do + config = @config + config[:secret] = "secret_ZELfDH6cf4Glc9NLPLxvsvdl9iZVD4qBCyMDXqch51C" + wip_reader = described_class.new(config) + + expect { wip_reader.execute }.to raise_exception("API token is invalid.") + end + end + end +end diff --git a/spec/bas/fetcher/postgres/pto_today_spec.rb b/spec/bas/read/postgres/pto_today_spec.rb similarity index 77% rename from spec/bas/fetcher/postgres/pto_today_spec.rb rename to spec/bas/read/postgres/pto_today_spec.rb index d880f57..3e116aa 100644 --- a/spec/bas/fetcher/postgres/pto_today_spec.rb +++ b/spec/bas/read/postgres/pto_today_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Fetcher::Postgres::PtoToday do +RSpec.describe Read::Postgres::PtoToday do before do config = { connection: { @@ -12,17 +12,17 @@ } } - @fetcher = described_class.new(config) + @read = described_class.new(config) end describe "attributes and arguments" do it { expect(described_class).to respond_to(:new).with(1).arguments } - it { expect(@fetcher).to respond_to(:config) } - it { expect(@fetcher).to respond_to(:fetch).with(0).arguments } + it { expect(@read).to respond_to(:config) } + it { expect(@read).to respond_to(:execute).with(0).arguments } end - describe ".fetch" do + describe ".execute" do let(:pg_conn) { instance_double(PG::Connection) } let(:fields) { %w[id individual_name start_date end_date] } let(:values) { [%w[5 2024-02-13 user1 2024-02-13 2024-02-14]] } @@ -37,11 +37,11 @@ allow(pg_conn).to receive(:exec_params).and_return(@pg_result) end - it "fetch data from the postgres database when there are results" do + it "read data from the postgres database when there are results" do allow(@pg_result).to receive(:res_status).and_return("PGRES_TUPLES_OK") allow(@pg_result).to receive(:check_result).and_return(nil) - pg_response = @fetcher.fetch + pg_response = @read.execute expect(pg_response.status).to eq("PGRES_TUPLES_OK") expect(pg_response.message).to eq("success") @@ -49,13 +49,13 @@ expect(pg_response.records).to eq(values) end - it "fetch data from the postgres database when there are no results" do + it "read data from the postgres database when there are no results" do allow(@pg_result).to receive(:fields).and_return([]) allow(@pg_result).to receive(:values).and_return([]) allow(@pg_result).to receive(:res_status).and_return("PGRES_TUPLES_OK") allow(@pg_result).to receive(:check_result).and_return(nil) - pg_response = @fetcher.fetch + pg_response = @read.execute expect(pg_response.status).to eq("PGRES_TUPLES_OK") expect(pg_response.message).to eq("success") @@ -63,12 +63,12 @@ expect(pg_response.records).to eq([]) end - it "fetch data from the postgres databases with a failure status" do + it "read data from the postgres databases with a failure status" do allow(@pg_result).to receive(:res_status).and_return("PGRES_EMPTY_QUERY") allow(@pg_result).to receive(:result_error_message).and_return("the query is empty") allow(@pg_result).to receive(:check_result).and_return(nil) - pg_response = @fetcher.fetch + pg_response = @read.execute expect(pg_response.status).to eq("PGRES_EMPTY_QUERY") expect(pg_response.message).to eq("the query is empty") @@ -76,14 +76,14 @@ expect(pg_response.records).to eq(nil) end - it "fetch data from the postgres databases with a bad state" do + it "read data from the postgres databases with a bad state" do error_to_raise = PG::Error.new allow(@pg_result).to receive(:res_status).and_return("PGRES_BAD_RESPONSE") allow(@pg_result).to receive(:result_error_message).and_return("bad response") allow(@pg_result).to receive(:check_result).and_raise(error_to_raise) - expect { @fetcher.fetch }.to raise_exception(error_to_raise) + expect { @read.execute }.to raise_exception(error_to_raise) end end end diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_empty_database.yml b/spec/fixtures/vcr_cassettes/notion/birthdays/read_with_empty_database.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_empty_database.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays/read_with_empty_database.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_filter.yml b/spec/fixtures/vcr_cassettes/notion/birthdays/read_with_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_filter.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays/read_with_filter.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_invalid_api_key.yml b/spec/fixtures/vcr_cassettes/notion/birthdays/read_with_invalid_api_key.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_invalid_api_key.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays/read_with_invalid_api_key.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_invalid_database_id.yml b/spec/fixtures/vcr_cassettes/notion/birthdays/read_with_invalid_database_id.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays/fetch_with_invalid_database_id.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays/read_with_invalid_database_id.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays/fetch_without_filter.yml b/spec/fixtures/vcr_cassettes/notion/birthdays/read_without_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays/fetch_without_filter.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays/read_without_filter.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_empty_database.yml b/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_empty_database.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_empty_database.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_empty_database.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_filter.yml b/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_filter.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_filter.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_invalid_api_key.yml b/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_invalid_api_key.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_invalid_api_key.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_invalid_api_key.yml diff --git a/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_invalid_database_id.yml b/spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_invalid_database_id.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/birthdays_next_week/fetch_with_invalid_database_id.yml rename to spec/fixtures/vcr_cassettes/notion/birthdays_next_week/read_with_invalid_database_id.yml diff --git a/spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_empty_database.yml b/spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_empty_database.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_empty_database.yml rename to spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_empty_database.yml diff --git a/spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_filter.yml b/spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_filter.yml rename to spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_filter.yml diff --git a/spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_invalid_api_key.yml b/spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_invalid_api_key.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_invalid_api_key.yml rename to spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_invalid_api_key.yml diff --git a/spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_invalid_database_id.yml b/spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_invalid_database_id.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/pto_next_week/fetch_with_invalid_database_id.yml rename to spec/fixtures/vcr_cassettes/notion/pto_next_week/read_with_invalid_database_id.yml diff --git a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_empty_database.yml b/spec/fixtures/vcr_cassettes/notion/ptos/read_with_empty_database.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_empty_database.yml rename to spec/fixtures/vcr_cassettes/notion/ptos/read_with_empty_database.yml diff --git a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_filter.yml b/spec/fixtures/vcr_cassettes/notion/ptos/read_with_filter.yml similarity index 62% rename from spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_filter.yml rename to spec/fixtures/vcr_cassettes/notion/ptos/read_with_filter.yml index 2e176de..95d714f 100644 --- a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_filter.yml +++ b/spec/fixtures/vcr_cassettes/notion/ptos/read_with_filter.yml @@ -55,4 +55,60 @@ http_interactions: string: !binary |- eyJvYmplY3QiOiJsaXN0IiwicmVzdWx0cyI6W3sib2JqZWN0IjoicGFnZSIsImlkIjoiMWNlYTMyYjgtNDM4Ni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wZSI6ImRhdGUiLCJkYXRlIjp7InN0YXJ0IjoiMjAyNC0wMS0yMiIsImVuZCI6bnVsbCwidGltZV96b25lIjpudWxsfX0sIkRlc2RlPyB5IEhhc3RhPyI6eyJpZCI6IiU1RGQlNjBoIiwidHlwZSI6ImRhdGUiLCJkYXRlIjp7InN0YXJ0IjoiMjAyNC0wMS0yMiIsImVuZCI6IjIwMjQtMDEtMjUiLCJ0aW1lX3pvbmUiOm51bGx9fSwiUHJveWVjdG8iOnsiaWQiOiJhZUtyIiwidHlwZSI6InNlbGVjdCIsInNlbGVjdCI6eyJpZCI6ImQ0N2Q0NDgwLTA4ZjQtNDE4OS1hZTNiLWFkZjJiMDZkYzVjYiIsIm5hbWUiOiJDb2xsYWJyYSIsImNvbG9yIjoib3JhbmdlIn19LCJUb2RheT8iOnsiaWQiOiJjJTQwJTYwJTdEIiwidHlwZSI6ImZvcm11bGEiLCJmb3JtdWxhIjp7InR5cGUiOiJib29sZWFuIiwiYm9vbGVhbiI6dHJ1ZX19LCJOYW1lIjp7ImlkIjoidGl0bGUiLCJ0eXBlIjoidGl0bGUiLCJ0aXRsZSI6W119fSwidXJsIjoiaHR0cHM6Ly93d3cubm90aW9uLnNvL2NjODQ5ZjIwODZlNDRkYzJiMmFjM2VmYjA1MjQxYjRlIiwicHVibGljX3VybCI6bnVsbH1dLCJuZXh0X2N1cnNvciI6bnVsbCwiaGFzX21vcmUiOmZhbHNlLCJ0eXBlIjoicGFnZV9vcl9kYXRhYmFzZSIsInBhZ2Vfb3JfZGF0YWJhc2UiOnt9LCJyZXF1ZXN0X2lkIjoiYjkxNWU5NjYtNGM4Ni00ZGQ3LWFlZTktZTZiMjk2MDMxZjc3In0= recorded_at: Wed, 24 Jan 2024 15:21:27 GMT +- request: + method: post + uri: https://api.notion.com/v1/databases/8187370982134ed099f9d14385aa81c9/query + body: + encoding: UTF-8 + string: '{"filter":{"and":[{"property":"Desde?","date":{"on_or_before":"2024-04-08"}},{"property":"Hasta?","date":{"on_or_after":"2024-04-08"}}]}}' + headers: + Authorization: + - Bearer secret_K5UCqm27GvAscTlaGJmS2se4fyM1K7is3OIZMw03NaC + Content-Type: + - application/json + Notion-Version: + - '2022-06-28' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 08 Apr 2024 22:07:56 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + X-Powered-By: + - Express + X-Notion-Request-Id: + - 2c6398e6-2163-49ac-961f-3d394f12a49f + Etag: + - W/"c9b-zC4LpTN6CmJl9u7AuCQd2NjMGn0" + Vary: + - Accept-Encoding + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - __cf_bm=P6MJX6fXfzsolIESXzhfsVZ_plmm8zMqT6.i3HUvYZw-1712614076-1.0.1.1-om.VM.xPaTFOTu8TJfuX46L9kl0Gd20LAUiYEeY0mgHLlLL5AYAud7w7ldUAbobhZ7QKL6ZgWdPKvWKKh4Eylw; + path=/; expires=Mon, 08-Apr-24 22:37:56 GMT; domain=.notion.com; HttpOnly; + Secure; SameSite=None + Server: + - cloudflare + Cf-Ray: + - 871592bb6bd4f7b8-BOG + body: + encoding: ASCII-8BIT + string: '{"object":"list","results":[{"object":"page","id":"f37f592a-fd4b-4b7a-8d02-1ab6284d87f2","created_time":"2024-02-26T21:39:00.000Z","last_edited_time":"2024-04-08T22:07:00.000Z","created_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"last_edited_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"cover":null,"icon":null,"parent":{"type":"database_id","database_id":"81873709-8213-4ed0-99f9-d14385aa81c9"},"archived":false,"in_trash":false,"properties":{"Desde?":{"id":"TU%7DA","type":"date","date":{"start":"2024-04-08T14:00:00.000-05:00","end":null,"time_zone":null}},"Hasta?":{"id":"XNm_","type":"date","date":{"start":"2024-04-08T18:00:00.000-05:00","end":null,"time_zone":null}},"Description":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Luis","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Luis","href":null}]}},"url":"https://www.notion.so/Luis-f37f592afd4b4b7a8d021ab6284d87f2","public_url":null},{"object":"page","id":"44ad84ec-caac-494c-9415-0afe88749f48","created_time":"2024-02-26T21:39:00.000Z","last_edited_time":"2024-04-08T22:07:00.000Z","created_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"last_edited_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"cover":null,"icon":null,"parent":{"type":"database_id","database_id":"81873709-8213-4ed0-99f9-d14385aa81c9"},"archived":false,"in_trash":false,"properties":{"Desde?":{"id":"TU%7DA","type":"date","date":{"start":"2024-04-08","end":null,"time_zone":null}},"Hasta?":{"id":"XNm_","type":"date","date":{"start":"2024-04-12","end":null,"time_zone":null}},"Description":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Lorenzo","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Lorenzo","href":null}]}},"url":"https://www.notion.so/Lorenzo-44ad84eccaac494c94150afe88749f48","public_url":null},{"object":"page","id":"4b8a9481-2c47-466d-bc98-2b65b74c648f","created_time":"2024-02-26T21:38:00.000Z","last_edited_time":"2024-04-08T22:07:00.000Z","created_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"last_edited_by":{"object":"user","id":"7b6a0839-d5ad-4636-9509-8411cc70688d"},"cover":null,"icon":null,"parent":{"type":"database_id","database_id":"81873709-8213-4ed0-99f9-d14385aa81c9"},"archived":false,"in_trash":false,"properties":{"Desde?":{"id":"TU%7DA","type":"date","date":{"start":"2024-04-08","end":null,"time_zone":null}},"Hasta?":{"id":"XNm_","type":"date","date":{"start":"2024-04-08","end":null,"time_zone":null}},"Description":{"id":"title","type":"title","title":[{"type":"text","text":{"content":"Felipe + Guzman","link":null},"annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"plain_text":"Felipe + Guzman","href":null}]}},"url":"https://www.notion.so/Felipe-Guzman-4b8a94812c47466dbc982b65b74c648f","public_url":null}],"next_cursor":null,"has_more":false,"type":"page_or_database","page_or_database":{},"request_id":"2c6398e6-2163-49ac-961f-3d394f12a49f"}' + recorded_at: Mon, 08 Apr 2024 22:07:56 GMT recorded_with: VCR 6.2.0 diff --git a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_invalid_api_key.yml b/spec/fixtures/vcr_cassettes/notion/ptos/read_with_invalid_api_key.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_invalid_api_key.yml rename to spec/fixtures/vcr_cassettes/notion/ptos/read_with_invalid_api_key.yml diff --git a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_invalid_database_id.yml b/spec/fixtures/vcr_cassettes/notion/ptos/read_with_invalid_database_id.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/ptos/fetch_with_invalid_database_id.yml rename to spec/fixtures/vcr_cassettes/notion/ptos/read_with_invalid_database_id.yml diff --git a/spec/fixtures/vcr_cassettes/notion/ptos/fetch_without_filter.yml b/spec/fixtures/vcr_cassettes/notion/ptos/read_without_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/ptos/fetch_without_filter.yml rename to spec/fixtures/vcr_cassettes/notion/ptos/read_without_filter.yml diff --git a/spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_empty_database.yml b/spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_empty_database.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_empty_database.yml rename to spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_empty_database.yml diff --git a/spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_invalid_api_key.yml b/spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_invalid_api_key.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_invalid_api_key.yml rename to spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_invalid_api_key.yml diff --git a/spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_invalid_database_id.yml b/spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_invalid_database_id.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_with_invalid_database_id.yml rename to spec/fixtures/vcr_cassettes/notion/wip_limit/read_with_invalid_database_id.yml diff --git a/spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_without_filter.yml b/spec/fixtures/vcr_cassettes/notion/wip_limit/read_without_filter.yml similarity index 100% rename from spec/fixtures/vcr_cassettes/notion/wip_limit/fetch_without_filter.yml rename to spec/fixtures/vcr_cassettes/notion/wip_limit/read_without_filter.yml diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fcbfd50..6cbe3b8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,6 +24,4 @@ config.expect_with :rspec do |c| c.syntax = :expect end - - # config.include Fetcher::Configuration, type: :feature end