olioapps / typescript-starter-lab

0 stars 1 forks source link

Test readUserDataFile Function #122

Open emmalgs opened 1 year ago

emmalgs commented 1 year ago

Ticket: Test readUserDataFile Function

Description:

The readUserDataFile function needs to be thoroughly tested to ensure it correctly reads and parses user data files from the ./data directory based on the provided userId. This testing should cover various scenarios to verify its functionality.

Context:

The readUserDataFile function is a critical part of our application responsible for reading and parsing individual user data files. It relies on the file system to read files from the ./data directory.

Acceptance Criteria:

  1. Positive Test - Valid User File:

    • Create a temporary testing directory.
    • Populate the ./data directory with a temporary user data file with a known userId.
    • Call readUserDataFile with the known userId.
    • Ensure that the function resolves the Promise with the expected user object based on the test file.
    • Clean up the temporary files and directories after the test.
  2. Error Test - File Not Found:

    • Call readUserDataFile with a userId that does not correspond to an existing file in the ./data directory.
    • Ensure that the function rejects the Promise with an appropriate error message.
    • Clean up any temporary resources created during the test.
  3. Error Test - Parsing Error:

    • Create a temporary testing directory.
    • Populate the ./data directory with a user data file for which JSON parsing will fail intentionally (e.g., invalid JSON format).
    • Call readUserDataFile with the userId corresponding to the intentionally problematic file.
    • Verify that the function rejects the Promise with a parsing-related error.
    • Clean up the temporary files and directories after the test.

Definition of Done: