spec/client_spec.rb in pmp-0.1.3 vs spec/client_spec.rb in pmp-0.2.0

- old
+ new

@@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe PMP::Client do before(:each) { - @pmp = PMP::Client.new + @pmp = PMP::Client.new(oauth_token: 'thisisatestvalueonly') } it "make with options and pass along" do pmp = PMP::Client.new(oauth_token: 'thisisatestvalueonly') pmp.oauth_token.must_equal 'thisisatestvalueonly' @@ -28,8 +28,46 @@ with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}). to_return(:status => 200, :body => root_doc, :headers => {}) @root = @pmp.root @root.creator.must_be_instance_of PMP::Link + end + + it "gets a credentials object" do + @pmp.credentials.wont_be_nil + end + + it "gets a token object" do + + access_token = "thisisnotanaccesstokenno" + response_body = { + access_token: access_token, + token_type: "Bearer", + token_issue_date: DateTime.now, + token_expires_in: 24*60*60 + }.to_json + + stub_request(:post, "https://api.pmp.io/auth/access_token"). + with(:body => {"grant_type"=>"client_credentials"}, + :headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dGhpc2lzbm90YS1yZWFsLWNsaWVudC1pZC1zb3Zlcnlzb3JyeTp0aGlzaXNub3RhcmVhbHNlY3JldGVpdGhlcg==', 'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'api.pmp.io:443'}). + to_return(:status => 200, :body => response_body, :headers => {'Content-Type' => 'application/json; charset=utf-8'}) + + + + client_id = "thisisnota-real-client-id-soverysorry" + client_secret = "thisisnotarealsecreteither" + + pmp = PMP::Client.new(client_id: client_id, client_secret: client_secret) + + pmp.token.wont_be_nil + end + + it "creates profile uri for type" do + @pmp.profile_href_for_type('foo').must_equal("https://api.pmp.io/profiles/foo") + end + + it "makes a doc of a profile type" do + user = @pmp.doc_of_type('user') + user.links['profile'].href.must_equal "https://api.pmp.io/profiles/user" end end