Merge pull request #3290 from github/robertbrignull/history-tests-dtos
Don't accidentally mix DTO and non-DTO types in query-history-store.test.ts
This commit is contained in:
@@ -3,7 +3,7 @@ import {
|
||||
writeQueryHistoryToFile,
|
||||
} from "../../../../../src/query-history/store/query-history-store";
|
||||
import { join } from "path";
|
||||
import { writeFileSync, mkdirpSync, writeFile } from "fs-extra";
|
||||
import { writeFileSync, mkdirpSync } from "fs-extra";
|
||||
import type { InitialQueryInfo } from "../../../../../src/query-results";
|
||||
import { LocalQueryInfo } from "../../../../../src/query-results";
|
||||
import type { QueryWithResults } from "../../../../../src/run-queries-shared";
|
||||
@@ -13,22 +13,18 @@ import type { DatabaseInfo } from "../../../../../src/common/interface-types";
|
||||
import type { CancellationTokenSource } from "vscode";
|
||||
import { Uri } from "vscode";
|
||||
import { tmpDir } from "../../../../../src/tmp-dir";
|
||||
import type { VariantAnalysisHistoryItem } from "../../../../../src/query-history/variant-analysis-history-item";
|
||||
import type { QueryHistoryInfo } from "../../../../../src/query-history/query-history-info";
|
||||
import { createMockVariantAnalysisHistoryItem } from "../../../../factories/query-history/variant-analysis-history-item";
|
||||
import { nanoid } from "nanoid";
|
||||
import type {
|
||||
QueryHistoryDto,
|
||||
QueryHistoryItemDto,
|
||||
} from "../../../../../src/query-history/store/query-history-dto";
|
||||
import { mapQueryHistoryToDto } from "../../../../../src/query-history/store/query-history-domain-mapper";
|
||||
|
||||
describe("write and read", () => {
|
||||
let infoSuccessRaw: LocalQueryInfo;
|
||||
let infoSuccessInterpreted: LocalQueryInfo;
|
||||
let infoEarlyFailure: LocalQueryInfo;
|
||||
let infoLateFailure: LocalQueryInfo;
|
||||
let infoInProgress: LocalQueryInfo;
|
||||
|
||||
let variantAnalysis1: VariantAnalysisHistoryItem;
|
||||
let variantAnalysis2: VariantAnalysisHistoryItem;
|
||||
|
||||
let allHistory: QueryHistoryInfo[];
|
||||
let allHistoryDtos: QueryHistoryItemDto[];
|
||||
let expectedHistory: QueryHistoryInfo[];
|
||||
let queryPath: string;
|
||||
let cnt = 0;
|
||||
@@ -36,23 +32,23 @@ describe("write and read", () => {
|
||||
beforeEach(() => {
|
||||
queryPath = join(Uri.file(tmpDir.name).fsPath, `query-${cnt++}`);
|
||||
|
||||
infoSuccessRaw = createMockFullQueryInfo(
|
||||
const infoSuccessRaw = createMockFullQueryInfo(
|
||||
"a",
|
||||
createMockQueryWithResults(`${queryPath}-a`, false, "/a/b/c/a"),
|
||||
);
|
||||
infoSuccessInterpreted = createMockFullQueryInfo(
|
||||
const infoSuccessInterpreted = createMockFullQueryInfo(
|
||||
"b",
|
||||
createMockQueryWithResults(`${queryPath}-b`, true, "/a/b/c/b"),
|
||||
);
|
||||
infoEarlyFailure = createMockFullQueryInfo("c", undefined, true);
|
||||
infoLateFailure = createMockFullQueryInfo(
|
||||
const infoEarlyFailure = createMockFullQueryInfo("c", undefined, true);
|
||||
const infoLateFailure = createMockFullQueryInfo(
|
||||
"d",
|
||||
createMockQueryWithResults(`${queryPath}-c`, false, "/a/b/c/d"),
|
||||
);
|
||||
infoInProgress = createMockFullQueryInfo("e");
|
||||
const infoInProgress = createMockFullQueryInfo("e");
|
||||
|
||||
variantAnalysis1 = createMockVariantAnalysisHistoryItem({});
|
||||
variantAnalysis2 = createMockVariantAnalysisHistoryItem({});
|
||||
const variantAnalysis1 = createMockVariantAnalysisHistoryItem({});
|
||||
const variantAnalysis2 = createMockVariantAnalysisHistoryItem({});
|
||||
|
||||
allHistory = [
|
||||
infoSuccessRaw,
|
||||
@@ -64,6 +60,8 @@ describe("write and read", () => {
|
||||
variantAnalysis2,
|
||||
];
|
||||
|
||||
allHistoryDtos = mapQueryHistoryToDto(allHistory);
|
||||
|
||||
// the expected results only contains the history with completed queries
|
||||
expectedHistory = [
|
||||
infoSuccessRaw,
|
||||
@@ -139,54 +137,50 @@ describe("write and read", () => {
|
||||
|
||||
it("should remove remote queries from the history", async () => {
|
||||
const path = join(tmpDir.name, "query-history-with-remote.json");
|
||||
await writeFile(
|
||||
path,
|
||||
JSON.stringify({
|
||||
version: 2,
|
||||
queries: [
|
||||
...allHistory,
|
||||
{
|
||||
t: "remote",
|
||||
status: "InProgress",
|
||||
completed: false,
|
||||
queryId: nanoid(),
|
||||
remoteQuery: {
|
||||
queryName: "query-name",
|
||||
queryFilePath: "query-file.ql",
|
||||
queryText: "select 1",
|
||||
language: "javascript",
|
||||
controllerRepository: {
|
||||
owner: "github",
|
||||
name: "vscode-codeql-integration-tests",
|
||||
},
|
||||
executionStartTime: Date.now(),
|
||||
actionsWorkflowRunId: 1,
|
||||
repositoryCount: 0,
|
||||
writeRawQueryHistory(path, {
|
||||
version: 2,
|
||||
queries: [
|
||||
...allHistoryDtos,
|
||||
{
|
||||
t: "remote",
|
||||
status: "InProgress",
|
||||
completed: false,
|
||||
queryId: nanoid(),
|
||||
remoteQuery: {
|
||||
queryName: "query-name",
|
||||
queryFilePath: "query-file.ql",
|
||||
queryText: "select 1",
|
||||
language: "javascript",
|
||||
controllerRepository: {
|
||||
owner: "github",
|
||||
name: "vscode-codeql-integration-tests",
|
||||
},
|
||||
executionStartTime: Date.now(),
|
||||
actionsWorkflowRunId: 1,
|
||||
repositoryCount: 0,
|
||||
},
|
||||
{
|
||||
t: "remote",
|
||||
status: "Completed",
|
||||
completed: true,
|
||||
queryId: nanoid(),
|
||||
remoteQuery: {
|
||||
queryName: "query-name",
|
||||
queryFilePath: "query-file.ql",
|
||||
queryText: "select 1",
|
||||
language: "javascript",
|
||||
controllerRepository: {
|
||||
owner: "github",
|
||||
name: "vscode-codeql-integration-tests",
|
||||
},
|
||||
executionStartTime: Date.now(),
|
||||
actionsWorkflowRunId: 1,
|
||||
repositoryCount: 0,
|
||||
} as unknown as QueryHistoryItemDto,
|
||||
{
|
||||
t: "remote",
|
||||
status: "Completed",
|
||||
completed: true,
|
||||
queryId: nanoid(),
|
||||
remoteQuery: {
|
||||
queryName: "query-name",
|
||||
queryFilePath: "query-file.ql",
|
||||
queryText: "select 1",
|
||||
language: "javascript",
|
||||
controllerRepository: {
|
||||
owner: "github",
|
||||
name: "vscode-codeql-integration-tests",
|
||||
},
|
||||
executionStartTime: Date.now(),
|
||||
actionsWorkflowRunId: 1,
|
||||
repositoryCount: 0,
|
||||
},
|
||||
],
|
||||
}),
|
||||
"utf8",
|
||||
);
|
||||
} as unknown as QueryHistoryItemDto,
|
||||
],
|
||||
});
|
||||
|
||||
const actual = await readQueryHistoryFromFile(path);
|
||||
expect(actual.length).toEqual(expectedHistory.length);
|
||||
@@ -194,14 +188,10 @@ describe("write and read", () => {
|
||||
|
||||
it("should handle an invalid query history version", async () => {
|
||||
const badPath = join(tmpDir.name, "bad-query-history.json");
|
||||
writeFileSync(
|
||||
badPath,
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
queries: allHistory,
|
||||
}),
|
||||
"utf8",
|
||||
);
|
||||
writeRawQueryHistory(badPath, {
|
||||
version: 3,
|
||||
queries: allHistoryDtos,
|
||||
});
|
||||
|
||||
const allHistoryActual = await readQueryHistoryFromFile(badPath);
|
||||
// version number is invalid. Should return an empty array.
|
||||
@@ -274,4 +264,8 @@ describe("write and read", () => {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function writeRawQueryHistory(path: string, queryHistory: QueryHistoryDto) {
|
||||
writeFileSync(path, JSON.stringify(queryHistory), "utf8");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user