Skip to content

test: Add unit tests for skipSurvey() function (#444)#451

Open
Hitanshi7556 wants to merge 2 commits intoOneBusAway:developfrom
Hitanshi7556:test/survey-skip-tests
Open

test: Add unit tests for skipSurvey() function (#444)#451
Hitanshi7556 wants to merge 2 commits intoOneBusAway:developfrom
Hitanshi7556:test/survey-skip-tests

Conversation

@Hitanshi7556
Copy link
Copy Markdown

Overview

Adds unit tests for the skipSurvey() function to improve coverage for the fix introduced in #420.

Covered

  • Recurring surveys: ensures _skipped_timestamp is set when allows_multiple_responses: true
  • One-time surveys: ensures _skipped flag is set correctly
  • Legacy cleanup: verifies removal of stale _skipped flag when _skipped_timestamp is used

Testing

  • All tests passing (24 total: 3 new, 21 existing)
  • Run using: npm run test -- --run
  • No lint or build issues

Closes #444

- Test recurring survey skip: verify _skipped_timestamp set, _skipped NOT present
- Test one-time survey skip: verify _skipped set, _skipped_timestamp NOT present
- Test stale flag cleanup: verify old _skipped flag removed for recurring surveys
- All 24 tests passing
Copilot AI review requested due to automatic review settings March 26, 2026 12:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Vitest unit coverage for skipSurvey() behavior in src/lib/Surveys/surveyUtils.js, targeting the recurring-vs-one-time skip logic introduced in #420.

Changes:

  • Mock $stores/surveyStore to isolate surveyUtils in unit tests.
  • Add new skipSurvey test cases for recurring surveys, one-time surveys, and stale flag cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tests/lib/surveysUtils.test.js Outdated
Comment on lines +344 to +346
expect(localStorage.getItem('survey_123_skipped_timestamp')).toBeDefined();
expect(localStorage.getItem('survey_123_skipped')).toBeNull();
});
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localStorage.getItem() returns either a value or null (never undefined). Using toBeDefined() will pass even when the key is missing (because null is still “defined”), so these assertions won’t actually verify that the timestamp was written. Use an assertion like not.toBeNull() (and ideally assert it’s a numeric timestamp) instead.

Copilot uses AI. Check for mistakes.
Comment thread src/tests/lib/surveysUtils.test.js Outdated
Comment on lines +357 to +359
expect(localStorage.getItem('survey_456_skipped')).toBeDefined();
expect(localStorage.getItem('survey_456_skipped_timestamp')).toBeNull();
});
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toBeDefined() is not a reliable check for localStorage.getItem() (it will pass on null). This test should assert the permanent skip key is present with not.toBeNull() (and optionally that it equals 'true'/true depending on conventions) to ensure it really gets set.

Copilot uses AI. Check for mistakes.
Comment on lines +373 to +375
expect(localStorage.getItem('survey_789_skipped')).toBeNull();
expect(localStorage.getItem('survey_789_skipped_timestamp')).toBeDefined();
});
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: localStorage.getItem() returns null for missing keys, so toBeDefined() won’t fail if the timestamp was never set. Prefer not.toBeNull() (and ideally validate it’s a timestamp) so the test actually guards the recurring-survey behavior.

Copilot uses AI. Check for mistakes.
@Hitanshi7556
Copy link
Copy Markdown
Author

Resolved all comments PTAL @aaronbrethorst
Thank you

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Add unit tests for skipSurvey() function

2 participants