Skip to content

Add new testdata to Yahoo Finance mock

Dick Wolff edited this page Jun 1, 2024 · 5 revisions

When you add a new converter, of make a change to an existing one, you need to ensure the test coverage stays up to date. The tests in this repository make use of a mock for Yahoo Finance. This way the tests can be run consistently and the result will always be the same. There also isn’t a dependency on the live Yahoo Finance endpoint.

The mock makes use of two JSON files that contain the responses of Yahoo Finance. Whenever you need to update a test, you need to add new securities to the JSON files. Use the guide below to add new data to the mock. Before you start, please remove any local cache you may have!! This impacts which data will be added to the testdata files (or rather, won’t). You can find the cache at /var/tmp/e2g-cache.

  1. Open the src\converter.ts file and change the line where the SecurityService is created from const securityService = new SecurityService(); to const securityService = new SecurityService(new YahooFinanceService(new YahooFinanceTestdataWriter()));. Don’t forget to update the imports.
  2. Change the import file in your .env-file.
  3. Run the converter in which you have made a change. After the converter has completed, you should have two JSON files with changes (in Git).
  4. This is important: Run all tests locally before committing the JSON files!! This way you can check if you haven’t broken any existing test.
  5. When a test fails, look what is going wrong. If the failing test is of a converter you changed, fix the test. If the test of another converter fails, you’ve probably broken the mock. Please try again and first remove any local cache!.
  6. When all tests succeed, commit the two JSON files that were changed.
  7. Do not commit the converter.ts changes, but undo these so the converter is restored to it’s original state.
Clone this wiki locally