33 writeQueryHistoryToFile ,
44} from "../../../../../src/query-history/store/query-history-store" ;
55import { join } from "path" ;
6- import { writeFileSync , mkdirpSync , writeFile } from "fs-extra" ;
6+ import { writeFileSync , mkdirpSync } from "fs-extra" ;
77import type { InitialQueryInfo } from "../../../../../src/query-results" ;
88import { LocalQueryInfo } from "../../../../../src/query-results" ;
99import type { QueryWithResults } from "../../../../../src/run-queries-shared" ;
@@ -13,13 +13,18 @@ import type { DatabaseInfo } from "../../../../../src/common/interface-types";
1313import type { CancellationTokenSource } from "vscode" ;
1414import { Uri } from "vscode" ;
1515import { tmpDir } from "../../../../../src/tmp-dir" ;
16- import type { VariantAnalysisHistoryItem } from "../../../../../src/query-history/variant-analysis-history-item" ;
1716import type { QueryHistoryInfo } from "../../../../../src/query-history/query-history-info" ;
1817import { createMockVariantAnalysisHistoryItem } from "../../../../factories/query-history/variant-analysis-history-item" ;
1918import { nanoid } from "nanoid" ;
19+ import type {
20+ QueryHistoryDto ,
21+ QueryHistoryItemDto ,
22+ } from "../../../../../src/query-history/store/query-history-dto" ;
23+ import { mapQueryHistoryToDto } from "../../../../../src/query-history/store/query-history-domain-mapper" ;
2024
2125describe ( "write and read" , ( ) => {
2226 let allHistory : QueryHistoryInfo [ ] ;
27+ let allHistoryDtos : QueryHistoryItemDto [ ] ;
2328 let expectedHistory : QueryHistoryInfo [ ] ;
2429 let queryPath : string ;
2530 let cnt = 0 ;
@@ -55,6 +60,8 @@ describe("write and read", () => {
5560 variantAnalysis2 ,
5661 ] ;
5762
63+ allHistoryDtos = mapQueryHistoryToDto ( allHistory ) ;
64+
5865 // the expected results only contains the history with completed queries
5966 expectedHistory = [
6067 infoSuccessRaw ,
@@ -130,69 +137,61 @@ describe("write and read", () => {
130137
131138 it ( "should remove remote queries from the history" , async ( ) => {
132139 const path = join ( tmpDir . name , "query-history-with-remote.json" ) ;
133- await writeFile (
134- path ,
135- JSON . stringify ( {
136- version : 2 ,
137- queries : [
138- ...allHistory ,
139- {
140- t : "remote" ,
141- status : "InProgress" ,
142- completed : false ,
143- queryId : nanoid ( ) ,
144- remoteQuery : {
145- queryName : "query-name" ,
146- queryFilePath : "query-file.ql" ,
147- queryText : "select 1" ,
148- language : "javascript" ,
149- controllerRepository : {
150- owner : "github" ,
151- name : "vscode-codeql-integration-tests" ,
152- } ,
153- executionStartTime : Date . now ( ) ,
154- actionsWorkflowRunId : 1 ,
155- repositoryCount : 0 ,
140+ writeRawQueryHistory ( path , {
141+ version : 2 ,
142+ queries : [
143+ ...allHistoryDtos ,
144+ {
145+ t : "remote" ,
146+ status : "InProgress" ,
147+ completed : false ,
148+ queryId : nanoid ( ) ,
149+ remoteQuery : {
150+ queryName : "query-name" ,
151+ queryFilePath : "query-file.ql" ,
152+ queryText : "select 1" ,
153+ language : "javascript" ,
154+ controllerRepository : {
155+ owner : "github" ,
156+ name : "vscode-codeql-integration-tests" ,
156157 } ,
158+ executionStartTime : Date . now ( ) ,
159+ actionsWorkflowRunId : 1 ,
160+ repositoryCount : 0 ,
157161 } ,
158- {
159- t : "remote" ,
160- status : "Completed" ,
161- completed : true ,
162- queryId : nanoid ( ) ,
163- remoteQuery : {
164- queryName : "query-name" ,
165- queryFilePath : "query-file.ql" ,
166- queryText : "select 1" ,
167- language : "javascript" ,
168- controllerRepository : {
169- owner : "github" ,
170- name : "vscode-codeql-integration-tests" ,
171- } ,
172- executionStartTime : Date . now ( ) ,
173- actionsWorkflowRunId : 1 ,
174- repositoryCount : 0 ,
162+ } as unknown as QueryHistoryItemDto ,
163+ {
164+ t : "remote" ,
165+ status : "Completed" ,
166+ completed : true ,
167+ queryId : nanoid ( ) ,
168+ remoteQuery : {
169+ queryName : "query-name" ,
170+ queryFilePath : "query-file.ql" ,
171+ queryText : "select 1" ,
172+ language : "javascript" ,
173+ controllerRepository : {
174+ owner : "github" ,
175+ name : "vscode-codeql-integration-tests" ,
175176 } ,
177+ executionStartTime : Date . now ( ) ,
178+ actionsWorkflowRunId : 1 ,
179+ repositoryCount : 0 ,
176180 } ,
177- ] ,
178- } ) ,
179- "utf8" ,
180- ) ;
181+ } as unknown as QueryHistoryItemDto ,
182+ ] ,
183+ } ) ;
181184
182185 const actual = await readQueryHistoryFromFile ( path ) ;
183186 expect ( actual . length ) . toEqual ( expectedHistory . length ) ;
184187 } ) ;
185188
186189 it ( "should handle an invalid query history version" , async ( ) => {
187190 const badPath = join ( tmpDir . name , "bad-query-history.json" ) ;
188- writeFileSync (
189- badPath ,
190- JSON . stringify ( {
191- version : 3 ,
192- queries : allHistory ,
193- } ) ,
194- "utf8" ,
195- ) ;
191+ writeRawQueryHistory ( badPath , {
192+ version : 3 ,
193+ queries : allHistoryDtos ,
194+ } ) ;
196195
197196 const allHistoryActual = await readQueryHistoryFromFile ( badPath ) ;
198197 // version number is invalid. Should return an empty array.
@@ -265,4 +264,8 @@ describe("write and read", () => {
265264
266265 return result ;
267266 }
267+
268+ function writeRawQueryHistory ( path : string , queryHistory : QueryHistoryDto ) {
269+ writeFileSync ( path , JSON . stringify ( queryHistory ) , "utf8" ) ;
270+ }
268271} ) ;
0 commit comments