Skip to content

Commit

Permalink
Add authentication specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed Mar 26, 2024
1 parent 4c5b3f9 commit ea1649a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ build-iPhoneSimulator/
# .rubocop-https?--*

Gemfile.lock
.rspec_status
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
49 changes: 49 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RSpec.describe ServiceNow::Client do
let(:instance_id) { "instance_id_foo" }
let(:client_id) { "client_id_foo" }
let(:client_secret) { "client_secret_foo" }
let(:username) { "some_user" }
let(:password) { "p4ssw0rd" }
let(:refresh_token) { "refresh_token_foo" }

let(:connection) { double(Faraday) }
let(:response) { double(Faraday::Response, body: {"access_token" => "access_token_foo"}) }

describe ".authenticate" do
it "connects" do
expect(Faraday).to receive(:new).with({url: "https://#{instance_id}.service-now.com/"}).and_return(connection)
expect(connection).to receive(:post).with("oauth_token.do",
{
client_id: client_id,
client_secret: client_secret,
grant_type: "password",
username: username,
password: password
}
).and_return(response)

client = described_class.authenticate(instance_id, client_id, client_secret, username, password)

expect(client).to be_a(described_class)
end
end

describe ".authenticate_with_refresh_token" do
it "connects" do
expect(Faraday).to receive(:new).with({url: "https://#{instance_id}.service-now.com/"}).and_return(connection)
expect(connection).to receive(:post).with("oauth_token.do",
{
client_id: client_id,
client_secret: client_secret,
grant_type: "refresh_token",
refresh_token: refresh_token,
scope: "useraccount"
}
).and_return(response)

client = described_class.authenticate_with_refresh_token(instance_id, client_id, client_secret, refresh_token)

expect(client).to be_a(described_class)
end
end
end

0 comments on commit ea1649a

Please sign in to comment.