|
4 | 4 | CompletedLocalQueryInfo, |
5 | 5 | LocalQueryInfo, |
6 | 6 | } from '../../../query-results'; |
| 7 | +import { QueryEvaluationInfo, QueryWithResults } from '../../../run-queries-shared'; |
| 8 | +import { CancellationTokenSource } from 'vscode'; |
| 9 | +import { QueryResultType } from '../../../pure/legacy-messages'; |
7 | 10 |
|
8 | 11 | export function createMockLocalQueryInfo( |
9 | 12 | startTime: string, |
@@ -31,3 +34,56 @@ export function createMockLocalQueryInfo( |
31 | 34 | } as unknown) as CompletedQueryInfo, |
32 | 35 | } as unknown) as CompletedLocalQueryInfo; |
33 | 36 | } |
| 37 | + |
| 38 | +export function createMockLocalQuery( |
| 39 | + dbName = 'a', |
| 40 | + queryWithResults?: QueryWithResults, |
| 41 | + isFail = false |
| 42 | +): LocalQueryInfo { |
| 43 | + const initialQueryInfo = { |
| 44 | + databaseInfo: { name: dbName }, |
| 45 | + start: new Date(), |
| 46 | + queryPath: 'hucairz' |
| 47 | + } as InitialQueryInfo; |
| 48 | + |
| 49 | + const cancellationToken = { |
| 50 | + dispose: () => { /**/ }, |
| 51 | + } as CancellationTokenSource; |
| 52 | + |
| 53 | + const fqi = new LocalQueryInfo( |
| 54 | + initialQueryInfo, |
| 55 | + cancellationToken, |
| 56 | + ); |
| 57 | + |
| 58 | + if (queryWithResults) { |
| 59 | + fqi.completeThisQuery(queryWithResults); |
| 60 | + } |
| 61 | + |
| 62 | + if (isFail) { |
| 63 | + fqi.failureReason = 'failure reason'; |
| 64 | + } |
| 65 | + |
| 66 | + return fqi; |
| 67 | +} |
| 68 | + |
| 69 | +export function createMockQueryWithResults( |
| 70 | + sandbox: sinon.SinonSandbox, |
| 71 | + didRunSuccessfully = true, |
| 72 | + hasInterpretedResults = true |
| 73 | +): QueryWithResults { |
| 74 | + return { |
| 75 | + query: { |
| 76 | + hasInterpretedResults: () => Promise.resolve(hasInterpretedResults), |
| 77 | + deleteQuery: sandbox.stub(), |
| 78 | + } as unknown as QueryEvaluationInfo, |
| 79 | + successful: didRunSuccessfully, |
| 80 | + message: 'foo', |
| 81 | + dispose: sandbox.spy(), |
| 82 | + result: { |
| 83 | + evaluationTime: 1, |
| 84 | + queryId: 0, |
| 85 | + runId: 0, |
| 86 | + resultType: QueryResultType.SUCCESS, |
| 87 | + } |
| 88 | + }; |
| 89 | +} |
0 commit comments