Skip to content

[PB-5298]: Add unit tests for referral service and loadExternalScript utility#1891

Merged
terrerox merged 5 commits intofeature/cello-referralfrom
feature/cello-tests
Mar 24, 2026
Merged

[PB-5298]: Add unit tests for referral service and loadExternalScript utility#1891
terrerox merged 5 commits intofeature/cello-referralfrom
feature/cello-tests

Conversation

@terrerox
Copy link
Contributor

@terrerox terrerox commented Mar 20, 2026

Description

Related Issues

Related Pull Requests

Checklist

  • Changes have been tested locally.
  • Unit tests have been written or updated as necessary.
  • The code adheres to the repository's coding standards.
  • Relevant documentation has been added or updated.
  • No new warnings or errors have been introduced.
  • SonarCloud issues have been reviewed and addressed.
  • QA Passed

Testing Process

Additional Notes

@terrerox terrerox requested review from a team, CandelR, larryrider and xabg2 as code owners March 20, 2026 01:22
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 20, 2026

Deploying drive-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8db787b
Status: ✅  Deploy successful!
Preview URL: https://4a9c4d84.drive-web.pages.dev
Branch Preview URL: https://feature-cello-tests.drive-web.pages.dev

View logs

@terrerox terrerox changed the base branch from master to feature/cello-referral-banner March 20, 2026 02:05
@terrerox terrerox changed the title Feature/cello tests [PB-5298]: Add unit tests for referral service and loadExternalScript utility Mar 20, 2026
@terrerox terrerox removed the request for review from a team March 20, 2026 03:15
@terrerox terrerox self-assigned this Mar 20, 2026
};

describe('referralService', () => {
beforeEach(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if no reset the module as in loadExternalScript tests I think that bootPromise won't be reseted between tests. Can you confirm it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats right, i applied the same approach as loadExternalScript.test.ts to fix that

Comment on lines +3 to +8
vi.mock('./local-storage.service', () => ({
default: {
get: vi.fn(),
set: vi.fn(),
},
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

as localStorageService is a passthrough interface with no logic of its own regarding localStorage, I think that is not necessary to mock local-storage with vitest, it should work without mocking it.
https://vitest.dev/guide/environment

@terrerox terrerox requested a review from CandelR March 23, 2026 16:45
},
}));

vi.mock('utils/loadExternalScript', () => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

for me its more readable if the imports are the first thing in the file, and then the mocks, the constants, etc.

right now its all mixed and seems a little messy

wdyt?

@terrerox terrerox requested a review from larryrider March 23, 2026 16:57
Copy link
Collaborator

@CandelR CandelR left a comment

Choose a reason for hiding this comment

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

The tests are failing 🙃

@terrerox terrerox force-pushed the feature/cello-tests branch from 8e2d29d to 6555d52 Compare March 23, 2026 17:11
@sonarqubecloud
Copy link

@terrerox terrerox requested a review from CandelR March 23, 2026 17:18
…roper isolation

Use real localStorage (provided by jsdom) instead of mocking the passthrough localStorageService. Reset the referral.service module via vi.resetModules() in beforeEach to ensure bootPromise is fresh per test, matching the pattern used in loadExternalScript tests.
@terrerox terrerox force-pushed the feature/cello-tests branch from 6555d52 to 95eaa3e Compare March 24, 2026 18:53
@terrerox terrerox changed the base branch from feature/cello-referral-banner to feature/cello-referral March 24, 2026 18:53
@terrerox terrerox merged commit 952823a into feature/cello-referral Mar 24, 2026
1 of 3 checks passed
@terrerox terrerox deleted the feature/cello-tests branch March 24, 2026 19:01
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.

3 participants