Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,44 @@ describe("initializeLatestView", () => {

expect(initializeLatestMaterializedView).not.toHaveBeenCalled();
});

it("uses the BigQuery project when updating an existing view", async () => {
const originalProjectId = process.env.PROJECT_ID;
process.env.PROJECT_ID = "function-project";
const metadata = {
schema: {
fields: [{ name: "document_id" }, { name: "old_data" }],
},
view: { query: "SELECT FIRST_VALUE(data)" },
};
mockView.getMetadata.mockResolvedValueOnce([metadata]);

try {
await initializeLatestView({
bq: { projectId: "bigquery-project" } as any,
dataset: { id: "test_dataset" } as any,
view: mockView as any,
viewExists: true,
rawChangeLogTableName: "test_raw_table",
rawLatestViewName: "test_raw_view",
changeTrackerConfig: {
...mockConfig,
useNewSnapshotQuerySyntax: true,
},
});

expect(mockView.setMetadata).toHaveBeenCalledWith(metadata);
expect(metadata.view.query).toContain(
"`bigquery-project.test_dataset.test_raw_table`"
);
expect(metadata.view.query).not.toContain("function-project");
} finally {
if (originalProjectId === undefined) {
delete process.env.PROJECT_ID;
} else {
process.env.PROJECT_ID = originalProjectId;
}
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export async function initializeLatestView({
datasetId: config.datasetId,
tableName: rawChangeLogTableName,
schema,
bqProjectId: bq.projectId,
useLegacyQuery: !config.useNewSnapshotQuerySyntax,
});

Expand Down
Loading