spec/namely/authenticator_spec.rb in namely-0.0.1 vs spec/namely/authenticator_spec.rb in namely-0.1.0

- old
+ new

@@ -77,10 +77,28 @@ parsed_uri = URI(authorization_code_url) expect(parsed_uri.scheme).to eq "http" expect(parsed_uri.host).to eq "testing.example.com" end + + it "accepts a state parameter" do + authenticator = described_class.new( + client_id: "MY_CLIENT_ID", + client_secret: "MY_CLIENT_SECRET", + ) + + state = "this-is-a-piece-of-state" + + authorization_code_url = authenticator.authorization_code_url( + subdomain: "ellingsonmineral", + state: state, + ) + + parsed_uri = URI(authorization_code_url) + parsed_query = CGI.parse(parsed_uri.query) + expect(parsed_query["state"]).to eq [state] + end end describe "#retrieve_tokens" do it "exchanges an authorization code for access and refresh tokens" do erb_settings = { @@ -135,9 +153,27 @@ expect(tokens).to eq( "access_token" => "MY_ACCESS_TOKEN", "expires_in" => 899, "token_type" => "bearer", ) + end + end + end + + describe "#current_user" do + it "returns the profile of the current user" do + VCR.use_cassette("current_user") do + authenticator = described_class.new( + client_id: "MY_CLIENT_ID", + client_secret: "MY_CLIENT_SECRET", + ) + + profile = authenticator.current_user( + access_token: ENV.fetch("TEST_ACCESS_TOKEN"), + subdomain: ENV.fetch("TEST_SUBDOMAIN"), + ) + + expect(profile.id).to eq "459748d5-608c-4dce-bca9-49a066d7f3d0" end end end end