|
| 1 | +import { faker } from '@faker-js/faker'; |
1 | 2 | import { |
2 | 3 | InitialQueryInfo, |
3 | | - CompletedQueryInfo, |
4 | | - CompletedLocalQueryInfo, |
5 | 4 | LocalQueryInfo, |
6 | 5 | } from '../../../query-results'; |
7 | 6 | import { QueryEvaluationInfo, QueryWithResults } from '../../../run-queries-shared'; |
8 | 7 | import { CancellationTokenSource } from 'vscode'; |
9 | 8 | import { QueryResultType } from '../../../pure/legacy-messages'; |
| 9 | +import { QueryMetadata } from '../../../pure/interface-types'; |
10 | 10 |
|
11 | | -export function createMockLocalQueryInfo( |
12 | | - startTime: string, |
13 | | - userSpecifiedLabel?: string |
14 | | -): LocalQueryInfo { |
15 | | - return ({ |
16 | | - t: 'local', |
17 | | - userSpecifiedLabel, |
18 | | - startTime: startTime, |
19 | | - getQueryFileName() { |
20 | | - return 'query-file.ql'; |
21 | | - }, |
22 | | - getQueryName() { |
23 | | - return 'query-name'; |
24 | | - }, |
25 | | - initialInfo: ({ |
26 | | - databaseInfo: { |
27 | | - databaseUri: 'unused', |
28 | | - name: 'db-name', |
29 | | - }, |
30 | | - } as unknown) as InitialQueryInfo, |
31 | | - completedQuery: ({ |
32 | | - resultCount: 456, |
33 | | - statusString: 'in progress', |
34 | | - } as unknown) as CompletedQueryInfo, |
35 | | - } as unknown) as CompletedLocalQueryInfo; |
36 | | -} |
| 11 | +export function createMockLocalQueryInfo({ |
| 12 | + startTime = new Date(), |
| 13 | + resultCount = 0, |
| 14 | + userSpecifiedLabel = undefined, |
| 15 | + failureReason = undefined, |
| 16 | + dbName = 'db-name', |
| 17 | + hasMetadata = false, |
| 18 | + queryWithResults = undefined, |
| 19 | +}: { |
| 20 | + startTime?: Date, |
| 21 | + resultCount?: number, |
| 22 | + userSpecifiedLabel?: string, |
| 23 | + failureReason?: string, |
| 24 | + dbName?: string, |
| 25 | + hasMetadata?: boolean, |
| 26 | + queryWithResults?: QueryWithResults | undefined, |
| 27 | +}): LocalQueryInfo { |
| 28 | + const cancellationToken = { |
| 29 | + dispose: () => { /**/ }, |
| 30 | + } as CancellationTokenSource; |
37 | 31 |
|
38 | | -export function createMockLocalQuery( |
39 | | - dbName = 'a', |
40 | | - queryWithResults?: QueryWithResults, |
41 | | - isFail = false |
42 | | -): LocalQueryInfo { |
43 | 32 | const initialQueryInfo = { |
44 | | - databaseInfo: { name: dbName }, |
45 | | - start: new Date(), |
46 | | - queryPath: 'hucairz' |
| 33 | + queryText: 'select 1', |
| 34 | + isQuickQuery: false, |
| 35 | + isQuickEval: false, |
| 36 | + queryName: 'query-name', |
| 37 | + queryPath: 'query-file.ql', |
| 38 | + databaseInfo: { |
| 39 | + databaseUri: 'databaseUri', |
| 40 | + name: dbName, |
| 41 | + }, |
| 42 | + start: startTime, |
| 43 | + id: faker.datatype.number().toString(), |
| 44 | + userSpecifiedLabel |
47 | 45 | } as InitialQueryInfo; |
48 | 46 |
|
49 | | - const cancellationToken = { |
50 | | - dispose: () => { /**/ }, |
51 | | - } as CancellationTokenSource; |
| 47 | + const localQuery = new LocalQueryInfo(initialQueryInfo, cancellationToken); |
52 | 48 |
|
53 | | - const fqi = new LocalQueryInfo( |
54 | | - initialQueryInfo, |
55 | | - cancellationToken, |
56 | | - ); |
| 49 | + localQuery.failureReason = failureReason; |
57 | 50 |
|
58 | 51 | if (queryWithResults) { |
59 | | - fqi.completeThisQuery(queryWithResults); |
| 52 | + localQuery.completeThisQuery(queryWithResults); |
| 53 | + localQuery.completedQuery?.setResultCount(1); |
| 54 | + } else if (resultCount > 0) { |
| 55 | + const queryWithResults = createMockQueryWithResults({ hasMetadata }); |
| 56 | + localQuery.completeThisQuery(queryWithResults); |
| 57 | + localQuery.completedQuery?.setResultCount(resultCount); |
60 | 58 | } |
61 | 59 |
|
62 | | - if (isFail) { |
63 | | - fqi.failureReason = 'failure reason'; |
64 | | - } |
65 | | - |
66 | | - return fqi; |
| 60 | + return localQuery; |
67 | 61 | } |
68 | 62 |
|
69 | | -export function createMockQueryWithResults( |
70 | | - sandbox: sinon.SinonSandbox, |
| 63 | +export function createMockQueryWithResults({ |
| 64 | + sandbox = undefined, |
71 | 65 | didRunSuccessfully = true, |
72 | | - hasInterpretedResults = true |
73 | | -): QueryWithResults { |
| 66 | + hasInterpretedResults = true, |
| 67 | + hasMetadata = undefined |
| 68 | +}: { |
| 69 | + sandbox?: sinon.SinonSandbox, |
| 70 | + didRunSuccessfully?: boolean, |
| 71 | + hasInterpretedResults?: boolean, |
| 72 | + hasMetadata?: boolean, |
| 73 | +}): QueryWithResults { |
| 74 | + const dispose = sandbox ? sandbox.spy() : () => { /**/ }; |
| 75 | + const deleteQuery = sandbox ? sandbox.stub() : () => { /**/ }; |
| 76 | + const metadata = hasMetadata ? { name: 'query-name' } as QueryMetadata : undefined; |
| 77 | + |
74 | 78 | return { |
75 | 79 | query: { |
76 | 80 | hasInterpretedResults: () => Promise.resolve(hasInterpretedResults), |
77 | | - deleteQuery: sandbox.stub(), |
| 81 | + deleteQuery, |
| 82 | + metadata, |
78 | 83 | } as unknown as QueryEvaluationInfo, |
79 | 84 | successful: didRunSuccessfully, |
80 | | - message: 'foo', |
81 | | - dispose: sandbox.spy(), |
| 85 | + dispose, |
82 | 86 | result: { |
83 | 87 | evaluationTime: 1, |
84 | 88 | queryId: 0, |
|
0 commit comments