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

feat: Add number of testResultsCount #703

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions graphql_api/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,3 +842,15 @@ def test_branch_filter_on_test_results(self) -> None:
"""testResults(filters: { branch: "main"}) { edges { node { name } } }""",
)
assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]}

def test_resolve_test_results_count(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
TestFactory(repository=repo)
TestFactory(repository=repo)
res = self.fetch_repository(repo.name, """testResultsCount""")
assert res["testResultsCount"] == 2

def test_resolve_test_results_count_no_tests(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
res = self.fetch_repository(repo.name, """testResultsCount""")
assert res["testResultsCount"] == 0
1 change: 1 addition & 0 deletions graphql_api/types/repository/repository.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Repository {
last: Int
before: String
): TestResultConnection! @cost(complexity: 10, multipliers: ["first", "last"])
testResultsCount: Int!
}

type TestResultConnection {
Expand Down
6 changes: 6 additions & 0 deletions graphql_api/types/repository/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,9 @@ async def resolve_test_results(
else OrderingDirection.DESC,
**kwargs,
)


@repository_bindable.field("testResultsCount")
@sync_to_async
def resolve_test_results_count(repository: Repository, info: GraphQLResolveInfo) -> int:
return Test.objects.filter(repository=repository).count()
1 change: 1 addition & 0 deletions reports/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Meta:
model = models.Test

id = factory.Faker("word")
name = factory.Faker("word")
repository = factory.SubFactory(RepositoryFactory)


Expand Down
Loading