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

test(utils): Add comprehensive unit tests for format-utils module #86

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

mitsuki31
Copy link
Owner

Overview

This pull request introduces comprehensive unit tests for the format-utils module. The goal is to ensure that all utility functions and methods are thoroughly tested, covering a wide range of scenarios and edge cases to improve the module's reliability and maintainability.

Changes Made

Tests for DateFormatter Methods

  • constructor:
    • Valid and invalid inputs.
  • fromMicroseconds:
    • Valid and invalid inputs.
  • Conversion Methods:
    • toMicroseconds, micros, toMilliseconds, and millis.
  • Formatting Methods:
    • toISOString, toISO, toDateObject, toString, and toLocaleString with various locales.

Tests for FormatUtils Methods

  • Utility Methods:
    • parseFormatObject (valid and invalid inputs).
    • sortThumbnailsByResolution (valid and invalid inputs).
  • Thumbnail Handling:
    • getAuthorThumbnails (various scenarios).
    • getVideoThumbnails (various scenarios).
    • getAllThumbnails (various scenarios).
    • getThumbnailByResolution (various scenarios).
    • getThumbnail (various scenarios).
  • Media Presence Check
    • hasVideo and hasAudio with formats containing or lacking video/audio.

Test Assets

  • Several assets added for testing purposes:
    • test/assets/json/formats.json: Simulates video format data.
    • test/assets/json/videoThumbnails.json: Provides video thumbnail examples.
    • test/assets/json/authorThumbnails.json: Provides author thumbnail examples.

Impact

  • Ensures proper validation of inputs for all utility methods.
  • Enhances test coverage, making the module more robust against regressions.
  • Validates edge cases and various scenarios, such as missing or malformed inputs.
  • Provides a solid foundation for future updates or refactoring of the format-utils module.

Summary

These tests significantly improve the quality and maintainability of the format-utils module by:

  • Validating critical utility methods.
  • Handling a variety of input cases and scenarios.
  • Supporting ongoing development with robust and reusable test assets.

This PR sets a higher standard for testing practices within the codebase.

- Added tests for `DateFormatter` methods:
  - `constructor` with valid and invalid inputs
  - `fromMicroseconds` with valid and invalid inputs
  - `toMicroseconds` and `micros` methods
  - `toMilliseconds` and `millis` methods
  - `toISOString` and `toISO` methods
  - `toDateObject` method
  - `toString` method
  - `toLocaleString` method with various locales
- Added tests for `FormatUtils` methods:
  - `parseFormatObject` with valid and invalid inputs
  - `sortThumbnailsByResolution` with valid and invalid inputs
  - `getAuthorThumbnails` with various scenarios
  - `getVideoThumbnails` with various scenarios
  - `getAllThumbnails` with various scenarios
  - `getThumbnailByResolution` with various scenarios
  - `getThumbnail` with various scenarios
  - `hasVideo` with formats containing and not containing video
  - `hasAudio` with formats containing and not containing audio
- Added several assets for these unit tests to test various scenarios:
  - `test/assets/json/formats.json`
  - `test/assets/json/videoThumbnails.json`
  - `test/assets/json/authorThumbnails.json`
@mitsuki31 mitsuki31 added chore Maintenance updates to improve project maintainability patch Patch changes labels Jan 10, 2025
@mitsuki31 mitsuki31 self-assigned this Jan 10, 2025
@mitsuki31 mitsuki31 changed the title test: Add comprehensive unit tests for format-utils module test(utils): Add comprehensive unit tests for format-utils module Jan 10, 2025
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.33%. Comparing base (b212902) to head (67a668d).
Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
+ Coverage   77.52%   80.33%   +2.80%     
==========================================
  Files           9       10       +1     
  Lines         525      600      +75     
==========================================
+ Hits          407      482      +75     
  Misses        118      118              
Flag Coverage Δ
Ubuntu 80.33% <ø> (+2.80%) ⬆️
Windows 80.00% <ø> (?)
all 80.33% <ø> (+2.80%) ⬆️
macOS 80.33% <ø> (+2.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mitsuki31 mitsuki31 added this to the YTMP3-JS v2.0.0 milestone Jan 10, 2025
@mitsuki31
Copy link
Owner Author

Covered #84 and #85.

@mitsuki31 mitsuki31 merged commit 30d4c11 into master Jan 10, 2025
26 checks passed
@mitsuki31 mitsuki31 deleted the chore/add-test-suite-for-format-utils-module branch January 10, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance updates to improve project maintainability patch Patch changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant