Module: Notion::Testing
- Defined in:
- lib/notion/testing.rb
Defined Under Namespace
Classes: Adapter
Class Method Summary collapse
- .page(id: "page", properties: {}, **attributes) ⇒ Object
- .response(body, status: 200, headers: {}) ⇒ Object
- .stub_notion_page(id: "page", **attributes) ⇒ Object
Class Method Details
.page(id: "page", properties: {}, **attributes) ⇒ Object
10 11 12 |
# File 'lib/notion/testing.rb', line 10 def page(id: "page", properties: {}, **attributes) { "object" => "page", "id" => id, "properties" => properties }.merge(attributes.transform_keys(&:to_s)) end |
.response(body, status: 200, headers: {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/notion/testing.rb', line 14 def response(body, status: 200, headers: {}) Transport::Response.new( status: status, headers: headers, body: JSON.generate(body), request_id: headers["x-request-id"], elapsed: 0 ) end |
.stub_notion_page(id: "page", **attributes) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/notion/testing.rb', line 20 def stub_notion_page(id: "page", **attributes) raise LoadError, "webmock is required for stub_notion_page" unless defined?(WebMock) WebMock.stub_request(:get, %r{/v1/pages/#{Regexp.escape(id)}\z}) .to_return(status: 200, body: JSON.generate(page(id: id, **attributes))) end |