openfoodfacts / openfoodfacts-hungergames

One click Mini-Games for Open Food Facts for: categories, labels, weight, brands, logos… We'd need to port and improve nutrition and ingredients from the old version.
9 stars 14 forks source link

Make dev environement safe for production data set #397

Closed alexfauquette closed 2 years ago

alexfauquette commented 2 years ago

Story

For now, there is no distinction between being in "production" or "development" environment. To test a feature you could be tempted to answer randomly Yes or No to questions just to test your feature. Please do NOT do that

As said before, there is no distinction between environments, so all the questions you answer will be sent to servers that will apply the modification. So if you answer "Yes" to the question "Is that a chicken" and it was a fish, the product will see a fish in the list of chicken products 🙀

So either you take care of answering correctly to the questions, or you do not answer, you only skip them

Preventing this problem

It is possible by checking NODE_ENV variable to know if the code runs in production or in development mode:

const IS_DEVELOPPEMENT_MODE = process.env.NODE_ENV === "development"

I propose that if we are in development mode axios.post and axios.put are replaced by a console.log such that it does not impact our servers' data

sumana2001 commented 2 years ago

Hey! I am interested to work on this issue. Could you please assign it to me?

The way I am thinking of solving this issue is to replace all the POST request sections with a code block like: if(IS_DEVELOPMENT_MODE){ console.log(...) } else { axios.post(...) }

Is this approach fine? Or should I do it some other way?

alexfauquette commented 2 years ago

That's ok, maybe the constant should be defined only once (in const.js for example) such that if someone wants to try post methods in dev mode she can do it by modifying only one line of code

sumana2001 commented 2 years ago

Oh yes, I'll add it to const.js. Thank you!