-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into TW-2386-gh-405-ruby-nylas-api-returns-invali…
…d-exception-message-message-in-case-of-errors
- Loading branch information
Showing
7 changed files
with
100 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,39 @@ | |
# This spec is the only one that should have any webmock stuff going on, everything else should use the | ||
# FakeAPI to see what requests were made and what they included. | ||
describe Nylas::API do | ||
describe "#detect_provider" do | ||
# tests the detect_providr method | ||
it "returns the provider" do | ||
url = "https://api.nylas.com/connect/detect-provider" | ||
client = Nylas::HttpClient.new(app_id: "not-real", app_secret: "also-not-real") | ||
data = { | ||
"client_id" => "not-real", | ||
"client_secret" => "also-not-real", | ||
"email_address" => "[email protected]" | ||
} | ||
response = { | ||
auth_name: "gmail", | ||
detected: true, | ||
email_address: "[email protected]", | ||
is_imap: false, | ||
provider_name: "gmail" | ||
} | ||
|
||
stub_request(:post, url) | ||
.to_return( | ||
status: 200, | ||
body: response.to_json, | ||
headers: { "content-type" => "application/json" } | ||
) | ||
api = described_class.new(client: client) | ||
res = api.detect_provider("[email protected]") | ||
|
||
expect(res).to eq(response) | ||
expect(WebMock).to have_requested(:post, url) | ||
.with(body: data) | ||
end | ||
end | ||
|
||
describe "#exchange_code_for_token" do | ||
it "retrieves oauth token with code" do | ||
client = Nylas::HttpClient.new(app_id: "fake-app", app_secret: "fake-secret") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe Nylas::SearchCollection do | ||
let(:api) { FakeAPI.new } | ||
|
||
describe "#count" do | ||
it "Returns an enumerable for a single page of results, filtered by `offset` and `limit` and `where`" do | ||
allow(api).to receive(:execute) | ||
.with( | ||
auth_method: Nylas::HttpClient::AuthMethod::BEARER, | ||
method: :get, | ||
path: "/collection/search", | ||
query: { limit: 100, offset: 0 }, | ||
headers: {} | ||
).and_return([{ id: "1234" }]) | ||
|
||
collection = described_class.new(model: FullModel, api: api) | ||
|
||
expect(collection.count).to be 1 | ||
end | ||
end | ||
end |