Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavoyan committed May 29, 2024
1 parent 70778e5 commit e910015
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import NetworkService from "../../domain/infrastructure/network/NetworkService";
import CredentialTypeSchemaRepository from "../../domain/repositories/CredentialTypeSchemaRepository";
import { HttpMethod } from "../infrastructure/network/Request";
import Urls, { HeaderKeys, HeaderValues } from "./Urls";
import VCLCredentialTypes from "../../../api/entities/VCLCredentialTypes";

export default class CredentialTypeSchemaRepositoryImpl
implements CredentialTypeSchemaRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import VCLCountries from "../../../api/entities/VCLCountries";
import CountriesRepository from "../../domain/repositories/CountriesRepository";
import CountriesUseCase from "../../domain/usecases/CountriesModelUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class CountriesUseCaseImpl implements CountriesUseCase {
constructor(private readonly countriesRepository: CountriesRepository) {}
Expand All @@ -9,7 +10,7 @@ export default class CountriesUseCaseImpl implements CountriesUseCase {
try {
return await this.countriesRepository.getCountries();
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VCLCredentialTypesUIFormSchema from "../../../api/entities/VCLCredentialT
import VCLCredentialTypesUIFormSchemaDescriptor from "../../../api/entities/VCLCredentialTypesUIFormSchemaDescriptor";
import CredentialTypesUIFormSchemaRepository from "../../domain/repositories/CredentialTypesUIFormSchemaRepository";
import CredentialTypesUIFormSchemaUseCase from "../../domain/usecases/CredentialTypesUIFormSchemaUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class CredentialTypesUIFormSchemaUseCaseImpl
implements CredentialTypesUIFormSchemaUseCase
Expand All @@ -21,7 +22,7 @@ export default class CredentialTypesUIFormSchemaUseCaseImpl
countries
);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import VCLExchange from "../../../api/entities/VCLExchange";
import VCLExchangeDescriptor from "../../../api/entities/VCLExchangeDescriptor";
import ExchangeProgressRepository from "../../domain/repositories/ExchangeProgressRepository";
import ExchangeProgressUseCase from "../../domain/usecases/ExchangeProgressUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseCase {
constructor(private exchangeProgressRepository: ExchangeProgressRepository) {
Expand All @@ -13,7 +14,7 @@ export default class ExchangeProgressUseCaseImpl implements ExchangeProgressUseC
try {
return await this.exchangeProgressRepository.getExchangeProgress(exchangeDescriptor);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import VCLToken from "../../../api/entities/VCLToken";
import FinalizeOffersRepository from "../../domain/repositories/FinalizeOffersRepository";
import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository";
import FinalizeOffersUseCase from "../../domain/usecases/FinalizeOffersUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class FinalizeOffersUseCaseImpl
implements FinalizeOffersUseCase {
Expand Down Expand Up @@ -38,7 +39,7 @@ export default class FinalizeOffersUseCaseImpl
}
return new VCLJwtVerifiableCredentials(passedCredentials, failedCredentials);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VCLOffers from "../../../api/entities/VCLOffers";
import VCLToken from "../../../api/entities/VCLToken";
import GenerateOffersRepository from "../../domain/repositories/GenerateOffersRepository";
import GenerateOffersUseCase from "../../domain/usecases/GenerateOffersUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class GenerateOffersUseCaseImpl
implements GenerateOffersUseCase
Expand All @@ -16,7 +17,7 @@ export default class GenerateOffersUseCaseImpl
try {
return await this.generateOffersRepository.generateOffers(generateOffersDescriptor, sessionToken);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
3 changes: 2 additions & 1 deletion packages/sdk/src/impl/data/usecases/JwtServiceUseCaseImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository
import JwtServiceUseCase from "../../domain/usecases/JwtServiceUseCase";
import { Nullish } from "../../../api/VCLTypes";
import VCLToken from "../../../api/entities/VCLToken";
import VCLError from "../../../api/entities/error/VCLError";

export default class JwtServiceUseCaseImpl implements JwtServiceUseCase {
constructor(private readonly jwtServiceRepository: JwtServiceRepository) {}
Expand All @@ -18,7 +19,7 @@ export default class JwtServiceUseCaseImpl implements JwtServiceUseCase {
try {
return await this.jwtServiceRepository.verifyJwt(jwt, publicJwk, remoteCryptoServicesToken);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/impl/data/usecases/KeyServiceUseCaseImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import VCLDidJwk from "../../../api/entities/VCLDidJwk";
import VCLDidJwkDescriptor from "../../../api/entities/VCLDidJwkDescriptor";
import KeyServiceRepository from "../../domain/repositories/KeyServiceRepository";
import KeyServiceUseCase from "../../domain/usecases/KeyServiceUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class KeyServiceUseCaseImpl implements KeyServiceUseCase {
constructor(private readonly keyServiceRepository: KeyServiceRepository) {}
Expand All @@ -11,7 +12,7 @@ export default class KeyServiceUseCaseImpl implements KeyServiceUseCase {
try {
return await this.keyServiceRepository.generateDidJwk(didJwkDescriptor);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import VCLOrganizations from "../../../api/entities/VCLOrganizations";
import VCLOrganizationsSearchDescriptor from "../../../api/entities/VCLOrganizationsSearchDescriptor";
import OrganizationsRepository from "../../domain/repositories/OrganizationsRepository";
import OrganizationsUseCase from "../../domain/usecases/OrganizationsUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class OrganizationsUseCaseImpl implements OrganizationsUseCase {
constructor(private organizationsRepository: OrganizationsRepository) {}
Expand All @@ -12,7 +13,7 @@ export default class OrganizationsUseCaseImpl implements OrganizationsUseCase {
try {
return await this.organizationsRepository.searchForOrganizations(organizationsSearchDescriptor);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class PresentationRequestUseCaseImpl
),
);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/impl/data/usecases/SubmissionUseCaseImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import VCLSubmissionResult from "../../../api/entities/VCLSubmissionResult";
import JwtServiceRepository from "../../domain/repositories/JwtServiceRepository";
import SubmissionRepository from "../../domain/repositories/SubmissionRepository";
import SubmissionUseCase from "../../domain/usecases/SubmissionUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class SubmissionUseCaseImpl implements SubmissionUseCase {
constructor(
Expand All @@ -28,7 +29,7 @@ export default class SubmissionUseCaseImpl implements SubmissionUseCase {
);
return await this.submissionRepository.submit(submission, jwt);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import VCLVerifiedProfileDescriptor from "../../../api/entities/VCLVerifiedProfileDescriptor";
import VerifiedProfileRepository from "../../domain/repositories/VerifiedProfileRepository";
import VerifiedProfileUseCase from "../../domain/usecases/VerifiedProfileUseCase";
import VCLError from "../../../api/entities/error/VCLError";

export default class VerifiedProfileUseCaseImpl
implements VerifiedProfileUseCase {
Expand All @@ -13,7 +14,7 @@ export default class VerifiedProfileUseCaseImpl
try {
return await this.verifiedProfileRepository.getVerifiedProfile(verifiedProfileDescriptor);
} catch (error: any) {
throw new Error(error);
throw new VCLError(error);
}
}
}
3 changes: 2 additions & 1 deletion packages/sdk/test/usecases/CredentialManifestUseCase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ describe("CredentialManifestUseCase Tests", () => {
),
new VCLVerifiedProfile(JSON.parse(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1))
);
expect(true).toBe(false);
} catch (error: any) {
expect(error?.errorCode).toBe(VCLErrorCode.SdkError);
expect(error?.errorCode).toBe(VCLErrorCode.SdkError.toString());
}
});
});
18 changes: 9 additions & 9 deletions packages/sdk/test/usecases/ExchangeProgressUseCase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import NetworkServiceSuccess from "../NetworkServiceSuccess";
import ExchangeProgressRepositoryImpl from "../../src/impl/data/repositories/ExchangeProgressRepositoryImpl";
import ExchangeProgressUseCaseImpl from "../../src/impl/data/usecases/ExchangeProgressUseCaseImpl";
import { ExchangeProgressMocks } from "../infrastructure/resources/valid/ExchangeProgressMocks";
import { Dictionary, VCLErrorCode, VCLExchange, VCLExchangeDescriptor, VCLToken } from "../../src";
import { mock } from "node:test";
import { beforeAll, expect } from "@jest/globals";
import { Dictionary, VCLExchange, VCLExchangeDescriptor, VCLToken } from "../../src";
import { expect } from "@jest/globals";

describe("ExchangeProgressUseCase Tests", () => {
const subject1 = new ExchangeProgressUseCaseImpl(
Expand All @@ -14,7 +13,7 @@ describe("ExchangeProgressUseCase Tests", () => {
)
const subject2 = new ExchangeProgressUseCaseImpl(
new ExchangeProgressRepositoryImpl(
new NetworkServiceSuccess({ wrong: 'payload' })
new NetworkServiceSuccess('')
)
)
const exchangeDescriptor = {
Expand All @@ -30,11 +29,12 @@ describe("ExchangeProgressUseCase Tests", () => {
});

test("testGetExchangeProgressFailure", async () => {
try {
await subject1.getExchangeProgress(exchangeDescriptor)
} catch (error: any) {
expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString())
}
const exchange = await subject2.getExchangeProgress(exchangeDescriptor)

expect(exchange.id).toBe(undefined)
expect(exchange.type).toBe(undefined)
expect(exchange.disclosureComplete).toBe(undefined)
expect(exchange.exchangeComplete).toBe(undefined)
});

const expectedExchange = (exchangeJsonObj: Dictionary<any>): VCLExchange => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ describe("PresentationRequestUseCase Tests", () => {
),
new VCLVerifiedProfile({})
);
expect(true).toBe(false);
} catch (error: any) {
expect(error.errorCode).toBe(VCLErrorCode.SdkError);
expect(error.errorCode).toBe(VCLErrorCode.SdkError.toString());
}
});
});

0 comments on commit e910015

Please sign in to comment.