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

WOR-1817: Refactor api service tests #3033

Merged
merged 9 commits into from
Sep 18, 2024
Merged

Conversation

blakery
Copy link
Contributor

@blakery blakery commented Sep 16, 2024

Ticket: https://broadworkbench.atlassian.net/browse/WOR-1817

Create better testing setup for api-level tests, and apply to workspace service api.


PR checklist

  • Include the JIRA issue number in the PR description and title
  • Make sure Swagger is updated if API changes
    • ...and Orchestration's Swagger too!
  • If you changed anything in model/, then you should publish a new official rawls-model and update rawls-model in Orchestration's dependencies.
  • Get two thumbsworth of PR review
  • Verify all tests go green, including CI tests
  • Squash commits and merge to develop (branches are automatically deleted after merging)
  • Inform other teams of any substantial changes via Slack and/or email

@@ -57,7 +57,7 @@ trait WorkspaceApiService extends UserInfoDirectives {
}
} ~
path("workspaces" / "tags") {
parameters('q.?, "limit".as[Int].optional) { (queryString, limit) =>
parameters(Symbol("q").?, "limit".as[Int].optional) { (queryString, limit) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't functional - it's just that the previous syntax is deprecated.

@@ -79,13 +79,6 @@ trait WorkspaceApiService extends UserInfoDirectives {
}
} ~
path("workspaces" / Segment / Segment) { (workspaceNamespace, workspaceName) =>
/* we enforce a 6-character minimum for workspaceNamespace, as part of billing project creation.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment hasn't been true since the paths were re-ordered for correct path specificity.
In this PR however, we can finally demonstrate that this is true.

entity(as[Set[WorkspaceACLUpdate]]) { aclUpdate =>
val inviteUsersNotFoundValue = inviteUsersNotFound match {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes a bug discovered in testing, where if the query string contained an empty arg (eg: ?inviteUsersNotFound=), the service would throw a 500 because it tries to call .toBoolean on an empty string, which fails with an IllegalArgumentException.

override val bucketMigrationServiceConstructor: RawlsRequestContext => BucketMigrationService = _ =>
mock[BucketMigrationService],
override val userServiceConstructor: RawlsRequestContext => UserService = _ => mock[UserService]
)(implicit val executionContext: ExecutionContext)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The basic purpose of this is:

  1. set up default mocks with no functionality, so you only need to specify the ones you care about
  2. set up paths that reflect those in RawlsApiService, but without the parts that we don't care about, such as metrics and logging.

@@ -1439,4 +1447,68 @@ class SubmissionApiServiceSpec extends ApiServiceSpec with TableDrivenPropertyCh
}
}
}

it should "return a 201 when a comment is updated" in {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were in the original POC - so I might as well include them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff is kind of useless, because basically the entire file was replaced. I'd recommend just looking at the new file when reviewing.

@blakery blakery requested review from a team, cahrens and marctalbott and removed request for a team September 16, 2024 20:32
@blakery blakery marked this pull request as ready for review September 16, 2024 20:33
Copy link
Contributor

@marctalbott marctalbott left a comment

Choose a reason for hiding this comment

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

What does the change in coverage in the WorkspaceService look like?

class MockApiService(
val userInfo: UserInfo =
UserInfo(RawlsUserEmail(""), OAuth2BearerToken("token"), 123, RawlsUserSubjectId("123456789876543212349")),
override val openIDConnectConfiguration: OpenIDConnectConfiguration = mock[OpenIDConnectConfiguration],
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth setting these to RETURN_SMART_NULLS to help people figure out what calls aren't getting mocked correctly when they're writing a new test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

@blakery
Copy link
Contributor Author

blakery commented Sep 18, 2024

What does the change in coverage in the WorkspaceService look like?

A 3% reduction in coverage (about 40 lines).

The most significant losses are in getWorkspaceById, getBucketOptions, destroyPet, listPendingFileTransfersForWorkspace, and getBucketUsage.

I'll make a follow on ticket to add tests for those.
It will likely involve some refactoring of the service, so I think it's better to keep it separate.

@blakery
Copy link
Contributor Author

blakery commented Sep 18, 2024

Created WOR-1823 for follow-on test coverage.

@blakery blakery merged commit 712a4ac into develop Sep 18, 2024
29 checks passed
@blakery blakery deleted the refactor-api-service-tests branch September 18, 2024 14:35
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