Merge pull request #4057 from luisramos0/remove_spree_api_2

Remove dependency to spree_api - step 2 - routes and views
This commit is contained in:
Luis Ramos
2019-11-06 13:23:32 +00:00
committed by GitHub
25 changed files with 178 additions and 238 deletions

View File

@@ -1,8 +1,10 @@
require 'spec_helper'
describe Spree::Api::BaseController do
describe Api::BaseController do
render_views
controller(Spree::Api::BaseController) do
controller(Api::BaseController) do
skip_authorization_check only: :index
def index
render text: { "products" => [] }.to_json
end
@@ -23,13 +25,15 @@ describe Spree::Api::BaseController do
end
end
context "cannot make a request to the API" do
context "can make an anonymous request to the API" do
it "without an API key" do
api_get :index
expect(json_response).to eq( "error" => "You must specify an API key." )
expect(response.status).to eq(401)
expect(json_response["products"]).to eq []
expect(response.status).to eq(200)
end
end
context "cannot make a request to the API" do
it "with an invalid API key" do
request.env["X-Spree-Token"] = "fake_key"
get :index, {}
@@ -46,19 +50,15 @@ describe Spree::Api::BaseController do
it 'handles exceptions' do
expect(subject).to receive(:authenticate_user).and_return(true)
expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
get :index, token: "fake_key"
get :index
expect(json_response).to eq( "exception" => "no joy" )
end
it "maps symantec keys to nested_attributes keys" do
klass = double(nested_attributes_options: { line_items: {},
bill_address: {} })
attributes = { 'line_items' => { id: 1 },
'bill_address' => { id: 2 },
'name' => 'test order' }
mapped = subject.map_nested_attributes_keys(klass, attributes)
expect(mapped.key?('line_items_attributes')).to be_truthy
expect(mapped.key?('name')).to be_truthy
it 'handles record not found' do
expect(subject).to receive(:authenticate_user).and_return(true)
expect(subject).to receive(:index).and_raise(ActiveRecord::RecordNotFound.new)
get :index
expect(json_response).to eq( "error" => "The resource you were looking for could not be found." )
expect(response.status).to eq(404)
end
end

View File

@@ -49,12 +49,14 @@ describe UserRegistrationsController, type: :controller do
end
it "sets user.locale from cookie on create" do
original_i18n_locale = I18n.locale
original_locale_cookie = cookies[:locale]
cookies[:locale] = "pt"
xhr :post, :create, spree_user: user_params, use_route: :spree
expect(assigns[:user].locale).to eq("pt")
I18n.locale = original_i18n_locale
cookies[:locale] = original_locale_cookie
end
end

View File

@@ -24,7 +24,7 @@ feature "Managing users" do
click_link "users_email_title"
end
it "should be able to list users with order email asc" do
it "should list users with order email asc" do
expect(page).to have_css('table#listing_users')
within("table#listing_users") do
expect(page).to have_content("a@example.com")
@@ -32,7 +32,7 @@ feature "Managing users" do
end
end
it "should be able to list users with order email desc" do
it "should list users with order email desc" do
click_link "users_email_title"
within("table#listing_users") do
expect(page).to have_content("a@example.com")
@@ -57,7 +57,7 @@ feature "Managing users" do
click_link("a@example.com")
end
it "should let me edit the user password" do
it "should allow editing the user password" do
fill_in "user_password", :with => "welcome"
fill_in "user_password_confirmation", :with => "welcome"
click_button "Update"
@@ -71,6 +71,23 @@ feature "Managing users" do
expect(page).to have_content("The account will be updated once the new email is confirmed.")
end
it "should allow to generate, regenarate and clear the user api key", js: true do
user = Spree::User.find_by_email("a@example.com")
expect(page).to have_content "NO KEY"
click_button "Generate API key"
first_user_api_key = user.reload.spree_api_key
expect(page).to have_content first_user_api_key
click_button "Regenerate Key"
second_user_api_key = user.reload.spree_api_key
expect(page).to have_content second_user_api_key
expect(second_user_api_key).not_to eq first_user_api_key
click_button "Clear key"
expect(page).to have_content "NO KEY"
end
end
end

View File

@@ -272,13 +272,9 @@ describe "AdminProductEditCtrl", ->
describe "loading data upon initialisation", ->
it "gets a list of producers and then resets products with a list of data", ->
$httpBackend.expectGET("/api/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
spyOn($scope, "fetchProducts").and.returnValue "nothing"
$scope.initialise()
$httpBackend.flush()
expect($scope.fetchProducts.calls.count()).toBe 1
expect($scope.spree_api_key_ok).toEqual true
describe "fetching products", ->
$q = null

View File

@@ -79,7 +79,7 @@ describe ProductTagRulesFilterer do
variant_hidden_for_another_customer.update_attribute(:tag_list, non_applicable_rule.preferred_variant_tags)
overrides_to_hide = filterer.__send__(:overrides_to_hide)
expect(overrides_to_hide).to eq [variant_hidden_by_default.id, variant_hidden_by_rule.id]
expect(overrides_to_hide).to include variant_hidden_by_default.id, variant_hidden_by_rule.id
end
end