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

fix: small error in isOutOfStock logic #33

Merged
merged 3 commits into from Sep 18, 2020
Merged

fix: small error in isOutOfStock logic #33

merged 3 commits into from Sep 18, 2020

Conversation

vp-regular
Copy link
Contributor

Description

While looking into adding some of the other bestbuy AIBs, I noticed that the loop in isOutOfStock will always return the check that coincides with the last value of Store::oosLabels. This does not align with the logic in the documentation:

Checks if DOM has any out-of-stock related text.

This PR addresses this issue.

There are many different ways to do this, if you have a cleaner idea in mind, feel free to suggest one. I come from a mostly Java background so I'm unsure if node has a cleaner way to do this.

@jef
Copy link
Owner

jef commented Sep 18, 2020

I too am not a TS dev by trade! Welcome 😃 !

You're absolutely right. I want to cover my ass and say I didn't write this, but I did merge it and reviewed it 😭

Looks good to me. Just pass the lint and we'll be good to go!

npm run lint:fix does wonders here. npm is our gradle 😄 (Hopefully you're using gradle and not maven 😝 )

@vp-regular
Copy link
Contributor Author

Don't worry about it, it wouldn't be software development without random bugs to fix.

I'm assuming I can add the other best buy cards in a separate PR?

Copy link
Contributor

@DakkJaniels DakkJaniels left a comment

Choose a reason for hiding this comment

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

nevermind - I see what you meant now. This is good!

src/index.ts Outdated Show resolved Hide resolved
@jef
Copy link
Owner

jef commented Sep 18, 2020

The original logic is correct.

Let's pretend our dom text is this: blah blah out of stock blah blah

And oosLabels = ['out of stock', 'not available']

// at first result is false
const result = false

// first loop is 'out of stock'
result = `blah blah out of stock blah blah`.includes('out of stock');

// sets result to true

// now second loop comes around and does a check against 'not available'
result = `blah blah out of stock blah blah`.includes('not available');

// result now gets set to false and we return false.

@DakkJaniels
Copy link
Contributor

Yup, I thought it was merging in the results. Probably could still do that (not sure what the return of .includes is), but just breaking the function once you find our first in-stock hit makes more sense anyway!

@vp-regular vp-regular requested a review from jef September 18, 2020 20:39
@jef jef changed the title bugfix:Fix small error in index.ts::isOutOfStock logic fix: small error in isOutOfStock logic Sep 18, 2020
@jef jef merged commit c2a210c into jef:main Sep 18, 2020
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.

None yet

3 participants