seriouslysean / monster-hunter-now-events

A tool that auto-generates calendar events for Monster Hunter Now by scraping web news articles, processing them with AI, and creating a convenient calendar subscription.
https://seriouslysean.github.io/monster-hunter-now-events/
MIT License
8 stars 9 forks source link

[Feature]: Add unit testing where possible to prevent regression #17

Open seriouslysean opened 9 months ago

seriouslysean commented 9 months ago

JSON and event generation would both benefit from it, or at least some of the utility functions. This is a little tricky because it likely involves both having known articles that we've parsed in the past, and expected JSON output to validate the new return from.

For instance, imagine a test against the following:

Article HTML: https://github.com/seriouslysean/monster-hunter-now-events/blob/main/fixtures/20231001_news-oct-2023/index.html Expected JSON output: https://github.com/seriouslysean/monster-hunter-now-events/blob/main/fixtures/20231001_news-oct-2023/events.json

I don't think we can use them direct from the fixtures because they get regenerated when all articles are force pulled, so I think specific test cases would need to live in a tests/* directory.

The given test would then:

  1. Take the known HTML
  2. Reach out to the api
  3. Validate the JSON returned vs. what is expected
  4. Pass or fail

I know this will use API credits for the OpenAI API , but I don't know a better way of handling that short of a free API instead.

KathanrDave commented 8 months ago

can I give it a try ? @seriouslysean

seriouslysean commented 8 months ago

@KathanrDave yeah for sure! Mind explaining a little about what you had in mind?

I think for this first pass, you can start with something small to make sure it even works. I think it would be best to use vittest since it’s api compatible with jest and I like the jest api.

The other thing you could start with would be making a mock event and validating that the ICS file is properly generated from it using something like a snapshot which wouldn’t involve any sort of dynamic data or ai api access.

KathanrDave commented 8 months ago

yes @seriouslysean I was thinking to implement it without api access for the start. Get back to you with it.