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

fix: fix tests using the new sdk #1665

Open
wants to merge 29 commits into
base: new-sdk-release
Choose a base branch
from

Conversation

martin-trajanovski
Copy link
Collaborator

@martin-trajanovski martin-trajanovski commented Nov 19, 2024

Description

Fixing e2e and unit tests with the new sdk

Motivation

E2e and unit tests failing after the new sdk migration.

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Documentation

  • swagger documentation updated [required]
  • official documentation updated [nice-to-have]

official documentation info

If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included

Backend version

  • Does it require a specific version of the backend
  • which version of the backend is required:

Summary by Sourcery

Bug Fixes:

  • Fix tests to use the new SDK by updating service imports and method calls across multiple test files.

Summary by Sourcery

Fix tests to work with the new SDK by updating service imports and method calls. Refactor Cypress commands for better token handling. Update test files to ensure compatibility with the new SDK structure.

Bug Fixes:

  • Fix tests to use the new SDK by updating service imports and method calls across multiple test files.

Enhancements:

  • Refactor Cypress commands to use a new method for retrieving tokens, improving code readability and maintainability.

Tests:

  • Update test files to align with the new SDK structure, ensuring compatibility and functionality.

@martin-trajanovski martin-trajanovski marked this pull request as ready for review November 25, 2024 14:33
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @martin-trajanovski - I've reviewed your changes - here's some feedback:

Overall Comments:

  • There are some TODO comments about fixing types that should be addressed in follow-up PRs, but they don't block the core functionality
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/app/shared/MockStubs.ts Outdated Show resolved Hide resolved
Bumps the types group with 1 update: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node).


Updates `@types/node` from 22.9.0 to 22.9.3
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: types
...

Signed-off-by: dependabot[bot] <support@github.com>
…ypes-c0e67af0c7

chore(deps-dev): bump @types/node from 22.9.0 to 22.9.3 in the types group
Bumps [cypress](https://github.com/cypress-io/cypress) from 13.15.2 to 13.16.0.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/CHANGELOG.md)
- [Commits](cypress-io/cypress@v13.15.2...v13.16.0)

---
updated-dependencies:
- dependency-name: cypress
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…ypress-13.16.0

chore(deps-dev): bump cypress from 13.15.2 to 13.16.0
Bumps [mathjs](https://github.com/josdejong/mathjs) from 13.2.2 to 14.0.0.
- [Changelog](https://github.com/josdejong/mathjs/blob/develop/HISTORY.md)
- [Commits](josdejong/mathjs@v13.2.2...v14.0.0)

---
updated-dependencies:
- dependency-name: mathjs
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…athjs-14.0.0

chore(deps): bump mathjs from 13.2.2 to 14.0.0
@martin-trajanovski martin-trajanovski added the DCS DAPHNE Contribution to SciCat label Nov 26, 2024
Copy link
Contributor

@Junjiequan Junjiequan left a comment

Choose a reason for hiding this comment

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

Looks good in general.
I stopped tracking the use case of createMock where the mockData has already been defined in the MockStubs.ts file. It would be easier to track them with search in vscode

@@ -131,7 +136,7 @@ describe("DatasetTableComponent", () => {

describe("#userErrorCondition()", () => {
it("should return true if dataset has missingFilesError", () => {
const dataset = new Dataset();
const dataset = createMock<DatasetClass>({});
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it better if we use DatasetClass as the default for mockDataset and use OutputDatasetObsoleteDto for edge cases? What do you think?

Comment on lines +166 to +170
// TODO: Fix this any type casting here
spyOn(
component.userIdentititiesService,
"userIdentitiesControllerIsValidEmail",
).and.returnValue(of(true) as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is type any needed here?

return data as T;
}

export const mockDataset = createMock<OutputDatasetObsoleteDto>({});
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above, wouldn't it make more sense to use DatasetClass instead of ObsoleteDto?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I mentioned below I am not focusing that much on the details here in the tests right now as we will refactor all this in the near future if we use the next version of the dataset endpoints. They will be typed correctly and we wont have these inconsistencies anymore

Comment on lines +85 to +88
// TODO: Try to fix any type casting here
datasetApi.datasetsControllerThumbnail.and.returnValue(
of({ thumbnail } as any),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe something like of({ thumbnail } as unknown as HttpResponse<Attachment>)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I left a TODO comment here and don't want to investigate the proper fix right now as it is in the tests and the tests are passing. Will try to do it later and fix most of the TODOs left with this PR in the future whenever we can get some extra time doing this. I think I spent a lot of time around the types and most of them at least in the code are fixed. In the tests we can check it later I hope. But thanks for the feedback @Junjiequan I appreciate it.

});

it("should fetch thumbnail and cache it if not already cached", async () => {
const pid = "test-pid";
const thumbnail = "http://thumbnail-url.com/image.jpg";

datasetApi.thumbnail.and.returnValue(of({ thumbnail }));
datasetApi.datasetsControllerThumbnail.and.returnValue(
of({ thumbnail } as any),
Copy link
Contributor

@Junjiequan Junjiequan Nov 27, 2024

Choose a reason for hiding this comment

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

same as above

src/app/state-management/actions/datasets.actions.spec.ts Outdated Show resolved Hide resolved
src/app/state-management/actions/proposals.actions.spec.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DCS DAPHNE Contribution to SciCat testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants