Skip to content
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

Tests/tests for new changes #8

Open
wants to merge 9 commits into
base: features/api-for-reviews-and-questions
Choose a base branch
from

Conversation

mausamp
Copy link

@mausamp mausamp commented Jun 17, 2024

No description provided.

@@ -44,7 +44,7 @@ def scope
end

def resource
scope.find_by(slug: params[:id]) || scope.find(params[:id])
scope.friendly.find(params[:id])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work when we pass slug instead of id?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it works for both slug and id


# PUT/PATCH /api/v2/vendor/vendors/:vendor_id/questions/:id
def update
question = @vendor.product_questions.find(params[:id])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please ensure user have proper access to update?

I am afraid, user might be able to update product question from another vendor
also please add test

we have to ensure this for destroy as well

Spree::ProductQuestion.joins(product: :vendor).where(spree_products: { vendor_id: id })
end

def reviews

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yo ta review ra product question ko lib install garena bhane fail huncha..

yo ta vendor lai extend garera respective extension ma lekhnu parne

let!(:vendor_user) { create(:vendor_user, vendor: vendor, user: user) }

before do
create(:vendor_user, vendor: create(:active_vendor, name: 'Test Vendor'), user: user)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name should be from factory,
unless we want to specifically test string override..

end

describe 'vendors#create' do
let(:vendor_params) { { vendor: { name: 'Vendor test' } } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have let inside describe block and not at top of file?

let(:new_user) { create(:user) }

it 'creates a new vendor user' do
post "/api/v2/vendor/vendors/#{vendor.id}/users", params: { vendor_user: { email: new_user.email } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only vendor admin should be able to add new vendor users

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@poudelprakash dai, should I add a new attribute admin in the vendor users to indicate admin or create a function to pick up the first create vendor user as admin.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating user as admin will make user admin of whole app and not just vendor..

It would be better to manage this role via vendor users

describe '#destroy' do
let(:new_vendor_user) { create(:vendor_user, vendor: vendor, user: create(:user)) }

it 'deletes the vendor user' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to validate authorizaion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants