Make sorting tests work with remote queries & variant analysis history items#1710
Make sorting tests work with remote queries & variant analysis history items#1710elenatanasoiu merged 10 commits intomainfrom
Conversation
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`.
…ory items We can now, finally, test sorting works, with REAL objects.
We don't use it anymore.
87842d0 to
f0aa0a5
Compare
koesie10
left a comment
There was a problem hiding this comment.
LGTM, thanks for the multiple commits, those really make it easier to review!
| export function createMockVariantAnalysis({ | ||
| status = VariantAnalysisStatus.InProgress, | ||
| scannedRepos = createMockScannedRepos(), | ||
| skippedRepos = createMockSkippedRepos(), | ||
| executionStartTime = faker.datatype.number() | ||
| }: { | ||
| status?: VariantAnalysisStatus, | ||
| scannedRepos?: VariantAnalysisScannedRepository[], | ||
| skippedRepos?: VariantAnalysisSkippedRepositories, | ||
| executionStartTime?: number | undefined | ||
| }): VariantAnalysis { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok I've thought this a bit more. I'll try in my next PR to see if we could adapt it.
|
Thanks for the review @koesie10 ! |
🚨 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:
createMockVariantAnalysisandcreateMockVariantAnalysisHistoryItemto receive named params so that we can setresultCountandexecutionStartTime. We need this in order to test sorting by result and date.createMockRemoteQueryHistoryItem.LocalQueryInfointo a singlecreateMockLocalQueryInfomethod.createMockLocalQueryInfowe'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.Checklist
ready-for-doc-reviewlabel there.