Skip to content

Add unit tests for asset-service, interaction-tracker, media-viewer, and utils#92

Merged
olgahaha merged 2 commits intomainfrom
copilot/add-unit-tests-for-modules
Apr 16, 2026
Merged

Add unit tests for asset-service, interaction-tracker, media-viewer, and utils#92
olgahaha merged 2 commits intomainfrom
copilot/add-unit-tests-for-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Four source modules had zero test coverage despite containing critical functionality: API data mapping, analytics token management, media type detection, and platform detection.

New test files

asset-service_test.ts — 13 tests

  • fetchAsset: full field mapping (including the intentional thumnail_url API typo), explorerUrl construction, non-OK response, network error, non-JSON error body, null data
  • hasNftProduct: count threshold, HTTP errors, network failure
  • fetchAssetMetadata: hasC2pa flag, showcaseLink lowercasing, missing owner_name, error paths

interaction-tracker_test.ts — 7 tests

  • createEvent skips fetch when token === '', retries after 1s when token === null
  • getToken failure sets token to ''; sessionStorage cache bypasses fetch; fetched key is stored back to sessionStorage
  • trackInteraction truncates subid > 255 chars

media-viewer_test.ts — 11 tests

  • Empty src → "No source provided"; pending HEAD → loading state
  • image/*<img>, video/* / HLS → <video>, unknown MIME → "Unsupported file format"
  • error event dispatched for unsupported MIME, network failure, and empty src
  • isImageMimeType / isVideoMimeType helper correctness

utils_test.ts — 8 tests

  • isMobile() returns true for iPhone, Android, iPad, BlackBerry, Windows Phone UAs
  • isMobile() returns false for desktop Chrome, Firefox, macOS Safari UAs
  • Stubs Navigator.prototype.userAgent via Object.defineProperty with proper teardown

Approach

  • window.fetch stubbed via sinon in all network-dependent tests
  • decryptData on the InteractionTracker singleton stubbed to test token caching paths without real crypto keys
  • MediaViewer.determineFileType() called directly to test event dispatch without fixture timing complexity

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl ndor/bin/git (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl modules/@npmcli/run-script/lib/node-gyp-bin/node (dns block)
  • static-cdn.numbersprotocol.io
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl ndor/bin/git (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl modules/@npmcli/run-script/lib/node-gyp-bin/node (dns block)
  • via.placeholder.com
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl ndor/bin/git (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl modules/@npmcli/run-script/lib/node-gyp-bin/node (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][Medium] Add unit tests for untested modules: asset-service, interaction-tracker, media-viewer, utils</issue_title>
<issue_description>## Summary

Four source modules have zero test coverage. These modules contain critical functionality including API data mapping, analytics token management, media type detection, and platform detection.

Current Test Coverage

Module Test File Coverage
src/capture-eye.ts src/test/capture-eye_test.ts Partial (happy path only)
src/modal/modal.ts src/test/modal_test.ts Partial (happy path only)
src/asset/asset-service.ts None 0%
src/modal/interaction-tracker.ts None 0%
src/media-viewer/media-viewer.ts None 0%
src/utils.ts None 0%

Recommended Test Cases

asset-service.ts

  1. fetchAsset — correct mapping from API response to AssetModel (verify all fields including thumnail_url typo)
  2. fetchAsset — returns undefined on non-OK HTTP response
  3. fetchAsset — returns undefined on network error
  4. fetchAsset — handles non-JSON error response body gracefully
  5. hasNftProduct — returns product data when available
  6. hasNftProduct — returns undefined when no product found
  7. fetchAssetMetadata — correct mapping of owner_name, description, headline

interaction-tracker.ts

  1. Token fetched from sessionStorage cache on second call
  2. Token fetch failure sets token = '' (empty string, not null)
  3. createEvent does not fire when token === ''
  4. createEvent retries when token === null (pending fetch)
  5. Token decryption produces expected Bearer token format

media-viewer.ts

  1. Renders <img> when MIME type starts with image/
  2. Renders <video> when MIME type starts with video/
  3. Dispatches error event when MIME type is unsupported
  4. Renders loading state when src is empty or mimeType is null
  5. HEAD request failure path behavior

utils.ts

  1. isMobile() returns true for mobile user agents
  2. isMobile() returns false for desktop user agents
  3. isMobile() handles edge cases (empty string, undefined navigator)

Suggested Approach

  • Use sinon (already a devDependency) for stubbing fetch() calls
  • Use @open-wc/testing fixtures for component tests
  • Consider adding a test coverage threshold to CI to prevent regression</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] [Feature] Add unit tests for untested modules Add unit tests for asset-service, interaction-tracker, media-viewer, and utils Mar 17, 2026
Copilot AI requested a review from numbers-official March 17, 2026 13:22
@olgahaha olgahaha marked this pull request as ready for review April 16, 2026 06:05
Copilot AI and others added 2 commits April 16, 2026 06:18
…and utils

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
The tests were written against the old Bubble.io API (verify.numbersprotocol.io)
which has since been replaced. Updated to match the current Numbers API v3:

- Remove fetchAssetMetadata tests (function no longer exists; hasC2pa and
  showcaseLink are now part of fetchAsset response)
- Replace { response: { data: ... } } mock structure with flat JSON
  matching the v3 API response
- Update field mappings: nit_commit_custom, signed_metadata,
  integrity_info, asset_file_mime_type, asset_file_thumbnail, etc.
- Add tests for creator fallback chain, hasC2pa, and showcaseLink
- Add test for null response body
@numbers-official numbers-official force-pushed the copilot/add-unit-tests-for-modules branch from 0d39a9e to d13a87c Compare April 16, 2026 06:24
@olgahaha olgahaha merged commit e350410 into main Apr 16, 2026
7 checks passed
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.

[Feature][Medium] Add unit tests for untested modules: asset-service, interaction-tracker, media-viewer, utils

3 participants