spec/constantcontact/api_spec.rb in constantcontact-1.1.2 vs spec/constantcontact/api_spec.rb in constantcontact-1.2.0

- old
+ new

@@ -309,23 +309,10 @@ added.should respond_to(:id) added.id.should_not be_empty end end - describe "#delete_event" do - it "deletes an event" do - json = load_file('event.json') - - net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content') - response = RestClient::Response.create('', net_http_resp, {}) - RestClient.stub(:delete).and_return(response) - - event = ConstantContact::Components::Event.create(JSON.parse(json)) - @api.delete_event('token', event).should be_true - end - end - describe "#publish_event" do it "updates an event with status of ACTIVE" do json = load_file('event.json') hash = JSON.parse json hash["status"] = "ACTIVE" @@ -372,11 +359,11 @@ fees = @api.get_event_fees('token', event) #fees.should be_kind_of(ConstantContact::Components::ResultSet) #fees.results.collect{|f| f.should be_kind_of(ConstantContact::Components::Fee) } fees.should be_kind_of(Array) # inconsistent with oether APIs. - fees.collect{|f| f.should be_kind_of(ConstantContact::Components::Fee) } + fees.collect{|f| f.should be_kind_of(ConstantContact::Components::EventFee) } end end describe "#get_fee" do it "return an event fee" do @@ -386,13 +373,13 @@ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') response = RestClient::Response.create(fee_json, net_http_resp, {}) RestClient.stub(:get).and_return(response) event = ConstantContact::Components::Event.create(JSON.parse(event_json)) - fee = ConstantContact::Components::Fee.create(JSON.parse(fee_json)) + fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json)) retrieved = @api.get_event_fee('token', event, fee) - retrieved.should be_kind_of(ConstantContact::Components::Fee) + retrieved.should be_kind_of(ConstantContact::Components::EventFee) end end describe "#add_fee" do it "adds an event fee" do @@ -402,13 +389,13 @@ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created') response = RestClient::Response.create(fee_json, net_http_resp, {}) RestClient.stub(:post).and_return(response) event = ConstantContact::Components::Event.create(JSON.parse(event_json)) - fee = ConstantContact::Components::Fee.create(JSON.parse(fee_json)) + fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json)) added = @api.add_event_fee('token', event, fee) - added.should be_kind_of(ConstantContact::Components::Fee) + added.should be_kind_of(ConstantContact::Components::EventFee) added.id.should_not be_empty end end describe "#update_fee" do @@ -421,13 +408,13 @@ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created') response = RestClient::Response.create(hash.to_json, net_http_resp, {}) RestClient.stub(:put).and_return(response) event = ConstantContact::Components::Event.create(JSON.parse(event_json)) - fee = ConstantContact::Components::Fee.create(JSON.parse(fee_json)) + fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json)) updated = @api.update_event_fee('token', event, fee) - updated.should be_kind_of(ConstantContact::Components::Fee) + updated.should be_kind_of(ConstantContact::Components::EventFee) updated.fee.should_not eq(fee.fee) updated.fee.should eq(fee.fee + 1) end end @@ -439,11 +426,11 @@ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content') response = RestClient::Response.create('', net_http_resp, {}) RestClient.stub(:delete).and_return(response) event = ConstantContact::Components::Event.create(JSON.parse(event_json)) - fee = ConstantContact::Components::Fee.create(JSON.parse(fee_json)) + fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json)) @api.delete_event_fee('token', event, fee).should be_true end end describe "#get_registrants" do @@ -474,9 +461,222 @@ event = ConstantContact::Components::Event.create(JSON.parse(event_json)) registrant = ConstantContact::Components::Registrant.create(JSON.parse(registrant_json)) retrieved = @api.get_event_registrant('token', event, registrant) retrieved.should be_kind_of(ConstantContact::Components::Registrant) retrieved.id.should_not be_empty + end + end + + describe "#get_event_items" do + it "returns an array of event items" do + json_response = load_file('event_items_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json_response, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + results = @api.get_event_items('token', 1) + results.should be_kind_of(Array) + results.first.should be_kind_of(ConstantContact::Components::EventItem) + results.first.name.should eq('Running Belt') + end + end + + describe "#get_event_item" do + it "returns an event item" do + json = load_file('event_item_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + result = @api.get_event_item('token', 1, 1) + result.should be_kind_of(ConstantContact::Components::EventItem) + result.name.should eq('Running Belt') + end + end + + describe "#add_event_item" do + it "adds an event item" do + json = load_file('event_item_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:post).and_return(response) + event_item = ConstantContact::Components::EventItem.create(JSON.parse(json)) + + result = @api.add_event_item('token', 1, event_item) + result.should be_kind_of(ConstantContact::Components::EventItem) + result.name.should eq('Running Belt') + end + end + + describe "#delete_event_item" do + it "deletes an event item" do + net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content') + + response = RestClient::Response.create('', net_http_resp, {}) + RestClient.stub(:delete).and_return(response) + + result = @api.delete_event_item('token', 1, 1) + result.should be_true + end + end + + describe "#update_event_item" do + it "updates an event item" do + json = load_file('event_item_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:put).and_return(response) + event_item = ConstantContact::Components::EventItem.create(JSON.parse(json)) + + result = @api.update_event_item('token', 1, event_item) + result.should be_kind_of(ConstantContact::Components::EventItem) + result.name.should eq('Running Belt') + end + end + + describe "#get_event_item_attributes" do + it "returns an array of event item attributes" do + json_response = load_file('event_item_attributes_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json_response, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + results = @api.get_event_item_attributes('token', 1, 1) + results.should be_kind_of(Array) + results.first.should be_kind_of(ConstantContact::Components::EventItemAttribute) + results.first.name.should eq('Royal Blue') + end + end + + describe "#get_event_item_attribute" do + it "returns an event item attribute" do + json = load_file('event_item_attribute_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + result = @api.get_event_item_attribute('token', 1, 1, 1) + result.should be_kind_of(ConstantContact::Components::EventItemAttribute) + result.name.should eq('Hi-Vis Green') + end + end + + describe "#add_event_item_attribute" do + it "adds an event item attribute" do + json = load_file('event_item_attribute_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:post).and_return(response) + event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json)) + + result = @api.add_event_item_attribute('token', 1, 1, event_item_attribute) + result.should be_kind_of(ConstantContact::Components::EventItemAttribute) + result.name.should eq('Hi-Vis Green') + end + end + + describe "#delete_event_item_attribute" do + it "deletes an event item attribute" do + net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content') + + response = RestClient::Response.create('', net_http_resp, {}) + RestClient.stub(:delete).and_return(response) + + result = @api.delete_event_item_attribute('token', 1, 1, 1) + result.should be_true + end + end + + describe "#update_event_item_attribute" do + it "updates an event item attribute" do + json = load_file('event_item_attribute_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:put).and_return(response) + event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json)) + + result = @api.update_event_item_attribute('token', 1, 1, event_item_attribute) + result.should be_kind_of(ConstantContact::Components::EventItemAttribute) + result.name.should eq('Hi-Vis Green') + end + end + + describe "#get_promocodes" do + it "returns an array of promocodes" do + json_response = load_file('promocodes_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json_response, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + results = @api.get_promocodes('token', 1) + results.should be_kind_of(Array) + results.first.should be_kind_of(ConstantContact::Components::Promocode) + results.first.code_name.should eq('REDUCED_FEE') + end + end + + describe "#get_promocode" do + it "returns a promocode" do + json = load_file('promocode_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:get).and_return(response) + + result = @api.get_promocode('token', 1, 1) + result.should be_kind_of(ConstantContact::Components::Promocode) + result.code_name.should eq('TOTAL_FEE') + end + end + + describe "#add_promocode" do + it "adds a promocode" do + json = load_file('promocode_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:post).and_return(response) + promocode = ConstantContact::Components::Promocode.create(JSON.parse(json)) + + result = @api.add_promocode('token', 1, promocode) + result.should be_kind_of(ConstantContact::Components::Promocode) + result.code_name.should eq('TOTAL_FEE') + end + end + + describe "#delete_promocode" do + it "deletes a promocode" do + net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content') + + response = RestClient::Response.create('', net_http_resp, {}) + RestClient.stub(:delete).and_return(response) + + result = @api.delete_promocode('token', 1, 1) + result.should be_true + end + end + + describe "#update_promocode" do + it "updates an event item" do + json = load_file('promocode_response.json') + net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK') + + response = RestClient::Response.create(json, net_http_resp, {}) + RestClient.stub(:put).and_return(response) + promocode = ConstantContact::Components::Promocode.create(JSON.parse(json)) + + result = @api.update_promocode('token', 1, promocode) + result.should be_kind_of(ConstantContact::Components::Promocode) + result.code_name.should eq('TOTAL_FEE') end end describe "#get_email_campaigns" do it "gets a set of campaigns" do \ No newline at end of file