Skip to content

Commit

Permalink
Changed Prettier setting: lines are 120-char wide, previously 80
Browse files Browse the repository at this point in the history
  • Loading branch information
zaychenko-sergei committed Aug 4, 2023
1 parent feb4044 commit 9f6a158
Show file tree
Hide file tree
Showing 288 changed files with 2,381 additions and 6,954 deletions.
6 changes: 5 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"printWidth": 120,
"overrides": [
{
"files": "*.test.ts",
Expand All @@ -9,7 +10,10 @@
}
},
{
"files": ["*.html", "**/*.ts"],
"files": [
"*.html",
"**/*.ts"
],
"options": {
"tabWidth": 4
}
Expand Down
4 changes: 1 addition & 3 deletions src/app/api/account.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { AccountDetailsFragment } from "./kamu.graphql.interface";

@Injectable({ providedIn: "root" })
export class AccountApi {
public getAccountInfoByName(
name: string,
): Observable<AccountDetailsFragment> {
public getAccountInfoByName(name: string): Observable<AccountDetailsFragment> {
return of({ ...mockAccountDetails, login: name });
}
}
61 changes: 20 additions & 41 deletions src/app/api/auth.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ import { NavigationService } from "src/app/services/navigation.service";
import { fakeAsync, TestBed, tick } from "@angular/core/testing";
import { Apollo } from "apollo-angular";
import { AuthApi } from "./auth.api";
import {
AccountDetailsFragment,
FetchAccountInfoDocument,
GithubLoginDocument,
} from "./kamu.graphql.interface";
import {
ApolloTestingController,
ApolloTestingModule,
} from "apollo-angular/testing";
import { AccountDetailsFragment, FetchAccountInfoDocument, GithubLoginDocument } from "./kamu.graphql.interface";
import { ApolloTestingController, ApolloTestingModule } from "apollo-angular/testing";
import {
mockGithubLoginResponse,
mockLogin401Error,
Expand Down Expand Up @@ -45,14 +38,10 @@ describe("AuthApi", () => {
});

function loginViaAccessToken(): void {
service
.fetchUserInfoFromAccessToken(TEST_ACCESS_TOKEN)
.subscribe(() => {
expect(service.isAuthenticated).toBeTrue();
expect(service.currentUser).toBe(
mockUserInfoFromAccessToken.auth.accountInfo,
);
});
service.fetchUserInfoFromAccessToken(TEST_ACCESS_TOKEN).subscribe(() => {
expect(service.isAuthenticated).toBeTrue();
expect(service.currentUser).toBe(mockUserInfoFromAccessToken.auth.accountInfo);
});

const op = controller.expectOne(FetchAccountInfoDocument);
expect(op.operation.variables.accessToken).toEqual(TEST_ACCESS_TOKEN);
Expand All @@ -63,18 +52,14 @@ describe("AuthApi", () => {
}

function loginFullyViaGithub(): void {
service
.fetchUserInfoAndTokenFromGithubCallackCode(TEST_GITHUB_CODE)
.subscribe(() => {
expect(service.isAuthenticated).toBeTrue();
expect(service.currentUser).toBe(
mockGithubLoginResponse.auth.githubLogin.accountInfo,
);
expect(localStorageSetItemSpy).toHaveBeenCalledWith(
AppValues.LOCAL_STORAGE_ACCESS_TOKEN,
mockGithubLoginResponse.auth.githubLogin.token.accessToken,
);
});
service.fetchUserInfoAndTokenFromGithubCallackCode(TEST_GITHUB_CODE).subscribe(() => {
expect(service.isAuthenticated).toBeTrue();
expect(service.currentUser).toBe(mockGithubLoginResponse.auth.githubLogin.accountInfo);
expect(localStorageSetItemSpy).toHaveBeenCalledWith(
AppValues.LOCAL_STORAGE_ACCESS_TOKEN,
mockGithubLoginResponse.auth.githubLogin.token.accessToken,
);
});

const op = controller.expectOne(GithubLoginDocument);
expect(op.operation.variables.code).toEqual(TEST_GITHUB_CODE);
Expand All @@ -100,12 +85,10 @@ describe("AuthApi", () => {

it("should check user changes via login with alive access token", fakeAsync(() => {
let callbackInvoked = false;
service.onUserChanges.subscribe(
(user: MaybeNull<AccountDetailsFragment>) => {
callbackInvoked = true;
user ? checkUserIsLogged(user) : fail("User must not be null");
},
);
service.onUserChanges.subscribe((user: MaybeNull<AccountDetailsFragment>) => {
callbackInvoked = true;
user ? checkUserIsLogged(user) : fail("User must not be null");
});

loginViaAccessToken();
tick();
Expand Down Expand Up @@ -133,9 +116,7 @@ describe("AuthApi", () => {
.subscribe(
() => fail("Unexpected success"),
(e: Error) => {
expect(e).toEqual(
new AuthenticationError([mockLogin401Error]),
);
expect(e).toEqual(new AuthenticationError([mockLogin401Error]));
},
);

Expand All @@ -155,9 +136,7 @@ describe("AuthApi", () => {
.subscribe(
() => fail("Unexpected success"),
(e: Error) => {
expect(e).toEqual(
new AuthenticationError([mockLogin401Error]),
);
expect(e).toEqual(new AuthenticationError([mockLogin401Error]));
},
);

Expand Down
12 changes: 3 additions & 9 deletions src/app/api/auth.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { AuthenticationError } from "../common/errors";
export class AuthApi {
private user: MaybeNull<AccountDetailsFragment> = null;

private userChanges$: Subject<MaybeNull<AccountDetailsFragment>> =
new Subject<MaybeNull<AccountDetailsFragment>>();
private userChanges$: Subject<MaybeNull<AccountDetailsFragment>> = new Subject<MaybeNull<AccountDetailsFragment>>();

constructor(
private githubLoginGQL: GithubLoginGQL,
Expand All @@ -47,17 +46,12 @@ export class AuthApi {
this.userChanges$.next(user);
}

public fetchUserInfoAndTokenFromGithubCallackCode(
code: string,
): Observable<void> {
public fetchUserInfoAndTokenFromGithubCallackCode(code: string): Observable<void> {
return this.githubLoginGQL.mutate({ code }).pipe(
map((result: MutationResult<GithubLoginMutation>) => {
if (result.data) {
const data: GithubLoginMutation = result.data;
localStorage.setItem(
AppValues.LOCAL_STORAGE_ACCESS_TOKEN,
data.auth.githubLogin.token.accessToken,
);
localStorage.setItem(AppValues.LOCAL_STORAGE_ACCESS_TOKEN, data.auth.githubLogin.token.accessToken);
this.changeUser(data.auth.githubLogin.accountInfo);
} else {
throw new AuthenticationError(result.errors ?? []);
Expand Down
70 changes: 23 additions & 47 deletions src/app/api/dataset.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
mockDatasetMainDataResponse,
} from "./../search/mock.data";
import { TestBed } from "@angular/core/testing";
import {
ApolloTestingController,
ApolloTestingModule,
} from "apollo-angular/testing";
import { ApolloTestingController, ApolloTestingModule } from "apollo-angular/testing";
import { DatasetApi } from "./dataset.api";
import {
CommitEventToDatasetDocument,
Expand Down Expand Up @@ -60,9 +57,7 @@ describe("DatasetApi", () => {
datasetName: TEST_DATASET_NAME,
})
.subscribe((res: GetDatasetMainDataQuery) => {
expect(res.datasets.byOwnerAndName?.name).toEqual(
"alberta.case-details",
);
expect(res.datasets.byOwnerAndName?.name).toEqual("alberta.case-details");
expect(res.datasets.byOwnerAndName?.id).toEqual(
"did:odf:z4k88e8rxU6m5wCnK9idM5sGAxAGfvUgNgQbckwJ4ro78tXMLSu",
);
Expand Down Expand Up @@ -91,9 +86,7 @@ describe("DatasetApi", () => {
actualQuery.__typename === "DataQueryResultSuccess" &&
expectedQuery.__typename === "DataQueryResultSuccess"
) {
expect(actualQuery.data.content).toEqual(
expectedQuery.data.content,
);
expect(actualQuery.data.content).toEqual(expectedQuery.data.content);
} else {
fail("expecting successful query");
}
Expand All @@ -117,12 +110,8 @@ describe("DatasetApi", () => {
numPage: 1,
})
.subscribe((res: GetDatasetHistoryQuery) => {
expect(
res.datasets.byOwnerAndName?.metadata.chain.blocks
.totalCount,
).toEqual(
mockDatasetHistoryResponse.datasets.byOwnerAndName?.metadata
.chain.blocks.totalCount,
expect(res.datasets.byOwnerAndName?.metadata.chain.blocks.totalCount).toEqual(
mockDatasetHistoryResponse.datasets.byOwnerAndName?.metadata.chain.blocks.totalCount,
);
});

Expand All @@ -136,18 +125,14 @@ describe("DatasetApi", () => {
});

it("should extract datasets by account name", () => {
service
.fetchDatasetsByAccountName(TEST_USER_NAME)
.subscribe((res: DatasetsByAccountNameQuery) => {
expect(res.datasets.byAccountName.totalCount).toEqual(
mockDatasetsByAccountNameQuery.datasets.byAccountName
.totalCount,
);
expect(res.datasets.byAccountName.nodes[0].name).toEqual(
mockDatasetsByAccountNameQuery.datasets.byAccountName
.nodes[0].name,
);
});
service.fetchDatasetsByAccountName(TEST_USER_NAME).subscribe((res: DatasetsByAccountNameQuery) => {
expect(res.datasets.byAccountName.totalCount).toEqual(
mockDatasetsByAccountNameQuery.datasets.byAccountName.totalCount,
);
expect(res.datasets.byAccountName.nodes[0].name).toEqual(
mockDatasetsByAccountNameQuery.datasets.byAccountName.nodes[0].name,
);
});

const op = controller.expectOne(DatasetsByAccountNameDocument);
expect(op.operation.variables.accountName).toEqual(TEST_USER_NAME);
Expand All @@ -158,24 +143,20 @@ describe("DatasetApi", () => {
});

it("should load block by hash", () => {
const blockByHash =
mockGetMetadataBlockQuery.datasets.byOwnerAndName?.metadata.chain
.blockByHash;
const blockByHash = mockGetMetadataBlockQuery.datasets.byOwnerAndName?.metadata.chain.blockByHash;
service
.getBlockByHash({
accountName: TEST_USER_NAME,
datasetName: TEST_DATASET_NAME,
blockHash: TEST_BLOCK_HASH,
})
.subscribe((res: GetMetadataBlockQuery) => {
expect(
res.datasets.byOwnerAndName?.metadata.chain.blockByHash
?.blockHash,
).toEqual(blockByHash?.blockHash);
expect(
res.datasets.byOwnerAndName?.metadata.chain.blockByHash
?.author.name,
).toEqual(blockByHash?.author.name);
expect(res.datasets.byOwnerAndName?.metadata.chain.blockByHash?.blockHash).toEqual(
blockByHash?.blockHash,
);
expect(res.datasets.byOwnerAndName?.metadata.chain.blockByHash?.author.name).toEqual(
blockByHash?.author.name,
);
});

const op = controller.expectOne(GetMetadataBlockDocument);
Expand All @@ -195,14 +176,9 @@ describe("DatasetApi", () => {
datasetId: mockDatasetId,
event: mockEvent,
})
.subscribe(
(res: CommitEventToDatasetMutation | null | undefined) => {
expect(
res?.datasets.byId?.metadata.chain.commitEvent
.__typename,
).toEqual("CommitResultSuccess");
},
);
.subscribe((res: CommitEventToDatasetMutation | null | undefined) => {
expect(res?.datasets.byId?.metadata.chain.commitEvent.__typename).toEqual("CommitResultSuccess");
});

const op = controller.expectOne(CommitEventToDatasetDocument);
expect(op.operation.variables.datasetId).toEqual(mockDatasetId);
Expand Down
Loading

0 comments on commit 9f6a158

Please sign in to comment.