From 036cac556dbac403f1a9cf5407c659d9df791683 Mon Sep 17 00:00:00 2001 From: Tonatiuh Nunez Date: Wed, 30 Jul 2014 11:43:51 -0500 Subject: [PATCH 1/6] update user class since celery api now doesn't return response['data'] and instead it returns user data directly --- lib/celery/user.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/celery/user.rb b/lib/celery/user.rb index af11595..6352cb9 100644 --- a/lib/celery/user.rb +++ b/lib/celery/user.rb @@ -7,13 +7,14 @@ class User < Base :shipping_rates, :tax_rates, :nexus, :stripe, :affirm, :paypal_email, :analytics, :flags, :confirmation_url, :twitter, :facebook, :website, :subscription, :business, :has_affirm, :message_to_buyer, :access_token, - :emails, :has_paypalx, :confirmation_scripts + :emails, :has_paypalx, :confirmation_scripts, :salt, :secret, :hash, + :application_credit, :application_credit_used, :beta, :data def update(attrs={}) update_local_object(attrs) - response = perform_request(attrs) + response = perform_request({ user: attrs }) - return response['meta']['code'] == 200 ? true : false + return !response['user'].nil? end def perform_request(attrs) @@ -34,7 +35,7 @@ def me query_string += Celery.parameterize_options response = HTTParty.get(query_string) - self.new(response['data']) + self.new(response['user']) end end end From bc0f880e9703b99ab5688950d41238351fe565ac Mon Sep 17 00:00:00 2001 From: Tonatiuh Nunez Date: Wed, 30 Jul 2014 11:44:49 -0500 Subject: [PATCH 2/6] add some missing describes in the orders spec --- lib/celery.rb | 1 + spec/celery/order_spec.rb | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/celery.rb b/lib/celery.rb index 316cdd0..2f1d1d5 100644 --- a/lib/celery.rb +++ b/lib/celery.rb @@ -16,5 +16,6 @@ module Celery autoload :Billing, "celery/billing" autoload :Product, "celery/product" autoload :Tracking, "celery/tracking" + autoload :Coupon, 'celery/coupon' autoload :EndpointMethods, "celery/endpoint_methods" end diff --git a/spec/celery/order_spec.rb b/spec/celery/order_spec.rb index 9587cb3..9a35cc9 100644 --- a/spec/celery/order_spec.rb +++ b/spec/celery/order_spec.rb @@ -1,28 +1,34 @@ require 'spec_helper' describe Celery::Order, 'class methods' do - it 'returns all the orders from the endpoint' do - orders = Celery::Order.all - expect(orders).to be_kind_of Array - expect(orders.first).to be_kind_of Celery::Order + describe '.all' do + it 'returns all the orders from the endpoint' do + orders = Celery::Order.all + expect(orders).to be_kind_of Array + expect(orders.first).to be_kind_of Celery::Order + end end - it 'builds the orders based on the array' do - orders = [{ "id" => "1234" }] - orders = Celery::Order.build_collection(orders) - expect(orders.first).to be_kind_of Celery::Order - expect(orders.first.id).to eq("1234") + describe '.build_collection' do + it 'builds the orders based on the array' do + orders = [{ "id" => "1234" }] + orders = Celery::Order.build_collection(orders) + expect(orders.first).to be_kind_of Celery::Order + expect(orders.first.id).to eq("1234") + end end - it 'decodes the order' do - order = Celery::Order.decode(celery_encoded_order) - expect(order.id).to eq(celery_decoded_order.id) + describe '.decode' do + it 'decodes the order' do + order = Celery::Order.decode(celery_encoded_order) + expect(order.id).to eq(celery_decoded_order.id) + end end describe '.get' do let!(:attrs) do { - seller_id: "5388e71c5d519405004e3c3c", + seller_id: "53c69672237dd10700bb65af", buyer: { "email" => Faker::Internet.email, "name"=> Faker::Name.name, From 275abe4bf9f14508ee63b89d4f09f7db7fc6208b Mon Sep 17 00:00:00 2001 From: Tonatiuh Nunez Date: Wed, 30 Jul 2014 11:45:17 -0500 Subject: [PATCH 3/6] remove some specs of methods that are already being tested --- spec/celery_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/celery_spec.rb b/spec/celery_spec.rb index 6ca5932..06d1293 100644 --- a/spec/celery_spec.rb +++ b/spec/celery_spec.rb @@ -1,10 +1,7 @@ require 'spec_helper' describe Celery do - it { should be_kind_of Module } - it { should respond_to :access_token } - it { should respond_to :access_token= } - it { should respond_to :endpoint } + it { should be_kind_of Module } it 'returns the endpoint' do expect(Celery.endpoint).to eq("https://api.trycelery.com/v1/") From ca8b9a97da7252159be020ffe16450c8ca7f1036 Mon Sep 17 00:00:00 2001 From: Tonatiuh Nunez Date: Wed, 30 Jul 2014 11:47:20 -0500 Subject: [PATCH 4/6] add coupon spec for the .all method, update celery store token, update seller_id in orders spec to make reference to the seller in the new celery store --- lib/celery/coupon.rb | 12 ++++++++++++ spec/celery/coupon_spec.rb | 7 +++++++ spec/celery/order_spec.rb | 4 ++-- spec/spec_helper.rb | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/celery/coupon.rb create mode 100644 spec/celery/coupon_spec.rb diff --git a/lib/celery/coupon.rb b/lib/celery/coupon.rb new file mode 100644 index 0000000..8e62dde --- /dev/null +++ b/lib/celery/coupon.rb @@ -0,0 +1,12 @@ +class Celery::Coupon < Celery::Base + ENDPOINT_RESOURCE = 'coupons' + ENDPOINT_RESOURCE_SINGULAR = 'coupon' + + extend Celery::EndpointMethods::ClassMethods + include Celery::EndpointMethods::InstanceMethods + + attr_accessor :_id, :id, :user_id, :enabled, :code, + :type, :discount, :quantity, :slugs, + :emails, :tags, :product, :updated, + :updated_date, :created, :created_date +end diff --git a/spec/celery/coupon_spec.rb b/spec/celery/coupon_spec.rb new file mode 100644 index 0000000..e504ad7 --- /dev/null +++ b/spec/celery/coupon_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Celery::Coupon, '.all' do + it 'returns all the existent coupons' do + expect(Celery::Coupon.all.first).to be_kind_of(Celery::Coupon) + end +end diff --git a/spec/celery/order_spec.rb b/spec/celery/order_spec.rb index 9a35cc9..aec5864 100644 --- a/spec/celery/order_spec.rb +++ b/spec/celery/order_spec.rb @@ -43,7 +43,7 @@ "phone"=>"" }, }, - products: [ { "slug"=>"choco-cake", "name"=>"Chocholate cake", "quantity"=>1 } ] + products: [ { "slug"=>"computer", "name"=>"Glasses", "quantity"=>1 } ] } end @@ -90,7 +90,7 @@ describe Celery::Order, 'instance methods' do let!(:attrs) do { - seller_id: "5388e71c5d519405004e3c3c", + seller_id: "53c69672237dd10700bb65af", buyer: { "email" => Faker::Internet.email, "name"=> Faker::Name.name, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca2d5c2..3b6d645 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,7 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } -Celery.access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1Mzg4ZTcxYzVkNTE5NDA1MDA0ZTNjM2MifQ.Vw1dikATVaAK5YLZFTPOXKpJJexa8T6Ni1RuE3nh1nAU" +Celery.access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1M2M2OTY3MjIzN2RkMTA3MDBiYjY1YWYifQ.CbBFs_TdCfiVXmsEwVS5_mU47Un3j4NnVxHm_3Scp24' I18n.enforce_available_locales = true From a063cbfdece5483e4e076523fe85af8ee46ce4c2 Mon Sep 17 00:00:00 2001 From: Cesar Gomez Date: Wed, 10 Sep 2014 10:05:40 -0500 Subject: [PATCH 5/6] added new field 'version' to user (since now celery api includes it too) --- lib/celery/user.rb | 2 +- spec/celery/coupon_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/celery/user.rb b/lib/celery/user.rb index 6352cb9..2a8c150 100644 --- a/lib/celery/user.rb +++ b/lib/celery/user.rb @@ -8,7 +8,7 @@ class User < Base :analytics, :flags, :confirmation_url, :twitter, :facebook, :website, :subscription, :business, :has_affirm, :message_to_buyer, :access_token, :emails, :has_paypalx, :confirmation_scripts, :salt, :secret, :hash, - :application_credit, :application_credit_used, :beta, :data + :application_credit, :application_credit_used, :beta, :data, :version def update(attrs={}) update_local_object(attrs) diff --git a/spec/celery/coupon_spec.rb b/spec/celery/coupon_spec.rb index e504ad7..dd9471b 100644 --- a/spec/celery/coupon_spec.rb +++ b/spec/celery/coupon_spec.rb @@ -2,6 +2,6 @@ describe Celery::Coupon, '.all' do it 'returns all the existent coupons' do - expect(Celery::Coupon.all.first).to be_kind_of(Celery::Coupon) + expect(Celery::Coupon.all[0]).to be_kind_of(Celery::Coupon) end end From 391268b1ac346a6cb29aea92ca60e175f435b5bd Mon Sep 17 00:00:00 2001 From: Cesar Gomez Date: Wed, 10 Sep 2014 11:07:58 -0500 Subject: [PATCH 6/6] added missing tests for coupon endpoint to complete the CRUD --- lib/celery/coupon.rb | 4 ++++ spec/celery/coupon_spec.rb | 47 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/celery/coupon.rb b/lib/celery/coupon.rb index 8e62dde..39e4cbc 100644 --- a/lib/celery/coupon.rb +++ b/lib/celery/coupon.rb @@ -9,4 +9,8 @@ class Celery::Coupon < Celery::Base :type, :discount, :quantity, :slugs, :emails, :tags, :product, :updated, :updated_date, :created, :created_date + + def id + self._id + end end diff --git a/spec/celery/coupon_spec.rb b/spec/celery/coupon_spec.rb index dd9471b..0de055d 100644 --- a/spec/celery/coupon_spec.rb +++ b/spec/celery/coupon_spec.rb @@ -1,7 +1,50 @@ require 'spec_helper' describe Celery::Coupon, '.all' do - it 'returns all the existent coupons' do - expect(Celery::Coupon.all[0]).to be_kind_of(Celery::Coupon) + before :all do + @coupon = Celery::Coupon.all[0] + end + + describe '.all' do + it 'returns all the existent coupons' do + expect(Celery::Coupon.all[0]).to be_kind_of(Celery::Coupon) + end + end + + describe '.create' do + let(:attrs) do + { + type: 'percent', + code: Faker::Lorem.word, + discount: 10 + } + end + + it 'creates a new coupon' do + coupon = Celery::Coupon.create(attrs) + expect(coupon._id).to_not be_nil + end + end + + describe '.get' do + it 'finds a coupon by id' do + found_coupon = Celery::Coupon.get(@coupon._id) + expect(found_coupon.code).to eq(@coupon.code) + end + end + + describe '.update' do + let(:new_code) { Faker::Lorem.word } + before { @coupon.update(code: new_code) } + + it 'updates a coupon' do + expect(@coupon.code).to eq(new_code) + end + end + + describe '.delete' do + it 'deletes a coupon' do + expect(@coupon.destroy).to eq(true) + end end end