Skip to content

test: Remove set timeouts from tests and other cleanup#967

Closed
rmi22186 wants to merge 2 commits intofeat/SQDSDKS-6991-cookie-sync-gdpr-2from
refactor/SQDSDKS-6916-setTimeout-tests
Closed

test: Remove set timeouts from tests and other cleanup#967
rmi22186 wants to merge 2 commits intofeat/SQDSDKS-6991-cookie-sync-gdpr-2from
refactor/SQDSDKS-6916-setTimeout-tests

Conversation

@rmi22186
Copy link
Copy Markdown
Member

Instructions

  1. PR target branch should be against development
  2. PR title name should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-title-check.yml
  3. PR branch prefix should follow this format: https://github.com/mParticle/mparticle-workflows/blob/main/.github/workflows/pr-branch-check-name.yml

Summary

In this PR, there is a lot of cleanup

  • The main refactor is in cookie sync. I removed the setTimeout from the mock for onload and have it immediately call the callback, to avoid having setTImeout elsewhere in the cookie sync manager which has historically been very flakey.
  • removed Should and replaced with expect
  • used hasConfigurationReturned from Utils to keep things DRY
  • cleaned up function() {} to () => {} in some places

There is plenty more to do, but I was already going beyond the scope of this jira ticket.

Testing Plan

  • Was this tested locally? If not, explain why.

Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)

Comment thread test/src/tests-cookie-syncing.ts Outdated
Comment on lines +164 to +167
await waitForCondition(() => {
return (
mParticle.Identity.getCurrentUser()?.getMPID() === 'otherMPID'
);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await waitForCondition(() => {
return (
mParticle.Identity.getCurrentUser()?.getMPID() === 'otherMPID'
);
await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'otherMPID');

Comment thread test/src/tests-cookie-syncing.ts Outdated
mParticle.Identity.login({
userIdentities: { customerid: 'abc' },
});
await waitForCondition(() => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You may need to modify some of the other lines as well to get this to work.

Suggested change
await waitForCondition(() => {
await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1');

Comment thread test/src/tests-cookie-syncing.ts Outdated
).to.equal(1);
const data = mParticle.getInstance()._Persistence.getLocalStorage();
data[testMPID].csd.should.have.property('5');
await waitForCondition(hasIdentifyReturned)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await waitForCondition(hasIdentifyReturned)
await waitForCondition(hasIdentifyReturned);

});

it("should disable cookie sync if 'Do Not Forward' when 'Consent Rejected' is selected and user consent is rejected", function(done) {
it("should disable cookie sync if 'Do Not Forward' when 'Consent Rejected' is selected and user consent is rejected", function() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: See if you can easily replace these function references with () => if possible. If not, no biggie.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yea let's do that in the future. i already did stuff that's out of scope...and it's getting a bit late :)

Comment thread test/src/tests-cookie-syncing.ts Outdated

mParticle.Identity.getCurrentUser().setConsentState(
falseConsentState
await waitForCondition(hasIdentifyReturned)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await waitForCondition(hasIdentifyReturned)
await waitForCondition(hasIdentifyReturned);

window.mParticle.init(apiKey, window.mParticle.config);

window.mParticle.logEvent('Blocked event');
await waitForCondition(hasIdentifyReturned)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
await waitForCondition(hasIdentifyReturned)
await waitForCondition(hasIdentifyReturned);

Comment thread test/src/tests-cookie-syncing.ts Outdated
});
}

return element;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

indent

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
17.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants