Skip to content

Feature/test coverage #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Performance/Count:
Style/RaiseArgs:
Enabled: false

Style/OpMethod:
Naming/BinaryOperatorParameterName:
Enabled: false

# We can use good judgement here
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ gem 'solidus', github: 'solidusio/solidus', branch: 'v2.4'
gem 'solidus_auth_devise', '~> 1.0'

group :test, :development do
gem 'rspec-rails', '~> 3.0.0'
gem 'rspec-rails'
gem 'pry'
end

gemspec
2 changes: 0 additions & 2 deletions app/models/odoo/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ def self.find(address)
end
end
end


1 change: 0 additions & 1 deletion app/models/odoo/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ def order_lines
end
end
end

2 changes: 1 addition & 1 deletion app/models/odoo/order_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def product
end

private

def item_information
{
name: product.name,
Expand All @@ -28,6 +29,5 @@ def item_information
product_uom_qty: line_item.quantity
}
end

end
end
5 changes: 1 addition & 4 deletions app/models/odoo/partner.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Odoo
class Partner

attr_accessor :order, :odoo_partner, :invoice_partner, :delivery_partner

def self.find_or_create(order)
Expand Down Expand Up @@ -29,6 +28,7 @@ def create_children
end

private

def partner_attributes(address)
{
name: order.name,
Expand All @@ -49,8 +49,5 @@ def state(address)
def country(address)
Country.find(address)
end

end
end


1 change: 0 additions & 1 deletion app/models/odoo/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ def self.find(address)
end
end
end

1 change: 0 additions & 1 deletion lib/odoo_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ def self.create_order(order)
Odoo::Order.create(order)
end
end

2 changes: 1 addition & 1 deletion lib/solidus_odoo/factories.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
# Example adding this to your spec_helper will load these Factories for use:
Expand Down
14 changes: 8 additions & 6 deletions solidus_odoo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", 'LICENSE', 'Rakefile', 'README.md']
solidus_version = ['>= 1.0', '< 3']

s.add_dependency 'solidus_core', solidus_version
s.add_dependency 'solidus_backend', solidus_version
s.add_dependency 'solidus_api', solidus_version
s.add_dependency 'ooor'
s.add_dependency 'solidus_backend', solidus_version
s.add_dependency 'solidus_core', solidus_version
s.add_dependency 'solidus_support'
s.add_dependency 'ooor'

s.add_development_dependency 'capybara'
s.add_development_dependency 'poltergeist'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'factory_bot_rails'
s.add_development_dependency 'poltergeist'
s.add_development_dependency 'pry'
s.add_development_dependency 'pry-rails'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'pry-rails'
s.add_development_dependency 'ffaker'
end
15 changes: 15 additions & 0 deletions spec/models/odoo/country_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe Odoo::Country do
let!(:order) { create(:order_with_line_items, state: 'complete') }

context 'when an order is completed in solidus and Sale Order line is created in Odoo' do
before(:each) do
@address = order.ship_address.country.name
@country = ResCountry.find(['name', '=', @address]).first.name
end
it 'should have a country' do
expect('United States').to eq(@country)
end
end
end
16 changes: 16 additions & 0 deletions spec/models/odoo/order_line_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Odoo::OrderLine do
let(:order) { create(:order_with_line_items, state: 'complete') }

context 'When a spree order is sent to odoo' do
it 'should throw "name" error if product does not exist in odoo' do
line_item = order.products.last
expect(ProductProduct.find(default_code: line_item.slug)).to be_blank
end

it 'should find product in odoo' do
expect(ProductProduct.find(default_code: 'product-3-935')).to be_truthy
end
end
end
23 changes: 23 additions & 0 deletions spec/models/odoo/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Odoo::Order do
let(:order) { create(:order_with_line_items, state: 'complete') }

context 'When a spree order is sent to odoo' do
before(:each) do
@product = order.products.last
@product.name = "Samsung Tv"
@product.save!
@product.slug = "samsung-tv"
@product.save!
@product.reload
order.reload
end

it 'should have total sale price in odoo as in solidus' do
OdooService.create_order(order)

expect(SaleOrder.last.amount_total).to eq(order.total - order.ship_total)
end
end
end
54 changes: 54 additions & 0 deletions spec/models/odoo/partner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

describe Odoo::Partner do
let!(:order) { create(:order_with_line_items, state: 'complete') }

context 'when user completes an order' do
it 'should not have an account in odoo' do
expect(nil).to be(ResPartner.find(email: order.email).first)
end

it 'should create an account in odoo' do
address = order.ship_address
ResPartner.create(name: order.name,
street: address.address1,
city: address.city,
state_id: address.state.id,
zip: address.zipcode,
country_id: address.country.id,
phone: address.phone,
email: order.email)

expect(ResPartner.find(email: order.email)).to be_truthy
end

it 'should have an account in odoo' do
order.email = '[email protected]'
expect(ResPartner.find(email: order.email)).to be_truthy
end

it 'should have an account with billing/shipping address' do
address = order.ship_address

def partner_attributes(address)
{
name: order.name,
street: address.address1,
city: address.city,
state_id: address.id,
zip: address.zipcode,
country_id: address.id,
phone: address.phone,
email: order.email
}
end

@odoo_partner = ResPartner.create partner_attributes(address)
@invoice_partner = ResPartner.create partner_attributes(order.bill_address).merge(name: "billing", type: "invoice", parent_id: @odoo_partner.id)
@delivery_partner = ResPartner.create partner_attributes(order.ship_address).merge(name: "shipping", type: "delivery", parent_id: @odoo_partner.id)
@odoo_partner.save

expect(@odoo_partner.associations['child_ids']).not_to be_blank
end
end
end
14 changes: 14 additions & 0 deletions spec/models/odoo/state_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

describe Odoo::Country do
let!(:order) { create(:order_with_line_items, state: 'complete') }

context 'when an order is completed in solidus and Sale Order line is created in Odoo' do
it 'should have a state' do
address = order.ship_address.state.name
state = ResCountryState.find(['name', '=', address]).first.name

expect('Alabama').to eq(state)
end
end
end
15 changes: 15 additions & 0 deletions spec/models/spree/order_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe Spree::Order do
let!(:order) { create(:order_with_line_items, state: 'complete') }

context 'when user finishes filling in payment information' do
it 'and order should be generated' do
expect(Spree::Order.count).to be(1)
end

it 'should have status as completed' do
expect("complete").to eq(order.state)
end
end
end
44 changes: 0 additions & 44 deletions spec/rails_helper.rb

This file was deleted.