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

[ACS-6456] Migrated Share File e2es to Playwright #3565

Merged
merged 5 commits into from
Dec 22, 2023
Merged

Conversation

SheenaMalhotra182
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation
  • Other... Please describe:

What is the current behaviour? (You can also link to an open issue here)
Protractor is deprecated and e2es for 'share-file.test.ts' are written in Protractor.

What is the new behaviour?
Migrated the Protractor test cases into Playwright for 'share-file.test.ts' file.

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:
https://alfresco.atlassian.net/browse/ACS-6456

test.describe('when logged in', () => {
const expiryDateObj: Date = new Date();
expiryDateObj.setFullYear(expiryDateObj.getFullYear() + 1);
const expiryDate: any = expiryDateObj.toISOString().replace('Z', '+0000');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use any

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing 'any' here is giving a red line error on expiryDate here
await shareApi.shareFilesByIds([file6Id, file7Id], expiryDate);
because shareFileByIds() and other nested methods expect expireDate to be of type 'Date'. But strangely, the shareFilesByIds() method works only if the expireDate is of type 'string', otherwise the tests don't work as expected.
image

Due to this strange behavior, having 'any' helps but if I remove 'any', I will have to modify the data type of expireDate from 'Date' to 'string' at multiple places and in JS-API which will need upstream.

I have tried multiple ways to make expiryDate an object of type 'Date' so that no changes are required on the API level but that does not seem to work

What do you suggest here? Should we go ahead with 'any'? or can we use some other approach here? @MichalKinas

Copy link
Contributor

Choose a reason for hiding this comment

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

If you need to pass a Date there you can use expiryDateObj object, expiryDate should be a string and using any here is incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried using expiryDateObj but this does not help as 'shareFilesByIds()' is working properly only with expiryDate as string.
If we remove any, we get an error because 'shareFilesByIds()' expects a Date but is somehow working only with string

Copy link
Contributor

@MichalKinas MichalKinas Dec 21, 2023

Choose a reason for hiding this comment

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

You can try creating new date from expiryDate but if it won't work it means that your code is not correct somewhere, any is anti-pattern and it should be used only in specific cases and this is not one of them. any shouldn't be used to fix an error or not working code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I understand what you are saying but the problem I am facing in doing so is that

  1. the API actually expects 'expiryDate' to be of type string. (see sharedLinkBodyCreate https://api-explorer.alfresco.com/api-explorer/?urls.primaryName=Core%20API#/shared-links/createSharedLink)
    image

  2. But, in the code, the expected type of 'expiryDate' is set to Date in JS API and all related methods like 'shareNodes()' or 'shareFileByIds()'
    image

So even if I create new date from 'expiryDate' , the API will still not run as expected.
So far, this approach (using 'any') was being used in Protractor e2es so if we remove 'any', we either get some red line errors but the tests run fine
OR
we might need to make changes in JS API which I am not sure is feasible.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case you still don't have to use any, you can declare expiryDate as let expiryDate: Date | string = ... and then pass it to the correct function like expiryDate as Date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing expiryDate as Date does not help because this.apiService.share.createSharedLink(data); fails if expiry is of type 'Date' and gives status code 400.
It gives 200 only with type string (as per swagger https://api-explorer.alfresco.com/api-explorer/?urls.primaryName=Core%20API#/shared-links/createSharedLink)
and I am blocked because I cannot set the type of expiryDate to string.
image (3)
image (2)

@DenysVuika, Michal suggested double-checking with you if we should make changes for this in JS-API for e2es.
Can you please suggest what would be the feasible solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MichalKinas, as per my discussion with @DenysVuika, we can use 'any' for now and have a separate ticket to fix typings in JS-API.

I have created this JIRA https://alfresco.atlassian.net/browse/ACS-6533 for the same.

e2e/playwright/actions/src/tests/share/share-file.spec.ts Outdated Show resolved Hide resolved
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@SheenaMalhotra182 SheenaMalhotra182 merged commit 373a41b into develop Dec 22, 2023
25 checks passed
@SheenaMalhotra182 SheenaMalhotra182 deleted the ACS-6456 branch December 22, 2023 19:37
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