Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Borzenko committed Sep 16, 2024
1 parent ba393fb commit 11f3ea8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe("DatasetCommitService", () => {

let getDatasetInfoSpy: jasmine.Spy;
let navigationServiceSpy: jasmine.Spy;
let requestDatasetMainDataSpy: jasmine.Spy;

const TEST_ACCOUNT_NAME = "accountName";
const TEST_DATASET_NAME = "datasetName";
Expand All @@ -60,9 +59,6 @@ describe("DatasetCommitService", () => {
getDatasetInfoSpy = spyOn(datasetApi, "getDatasetInfoByAccountAndDatasetName").and.returnValue(
of(mockDatasetMainDataResponse as DatasetByAccountAndDatasetNameQuery),
);

requestDatasetMainDataSpy = spyOn(datasetService, "requestDatasetMainData").and.returnValue(of());

navigationServiceSpy = spyOn(navigationService, "navigateToDatasetView");
});

Expand Down Expand Up @@ -91,13 +87,6 @@ describe("DatasetCommitService", () => {
});
}

function expectRequestedDatasetMainData() {
expect(requestDatasetMainDataSpy).toHaveBeenCalledOnceWith({
accountName: TEST_ACCOUNT_NAME,
datasetName: TEST_DATASET_NAME,
});
}

it("should check getIdByAccountNameAndDatasetName() method with cache", fakeAsync(() => {
// 1st requests queries the API
let eventsCount = 0;
Expand Down Expand Up @@ -160,7 +149,6 @@ describe("DatasetCommitService", () => {
accountId: TEST_ACCOUNT_ID,
});
expectNavigatedToDatasetOverview();
expectRequestedDatasetMainData();
}));

[mockCommitEventToDatasetResultAppendError, mockCommitEventToDataseMetadataManifestMalformedError].forEach(
Expand All @@ -186,7 +174,6 @@ describe("DatasetCommitService", () => {
accountId: TEST_ACCOUNT_ID,
});
expect(navigationServiceSpy).not.toHaveBeenCalled();
expect(requestDatasetMainDataSpy).not.toHaveBeenCalled();

// If error triggered, our subscription will be closed
expect(errorSubscription$.closed).toBeTrue();
Expand Down Expand Up @@ -255,7 +242,6 @@ describe("DatasetCommitService", () => {
content: README_CONTENT,
});
expectNavigatedToDatasetOverview();
expectRequestedDatasetMainData();
}));

it("should check update readme for dataset when not found", () => {
Expand Down
13 changes: 0 additions & 13 deletions src/app/dataset-view/dataset.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,4 @@ describe("DatasetComponent", () => {
expect(component.sqlLoading).toEqual(true);
flush();
}));

it("should check init current hash for last block", fakeAsync(() => {
const MOCK_HEAD_BLOCK_HASH = "f16207c1039f6d9f5e107a2285ccfe04bc88cb65ddd2b217ceb62b717774b2f85f1f5";
const requestDatasetHeadBlockHashSpy = spyOn(datasetService, "requestDatasetHeadBlockHash").and.returnValue(
of(MOCK_HEAD_BLOCK_HASH),
);
component.ngOnInit();
tick();

expect(component.currentHeadBlockHash).toEqual(MOCK_HEAD_BLOCK_HASH);
expect(requestDatasetHeadBlockHashSpy).toHaveBeenCalledTimes(1);
flush();
}));
});
17 changes: 10 additions & 7 deletions src/app/dataset-view/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SetVocab,
} from "../api/kamu.graphql.interface";
import { DatasetInfo } from "../interface/navigation.interface";
import { inject, Injectable } from "@angular/core";
import { inject, Injectable, Injector } from "@angular/core";
import { combineLatest, Observable, of, Subject } from "rxjs";
import { DataRow, DatasetLineageNode, DatasetRequestBySql, DatasetSchema } from "../interface/dataset.interface";
import {
Expand Down Expand Up @@ -47,7 +47,7 @@ import { updateCacheHelper } from "../apollo-cache.helper";
export class DatasetService {
private datasetApi = inject(DatasetApi);
private datasetSubsService = inject(DatasetSubscriptionsService);
private apolloCache = inject(APOLLO_OPTIONS);
private injector = inject(Injector);
private currentSetVocab: SetVocab;
private currentHeadBlockHash: string;
private dataset$: Subject<DatasetBasicsFragment> = new Subject<DatasetBasicsFragment>();
Expand Down Expand Up @@ -113,11 +113,14 @@ export class DatasetService {
}

private updateCache(datasetBasics: DatasetBasicsFragment): void {
updateCacheHelper(this.apolloCache.cache, {
accountId: datasetBasics.owner.id,
datasetId: datasetBasics.id,
fieldNames: ["metadata", "data"],
});
const cache = this.injector.get(APOLLO_OPTIONS).cache;
if (cache) {
updateCacheHelper(cache, {
accountId: datasetBasics.owner.id,
datasetId: datasetBasics.id,
fieldNames: ["metadata", "data"],
});
}
}

public requestDatasetBasicDataWithPermissions(info: DatasetInfo): Observable<void> {
Expand Down

0 comments on commit 11f3ea8

Please sign in to comment.