Skip to content

Make sorting tests work with remote queries & variant analysis history items#1710

Merged
elenatanasoiu merged 10 commits intomainfrom
elena/sort-sorting
Nov 3, 2022
Merged

Make sorting tests work with remote queries & variant analysis history items#1710
elenatanasoiu merged 10 commits intomainfrom
elena/sort-sorting

Conversation

@elenatanasoiu
Copy link
Copy Markdown
Contributor

@elenatanasoiu elenatanasoiu commented Nov 3, 2022

🚨 Please review this commit-by-commit.

This is a follow-up to #1688 where we first started converting our query history tests to check all types of history items instead of just local query ones.

In order to test sorting with local queries, remote queries and variant analyses, we've had to make a few changes:

  1. Allow createMockVariantAnalysis and createMockVariantAnalysisHistoryItem to receive named params so that we can set resultCount and executionStartTime. We need this in order to test sorting by result and date.
  2. We do the same for createMockRemoteQueryHistoryItem.
  3. We're combining the two existing factory methods for creating a LocalQueryInfo into a single createMockLocalQueryInfo method.
  4. For createMockLocalQueryInfo we're now returning a real object instead of typecasting something else. Not having a real object blocked us from being able to understand which fields we need in our tests and how they interact together.
  5. Finally, we change our sorting tests to check all types of history item types, instead of just local queries.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

So that we can set them selectively.

For example, we'd like to set executionStartTime to test sorting by date.
Similarly, we want to provide params selectively to test sorting.

We're also setting some defaults to play nicely with our current
tests.
…artTime

Again, we'll need these for sorting.

We also want to be able to set/unset a userSpecifiedLabel. Since this factory
method is used in `history-item-label-provider.test.ts`, we have tests there
that count on this custom label being defined/undefined.
One factory method to rule them all!

There were a number of problems with these methods:

1. We were previously using two different factory methods to generate
a fake local queries. Ideally we'd just have one.

2. We weren't really creating a real LocalQueryInfo object, which
blocked us [1] from being able to correctly understand which fields we
need in our tests and how they interact together.

3. We stubbed a bunch of methods on the original object to get our tests
to work. We can now use a real object with all the trimmings.

[1]: #1697 (comment)
…y method

We're making a number of changes:

1. We're changing the userSpecifiedLabel value to be
`user-specified-name` instead of `xxx`

2. For local queries, we're changing `in progress` to `finished in 0
seconds` when the query has results. The previous version was
contradictory because any query still in progress wouldn't have results.

3. Similarly, for remote queries, we're changing `in progress` to
`completed` when the query has results. Here we actually set a `status`
property which means `in progress` becomes `completed`.
@elenatanasoiu elenatanasoiu changed the title Make sorting tests work with remote queries and variant analysis history items Make sorting tests work with remote queries & variant analysis history items Nov 3, 2022
…ory items

We can now, finally, test sorting works, with REAL objects.
We don't use it anymore.
@elenatanasoiu elenatanasoiu marked this pull request as ready for review November 3, 2022 14:57
@elenatanasoiu elenatanasoiu requested review from a team as code owners November 3, 2022 14:57
Copy link
Copy Markdown
Member

@koesie10 koesie10 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the multiple commits, those really make it easier to review!

Comment on lines +13 to +23
export function createMockVariantAnalysis({
status = VariantAnalysisStatus.InProgress,
scannedRepos = createMockScannedRepos(),
skippedRepos = createMockSkippedRepos(),
executionStartTime = faker.datatype.number()
}: {
status?: VariantAnalysisStatus,
scannedRepos?: VariantAnalysisScannedRepository[],
skippedRepos?: VariantAnalysisSkippedRepositories,
executionStartTime?: number | undefined
}): VariantAnalysis {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for making this change, this makes it much easier to use!

An alternative to this would be to allow passing in all properties using something like this:

export function createMockVariantAnalysis(data: Partial<VariantAnalysis>): VariantAnalysis {
  return {
    status: VariantAnalysisStatus.InProgress,
    // ... other defaults
    ...data,
  };
}

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice! I gave it a shot but I think it would involve declaring these params:

scannedRepos = createMockScannedRepos(),
skippedRepos = createMockSkippedRepos(),

outside of the method call and passing them in. That would require a lot more refactoring and I'm a bit refactored out. 😄

I considered adding it any way:

export function createMockVariantAnalysis({
  status = VariantAnalysisStatus.InProgress,
  scannedRepos = createMockScannedRepos(),
  skippedRepos = createMockSkippedRepos(),
  executionStartTime = faker.datatype.number(),
  data,
}: {
  status?: VariantAnalysisStatus,
  scannedRepos?: VariantAnalysisScannedRepository[],
  skippedRepos?: VariantAnalysisSkippedRepositories,
  executionStartTime?: number | undefined,
  data?: Partial<VariantAnalysis>
}): VariantAnalysis {
  return {
    // all the existing stuff
    ...data
  }
}

but that seems like it would defeat the point of it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok I've thought this a bit more. I'll try in my next PR to see if we could adapt it.

@elenatanasoiu
Copy link
Copy Markdown
Contributor Author

Thanks for the review @koesie10 !

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants