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

Spec requiring tax category when creating products #12038

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Jan 12, 2024

What? Why?

It doesn't really fix the error described in the issue but it shows that the error was caused by a misconfiguration of the instance.

Instead I discovered some unnecessary spec code and cleaned up a little.

What should we test?

  • Create a product.
  • Create a variant.
  • The above with and without requiring a tax category.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

We observed an error when an instance requires a tax category and we
tried to create products via the DFC API:

* openfoodfoundation#11212

But I found that the error only appears after changing the instance
config without declaring a tax category as default. The right setup as
in the spec does work. The spec passes.

I don't think that this needs any fix. We shouldn't assign any tax
category just because it's required. The instance manager needs to
select a default.
The logic doesn't change but I simplified it and added more detailed
specs.
Best viewed ignoring whitespaces.

Products don't require a tax category by default. And when you activate
it via Spree::Config then it's automatically reset at the end of the spec.
We don't need this helper to do it.
These shared examples were used in only one spec file. It's much easier
to read having all the related specs in one file instead of hiding some
in a helper module.

It's also one less file to load whenever we run specs.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Jan 12, 2024
@mkllnk mkllnk self-assigned this Jan 12, 2024
@mkllnk mkllnk marked this pull request as ready for review January 12, 2024 06:27
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Looks good !

Comment on lines +38 to +42
expect {
variant.tax_category = nil
}.to_not change {
variant.tax_category
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not following what we are testing here ? Are we just checking that a tax category can't be set to null if a default one exists ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we just checking that a tax category can't be set to null if a default one exists ?

Yes, exactly. Well, I don't actually know what would be saved to the database and it doesn't really matter but the getter method always returns the default in this case.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great, thanks for cleaning up! 🧹

@drummer83 drummer83 self-assigned this Jan 18, 2024
@drummer83 drummer83 added pr-staged-au staging.openfoodnetwork.org.au pr-staged-uk staging.openfoodnetwork.org.uk pr-staged-fr staging.coopcircuits.fr and removed pr-staged-au staging.openfoodnetwork.org.au pr-staged-uk staging.openfoodnetwork.org.uk labels Jan 18, 2024
@drummer83
Copy link
Contributor

Hmm, sorry, I think I am missing something here @mkllnk. On all three staging servers I get an error 404:

404 Undocumented | Error: response status is 404Response headers cache-control: no-cache  content-encoding: br  content-security-policy: default-src 'self' https:; font-src 'self' https: data: fonts.gstatic.com; img-src 'self' https: data: *.s3.amazonaws.com; object-src 'none'; frame-ancestors 'none'; script-src 'self' https: 'unsafe-inline' 'unsafe-eval' *.stripe.com openfoodnetwork.innocraft.cloud maps.googleapis.com maps.gstatic.com d2wy8f7a9ursnm.cloudfront.net; style-src 'self' https: 'unsafe-inline' fonts.googleapis.com cdnjs.cloudflare.com; connect-src 'self' https: https://staging.coopcircuits.fr wss://staging.coopcircuits.fr  content-type: application/json  date: Thu,18 Jan 2024 13:22:13 GMT  referrer-policy: strict-origin-when-cross-origin  server: nginx  strict-transport-security: max-age=63072000; includeSubDomains  x-content-type-options: nosniff,nosniff  x-download-options: noopen  x-firefox-spdy: h2  x-permitted-cross-domain-policies: none  x-request-id: ecd5649a-b9f2-4f0a-b43e-1fd08a29ffd8  x-runtime: 0.204090  x-xss-protection: 1; mode=block,1; mode=block
-- | --

image

Could you please provide some hints?
What do I have to change in the given example to make a correct request?
Anything else I need to enable on the server or in the super admin area?

Thanks!

@drummer83 drummer83 removed the pr-staged-fr staging.coopcircuits.fr label Jan 18, 2024
@drummer83 drummer83 removed their assignment Jan 18, 2024
@mkllnk
Copy link
Member Author

mkllnk commented Jan 18, 2024

I'm not exactly sure what you did, but here are some hints:

  • One of your screenshots contains an API key. Probably best to replace that one.
  • The shown example contains a spree_product_id which is used to create a variant for an existing product. But the id looks like the example id. If it can't find that product then it would reply with 404. You can just take that out to create a new product.
  • If you enabled requiring a tax category on the staging server, you need to have a default tax category.

@mkllnk
Copy link
Member Author

mkllnk commented Jan 18, 2024

My test notes above were aiming at the normal admin UX though. I wanted to be sure that I didn't break anything. The API itself is well covered with specs. I'm happy for you to test it as well but I thought it may be too much effort.

@drummer83
Copy link
Contributor

  • The shown example contains a spree_product_id which is used to create a variant for an existing product. But the id looks like the example id. If it can't find that product then it would reply with 404.

Ah, thanks! That's probably it! I checked that the id wasn't already taken and thought that the new variant would get this id assigned. Thanks for clarification! I will try this within the next days - weekend is coming. 😉

@drummer83 drummer83 self-assigned this Jan 24, 2024
@drummer83 drummer83 added no-staging-AU A tag which does not trigger deployments, indicating a server is being used pr-staged-au staging.openfoodnetwork.org.au and removed no-staging-AU A tag which does not trigger deployments, indicating a server is being used labels Jan 24, 2024
@drummer83
Copy link
Contributor

Hi @mkllnk,

I have tested this now.

After staging

Tax cat. required Default tax cat. available Result
No No ✔️
Yes No Error 500 ✔️
Yes Yes ✔️

Both have been tested for variants as well as for products.

According to your comment here it is ok to see the error when a tax category is required but no default tax category is set. 👍

Great! This one is ready to go! 🎉
Merging! 🚀

@drummer83 drummer83 merged commit ec4bbe6 into openfoodfoundation:master Jan 24, 2024
64 checks passed
@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Jan 24, 2024
@mkllnk mkllnk deleted the dfc-tax-category branch February 8, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[DFC] Can't create products for instances requiring tax categories on products
5 participants