diff --git a/packages/client-node/integration/LegalOfficer.ts b/packages/client-node/integration/LegalOfficer.ts index f34eec2..ed52820 100644 --- a/packages/client-node/integration/LegalOfficer.ts +++ b/packages/client-node/integration/LegalOfficer.ts @@ -43,8 +43,8 @@ export async function updateLegalOfficer(state: State) { additionalDetails: "Some new details", } as LegalOfficer; const aliceClient = client.withCurrentAccount(alice.account); - await aliceClient.directoryClient.createOrUpdate(updatedAlice); - const legalOfficers = await client.directoryClient.getLegalOfficers(); + await aliceClient.legalOfficerClient.createOrUpdate(updatedAlice); + const legalOfficers = await client.legalOfficerClient.getLegalOfficers(); const legalOfficer = legalOfficers.find(legalOfficer => legalOfficer.account.equals(alice.account)) expect(legalOfficer?.userIdentity).toEqual(updatedAlice.userIdentity); expect(legalOfficer?.postalAddress).toEqual(updatedAlice.postalAddress); diff --git a/packages/client/src/ComponentFactory.ts b/packages/client/src/ComponentFactory.ts index 84afcae..3034734 100644 --- a/packages/client/src/ComponentFactory.ts +++ b/packages/client/src/ComponentFactory.ts @@ -1,7 +1,7 @@ import { LogionNodeApiClass, Hash } from "@logion/node-api"; import { AuthenticationClient } from "./AuthenticationClient.js"; import { AxiosFactory } from "./AxiosFactory.js"; -import { DirectoryClient } from "./DirectoryClient.js"; +import { LegalOfficerClient } from "./LegalOfficerClient.js"; import { NetworkState } from "./NetworkState.js"; import { LegalOfficerEndpoint } from "./SharedClient.js"; import { LegalOfficerClass } from "./Types.js"; @@ -83,7 +83,7 @@ export abstract class AxiosFileUploader implements FileUploader { export interface CoreComponentFactory { buildAxiosFactory: () => AxiosFactory; - buildDirectoryClient: (api: LogionNodeApiClass, axiosFactory: AxiosFactory, token?: string) => DirectoryClient; + buildLegalOfficerClient: (api: LogionNodeApiClass, axiosFactory: AxiosFactory, token?: string) => LegalOfficerClient; buildAuthenticationClient: (api: LogionNodeApiClass, legalOfficers: LegalOfficerClass[]) => AuthenticationClient; buildNetworkState(nodesUp: LegalOfficerEndpoint[], nodesDown: LegalOfficerEndpoint[]): NetworkState; buildNodeApi(rpcEndpoints: string[]): Promise; @@ -91,7 +91,7 @@ export interface CoreComponentFactory { export const CoreComponentFactoryInstance: CoreComponentFactory = { buildAxiosFactory: () => new AxiosFactory(), - buildDirectoryClient: (api: LogionNodeApiClass, axiosFactory: AxiosFactory, token?: string) => new DirectoryClient(api, axiosFactory, token), + buildLegalOfficerClient: (api: LogionNodeApiClass, axiosFactory: AxiosFactory, token?: string) => new LegalOfficerClient(api, axiosFactory, token), buildAuthenticationClient: (api: LogionNodeApiClass, legalOfficers: LegalOfficerClass[]) => new AuthenticationClient(api, legalOfficers), buildNetworkState: (nodesUp: LegalOfficerEndpoint[], nodesDown: LegalOfficerEndpoint[]) => new NetworkState(nodesUp, nodesDown), buildNodeApi: (rpcEndpoints: string[]) => LogionNodeApiClass.connect(rpcEndpoints), diff --git a/packages/client/src/DirectoryClient.ts b/packages/client/src/LegalOfficerClient.ts similarity index 94% rename from packages/client/src/DirectoryClient.ts rename to packages/client/src/LegalOfficerClient.ts index b8dbd1e..51a5931 100644 --- a/packages/client/src/DirectoryClient.ts +++ b/packages/client/src/LegalOfficerClient.ts @@ -9,7 +9,7 @@ import { LegalOfficer, LegalOfficerClass, LegalOfficerPostalAddress, UserIdentit import { MultiSourceHttpClient, aggregateArrays, Endpoint, MultiSourceHttpClientState } from "./Http.js"; import { newBackendError } from "./Error.js"; -export interface DirectoryLegalOfficer { +interface BackendLegalOfficer { userIdentity: UserIdentity; postalAddress: LegalOfficerPostalAddress; address: string; @@ -23,7 +23,7 @@ export interface CreateOrUpdateLegalOfficer { additionalDetails: string; } -export class DirectoryClient { +export class LegalOfficerClient { constructor(api: LogionNodeApiClass, axiosFactory: AxiosFactory, token?: string) { this.authenticated = token !== undefined; @@ -56,7 +56,7 @@ export class DirectoryClient { onchainMap: Record ): Promise { const offchain = (await axios.get("/api/legal-officer") - .then(response => response.data.legalOfficers)) as DirectoryLegalOfficer[]; + .then(response => response.data.legalOfficers)) as BackendLegalOfficer[]; const offchainMap = this.toOffchainMap(offchain); const legalOfficers = []; for(const address in offchainMap) { @@ -72,14 +72,15 @@ export class DirectoryClient { legalOfficers.push(new LegalOfficerClass({ legalOfficer, axiosFactory: this.axiosFactory, + token: this.token, })); } } return legalOfficers; } - private toOffchainMap(array: DirectoryLegalOfficer[]): Record { - const map: Record = {}; + private toOffchainMap(array: BackendLegalOfficer[]): Record { + const map: Record = {}; array.forEach(item => { map[item.address] = item; }); return map; } diff --git a/packages/client/src/LogionClient.ts b/packages/client/src/LogionClient.ts index bbd0972..c367188 100644 --- a/packages/client/src/LogionClient.ts +++ b/packages/client/src/LogionClient.ts @@ -5,7 +5,7 @@ import { LogionNodeApiClass, UUID, ValidAccountId } from "@logion/node-api"; import { AccountTokens } from "./AuthenticationClient.js"; import { BalanceState, getBalanceState } from "./Balance.js"; import { ComponentFactory, buildComponentFactory } from "./ComponentFactory.js"; -import { DirectoryClient } from "./DirectoryClient.js"; +import { LegalOfficerClient } from "./LegalOfficerClient.js"; import { initMultiSourceHttpClientState, MultiSourceHttpClient, Token } from "./Http.js"; import { getInitialState, ProtectionState } from "./AccountRecovery.js"; import { AccountRecoveryClient } from "./AccountRecoveryClient.js"; @@ -45,18 +45,18 @@ export class LogionClient { const componentFactory = getComponentFactory(config); const axiosFactory = componentFactory.buildAxiosFactory(); const nodeApi = await componentFactory.buildNodeApi(config.rpcEndpoints); - const directoryClient = componentFactory.buildDirectoryClient( + const legalOfficerClient = componentFactory.buildLegalOfficerClient( nodeApi, axiosFactory, ); - const allLegalOfficers = await directoryClient.getLegalOfficers(); + const allLegalOfficers = await legalOfficerClient.getLegalOfficers(); const legalOfficers = allLegalOfficers.filter(legalOfficer => legalOfficer.node); const nodesUp: LegalOfficerEndpoint[] = legalOfficers.map(legalOfficer => ({ url: legalOfficer.node, legalOfficer: legalOfficer.account.address })); const sharedState: SharedState = { config, componentFactory, axiosFactory, - directoryClient, + legalOfficerClient, nodeApi, legalOfficers, allLegalOfficers, @@ -122,8 +122,8 @@ export class LogionClient { /** * An instance of Directory client. */ - get directoryClient(): DirectoryClient { - return this.sharedState.directoryClient; + get legalOfficerClient(): LegalOfficerClient { + return this.sharedState.legalOfficerClient; } /** @@ -216,15 +216,15 @@ export class LogionClient { */ withCurrentAccount(currentAccount?: ValidAccountId): LogionClient { this.ensureConnected(); - let directoryClient: DirectoryClient; + let legalOfficerClient: LegalOfficerClient; if(currentAccount !== undefined) { - directoryClient = this.sharedState.componentFactory.buildDirectoryClient( + legalOfficerClient = this.sharedState.componentFactory.buildLegalOfficerClient( this.sharedState.nodeApi, this.sharedState.axiosFactory, this.sharedState.tokens.get(currentAccount)?.value, ); } else { - directoryClient = this.sharedState.componentFactory.buildDirectoryClient( + legalOfficerClient = this.sharedState.componentFactory.buildLegalOfficerClient( this.sharedState.nodeApi, this.sharedState.axiosFactory, ); @@ -234,7 +234,7 @@ export class LogionClient { return new LogionClient({ ...sharedState, currentAccount, - directoryClient, + legalOfficerClient, }); } @@ -244,7 +244,7 @@ export class LogionClient { */ logout(): LogionClient { this.ensureConnected(); - const directoryClient = this.sharedState.componentFactory.buildDirectoryClient( + const legalOfficerClient = this.sharedState.componentFactory.buildLegalOfficerClient( this.sharedState.nodeApi, this.sharedState.axiosFactory ); @@ -252,7 +252,7 @@ export class LogionClient { ...this.sharedState, tokens: new AccountTokens(this.sharedState.nodeApi, {}), currentAccount: undefined, - directoryClient, + legalOfficerClient, }); } diff --git a/packages/client/src/SharedClient.ts b/packages/client/src/SharedClient.ts index 38e4baa..a1208c2 100644 --- a/packages/client/src/SharedClient.ts +++ b/packages/client/src/SharedClient.ts @@ -4,7 +4,7 @@ import { AccountTokens } from "./AuthenticationClient.js"; import { AxiosFactory } from "./AxiosFactory.js"; import { findOrThrow } from "./Collections.js"; import { ComponentFactory, FileUploader } from "./ComponentFactory.js"; -import { DirectoryClient } from "./DirectoryClient.js"; +import { LegalOfficerClient } from "./LegalOfficerClient.js"; import { Endpoint, Token } from "./Http.js"; import { NetworkState } from "./NetworkState.js"; import { LegalOfficerClass } from "./Types.js"; @@ -25,7 +25,7 @@ export interface SharedState { config: LogionClientConfig; componentFactory: ComponentFactory; axiosFactory: AxiosFactory; - directoryClient: DirectoryClient; + legalOfficerClient: LegalOfficerClient; networkState: NetworkState; nodeApi: LogionNodeApiClass; legalOfficers: LegalOfficerClass[]; diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 8c1da6b..97358d2 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -19,7 +19,7 @@ export * from './Balance.js'; export * from './CollectionItem.js'; export * from './ComponentFactory.js'; export * from './DateTimeUtil.js'; -export * from './DirectoryClient.js'; +export * from './LegalOfficerClient.js'; export * from './Environment.js'; export * from './Ethereum.js'; export * from './Hash.js'; diff --git a/packages/client/test/AccountRecovery.spec.ts b/packages/client/test/AccountRecovery.spec.ts index d24c4c8..c6a57f6 100644 --- a/packages/client/test/AccountRecovery.spec.ts +++ b/packages/client/test/AccountRecovery.spec.ts @@ -168,7 +168,7 @@ async function buildSharedState(): Promise { (factory: TestConfigFactory) => { factory.setupDefaultAxiosInstanceFactory(); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); }, currentAccount, @@ -284,7 +284,7 @@ describe("NoProtection", () => { setupFetchProtectionRequests(bobAxios, [], [], []); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); nodeApi.setup(instance => instance.queries.getRecoveryConfig(currentAccount)) @@ -339,7 +339,7 @@ describe("NoProtection", () => { const sharedState = await buildTestAuthenticatedSharedSate( (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); nodeApi.setup(instance => instance.queries.getActiveRecovery(RECOVERED_ADDRESS, currentAccount)) @@ -453,7 +453,7 @@ describe("PendingRecovery", () => { setupFetchProtectionRequests(bobAxios, [ bobRequest ], [], []); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); nodeApi.setup(instance => instance.queries.getRecoveryConfig(currentAccount)) @@ -506,7 +506,7 @@ describe("PendingRecovery", () => { setupFetchProtectionRequests(bobAxios, [], [ bobRequest ], []); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); nodeApi.setup(instance => instance.queries.getRecoveryConfig(currentAccount)) @@ -594,7 +594,7 @@ describe("AcceptedProtection", () => { setupFetchProtectionRequests(bobAxios, [], [ bobRequest ], []); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); nodeApi.setup(instance => instance.queries.getRecoveryConfig(currentAccount)) @@ -662,7 +662,7 @@ describe("PendingRecovery", () => { setupFetchProtectionRequests(bobAxios, [], [ bobRequest ], []); factory.setupDefaultNetworkState(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); const recoveryConfig = { diff --git a/packages/client/test/Balance.spec.ts b/packages/client/test/Balance.spec.ts index 2b364be..d14dc95 100644 --- a/packages/client/test/Balance.spec.ts +++ b/packages/client/test/Balance.spec.ts @@ -22,9 +22,9 @@ describe("Balance", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); nodeApi.setup(instance => instance.queries.getAccountData(REQUESTER_ADDRESS)) .returns(Promise.resolve(BALANCE)); @@ -73,11 +73,11 @@ describe("Balance", () => { const axiosFactory = testConfigFactory.setupAxiosFactoryMock(); testConfigFactory.setupDefaultNetworkState(); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); setupFetchTransactions(axiosFactory, transactions, REQUESTER_ADDRESS.address) - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ new LegalOfficerClass({ + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ new LegalOfficerClass({ legalOfficer: ALICE, axiosFactory: axiosFactory.object(), }) ])); @@ -132,9 +132,9 @@ describe("Balance", () => { const axiosFactory = testConfigFactory.setupAxiosFactoryMock(); testConfigFactory.setupDefaultNetworkState(); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); nodeApi.setup(instance => instance.queries.getAccountData(REQUESTER_ADDRESS)) .returns(Promise.resolve(BALANCE)); @@ -201,9 +201,9 @@ describe("Balance", () => { const axiosFactory = testConfigFactory.setupAxiosFactoryMock(); testConfigFactory.setupDefaultNetworkState(); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); nodeApi.setup(instance => instance.queries.getAccountData(REQUESTER_ADDRESS)) .returns(Promise.resolve(BALANCE)); @@ -279,9 +279,9 @@ describe("Balance", () => { const axiosFactory = testConfigFactory.setupAxiosFactoryMock(); testConfigFactory.setupDefaultNetworkState(); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([])); nodeApi.setup(instance => instance.queries.getAccountData(REQUESTER_ADDRESS)) .returns(Promise.resolve(BALANCE)); diff --git a/packages/client/test/DirectoryClient.spec.ts b/packages/client/test/DirectoryClient.spec.ts index e9201ed..926e565 100644 --- a/packages/client/test/DirectoryClient.spec.ts +++ b/packages/client/test/DirectoryClient.spec.ts @@ -4,15 +4,15 @@ import { Mock } from "moq.ts"; import { AccountId32 } from "@polkadot/types/interfaces/types.js"; import type { Bytes } from '@polkadot/types-codec'; import { PalletLoAuthorityListLegalOfficerData, PalletLoAuthorityListHostData, PalletLoAuthorityListGuestData, LogionRuntimeRegion } from "@polkadot/types/lookup"; -import { AxiosFactory, DirectoryClient, DirectoryLegalOfficer } from "../src/index.js"; +import { AxiosFactory, LegalOfficerClient } from "../src/index.js"; import { EMPTY_POSTAL_ADDRESS, EMPTY_USER_IDENTITY, mockCodecWithToString, mockCodecWithToUtf8, mockOption, mockStorageKey } from "./Utils.js"; -describe("DirectoryClient", () => { +describe("LegalOfficerClient", () => { it("handles guest LLOs", async () => { const api = mockApi(); const axiosFactory = mockAxiosFactory(); - const client = new DirectoryClient(api, axiosFactory); + const client = new LegalOfficerClient(api, axiosFactory); const legalOfficers = await client.getLegalOfficers(); @@ -72,7 +72,7 @@ function mockAxiosFactory(): AxiosFactory { function mockAxios(addresses: string[]): AxiosInstance { const axios = new Mock(); const response = new Mock(); - const legalOfficers: DirectoryLegalOfficer[] = addresses.map(address => ( { + const legalOfficers = addresses.map(address => ( { address, additionalDetails: "", postalAddress: EMPTY_POSTAL_ADDRESS, diff --git a/packages/client/test/Loc.spec.ts b/packages/client/test/Loc.spec.ts index 6516cac..cf6494a 100644 --- a/packages/client/test/Loc.spec.ts +++ b/packages/client/test/Loc.spec.ts @@ -1002,7 +1002,7 @@ async function buildSharedState(isVerifiedIssuer: boolean = false): Promise { factory.setupDefaultNetworkState(); factory.setupFileUploaderMock(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const axiosFactoryMock = factory.setupAxiosFactoryMock(); uploaderMock = factory.setupFileUploaderMock(); diff --git a/packages/client/test/LogionClient.spec.ts b/packages/client/test/LogionClient.spec.ts index 6d0e1ac..3c89a1c 100644 --- a/packages/client/test/LogionClient.spec.ts +++ b/packages/client/test/LogionClient.spec.ts @@ -29,8 +29,8 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()) + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); + legalOfficerClient.setup(instance => instance.getLegalOfficers()) .returns(Promise.resolve(testConfigFactory.buildLegalOfficerClasses(clientLegalOfficers))); }); const client = await LogionClient.create(config); @@ -49,10 +49,10 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); api = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()) + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); + legalOfficerClient.setup(instance => instance.getLegalOfficers()) .returns(Promise.resolve(testConfigFactory.buildLegalOfficerClasses(clientLegalOfficers))); - testConfigFactory.setupAuthenticatedDirectoryClientMock(token); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(token); }); const client = await LogionClient.create(config); @@ -74,16 +74,16 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultNetworkState(); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); const legalOfficerClasses = testConfigFactory.buildLegalOfficerClasses(clientLegalOfficers); - directoryClient.setup(instance => instance.getLegalOfficers()) + legalOfficerClient.setup(instance => instance.getLegalOfficers()) .returns(Promise.resolve(legalOfficerClasses)); const authenticationClient = testConfigFactory.setupAuthenticationClientMock(clientLegalOfficers); authenticationClient.setup(instance => instance.authenticate(addresses, signer.object())) .returns(Promise.resolve(tokens)); - testConfigFactory.setupAuthenticatedDirectoryClientMock(token); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(token); }); const client = await LogionClient.create(config); @@ -103,7 +103,7 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - testConfigFactory.setupAuthenticatedDirectoryClientMock(tokens.get(alice)!.value); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(tokens.get(alice)!.value); authenticationClient = testConfigFactory.setupAuthenticationClientMock(legalOfficers); authenticationClient.setup(instance => instance.refresh(tokens)).returns(Promise.resolve(tokens)); }, alice, legalOfficers, tokens); @@ -123,7 +123,7 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - testConfigFactory.setupAuthenticatedDirectoryClientMock(tokens.get(alice)!.value); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(tokens.get(alice)!.value); authenticationClient = testConfigFactory.setupAuthenticationClientMock(legalOfficers); authenticationClient.setup(instance => instance.refresh(tokens)).returns(Promise.resolve(tokens)); }, alice, legalOfficers, tokens); @@ -143,9 +143,9 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultNetworkState(); const api = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); const alice = ALICE.account; - testConfigFactory.setupAuthenticatedDirectoryClientMock(tokens.get(alice)!.value); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(tokens.get(alice)!.value); const bob = BOB.account; - testConfigFactory.setupAuthenticatedDirectoryClientMock(tokens.get(bob)!.value); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(tokens.get(bob)!.value); const config = testConfigFactory.buildTestConfig(LOGION_CLIENT_CONFIG); const sharedState = await buildAuthenticatedSharedStateUsingTestConfig(config, alice, legalOfficers, tokens); @@ -154,7 +154,7 @@ describe("LogionClient", () => { const bobClient = aliceClient.withCurrentAccount(bob); expect(bobClient.currentAccount).toBe(bob); - testConfigFactory.verifyComponentFactory(instance => instance.buildDirectoryClient(api.object(), It.IsAny(), tokens.get(bob)!.value)); + testConfigFactory.verifyComponentFactory(instance => instance.buildLegalOfficerClient(api.object(), It.IsAny(), tokens.get(bob)!.value)); }); it("logs out", async () => { @@ -166,7 +166,7 @@ describe("LogionClient", () => { testConfigFactory.setupDefaultAxiosInstanceFactory(); testConfigFactory.setupDefaultNetworkState(); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - testConfigFactory.setupAuthenticatedDirectoryClientMock(tokens.get(alice)!.value); + testConfigFactory.setupAuthenticatedLegalOfficerClientMock(tokens.get(alice)!.value); testConfigFactory.setupAuthenticationClientMock(legalOfficers); }, alice, legalOfficers, tokens); const authenticatedClient = new LogionClient({ ...sharedState }); diff --git a/packages/client/test/Public.spec.ts b/packages/client/test/Public.spec.ts index 7ebb563..81a83d7 100644 --- a/packages/client/test/Public.spec.ts +++ b/packages/client/test/Public.spec.ts @@ -176,7 +176,7 @@ async function buildSharedState(): Promise { (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); factory.setupFileUploaderMock(); - factory.setupDirectoryClientMock(); + factory.setupLegalOfficerClientMock(); const axiosFactoryMock = factory.setupAxiosFactoryMock(); diff --git a/packages/client/test/RecoveryReview.spec.ts b/packages/client/test/RecoveryReview.spec.ts index 3a750c8..09e27ab 100644 --- a/packages/client/test/RecoveryReview.spec.ts +++ b/packages/client/test/RecoveryReview.spec.ts @@ -72,8 +72,8 @@ function setupConfig(axios: Mock): LogionClientConfig { .returns(axios.object()); setupBackend(axios); testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ new LegalOfficerClass({ legalOfficer: ALICE, axiosFactory: axiosFactory.object(), diff --git a/packages/client/test/SecretRecovery.spec.ts b/packages/client/test/SecretRecovery.spec.ts index 1bb38c3..2193425 100644 --- a/packages/client/test/SecretRecovery.spec.ts +++ b/packages/client/test/SecretRecovery.spec.ts @@ -50,9 +50,9 @@ function configure() { axiosFactory.setup(instance => instance.buildAxiosInstance(It.IsAny(), It.IsAny())) .returns(axios.object()); const nodeApi = testConfigFactory.setupNodeApiMock(LOGION_CLIENT_CONFIG); - const directoryClient = testConfigFactory.setupDirectoryClientMock(); + const legalOfficerClient = testConfigFactory.setupLegalOfficerClientMock(); - directoryClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ + legalOfficerClient.setup(instance => instance.getLegalOfficers()).returns(Promise.resolve([ new LegalOfficerClass({ legalOfficer: ALICE, axiosFactory: axiosFactory.object(), diff --git a/packages/client/test/TestConfigFactory.ts b/packages/client/test/TestConfigFactory.ts index 37dcc82..247dca4 100644 --- a/packages/client/test/TestConfigFactory.ts +++ b/packages/client/test/TestConfigFactory.ts @@ -5,7 +5,7 @@ import { AuthenticationClient, AxiosFactory, ComponentFactory, - DirectoryClient, + LegalOfficerClient, LogionClientConfig, LegalOfficer, LegalOfficerClass, @@ -42,18 +42,18 @@ export class TestConfigFactory { return nodeApi; } - setupDirectoryClientMock(): Mock { - const directoryClient = new Mock(); - this._componentFactory.setup(instance => instance.buildDirectoryClient(It.IsAny(), It.IsAny())) - .returns(directoryClient.object()); - return directoryClient; + setupLegalOfficerClientMock(): Mock { + const legalOfficerClient = new Mock(); + this._componentFactory.setup(instance => instance.buildLegalOfficerClient(It.IsAny(), It.IsAny())) + .returns(legalOfficerClient.object()); + return legalOfficerClient; } - setupAuthenticatedDirectoryClientMock(token: string): Mock { - const directoryClient = new Mock(); - this._componentFactory.setup(instance => instance.buildDirectoryClient(It.IsAny(), It.IsAny(), token)) - .returns(directoryClient.object()); - return directoryClient; + setupAuthenticatedLegalOfficerClientMock(token: string): Mock { + const legalOfficerClient = new Mock(); + this._componentFactory.setup(instance => instance.buildLegalOfficerClient(It.IsAny(), It.IsAny(), token)) + .returns(legalOfficerClient.object()); + return legalOfficerClient; } setupAuthenticationClientMock(legalOfficers: LegalOfficer[]): Mock { diff --git a/packages/client/test/Utils.ts b/packages/client/test/Utils.ts index 9f4f3a7..83ba677 100644 --- a/packages/client/test/Utils.ts +++ b/packages/client/test/Utils.ts @@ -114,7 +114,7 @@ export async function buildAuthenticatedSharedStateUsingTestConfig( ): Promise { const componentFactory = (config as any).__componentFactory; const axiosFactory = componentFactory.buildAxiosFactory(); - const directoryClient = componentFactory.buildDirectoryClient(axiosFactory); + const legalOfficerClient = componentFactory.buildLegalOfficerClient(axiosFactory); const nodesUp: LegalOfficerEndpoint[] = legalOfficers.map(legalOfficer => ({ url: legalOfficer.node, legalOfficer: legalOfficer.account.address })); const networkState = componentFactory.buildNetworkState(nodesUp, []); const nodeApi = await componentFactory.buildNodeApi(config.rpcEndpoints); @@ -127,7 +127,7 @@ export async function buildAuthenticatedSharedStateUsingTestConfig( config, componentFactory, axiosFactory, - directoryClient, + legalOfficerClient, networkState, nodeApi, currentAccount: currentAccount, diff --git a/packages/client/test/Vault.spec.ts b/packages/client/test/Vault.spec.ts index 719df2c..83db243 100644 --- a/packages/client/test/Vault.spec.ts +++ b/packages/client/test/Vault.spec.ts @@ -80,7 +80,7 @@ describe("Vault", () => { const sharedState = await buildTestAuthenticatedSharedSate( (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); - factory.setupDirectoryClientMock(); + factory.setupLegalOfficerClientMock(); factory.setupAxiosFactoryMock(); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); @@ -156,7 +156,7 @@ describe("Vault", () => { const sharedState = await buildTestAuthenticatedSharedSate( (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); - factory.setupDirectoryClientMock(); + factory.setupLegalOfficerClientMock(); factory.setupAxiosFactoryMock(); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); @@ -233,7 +233,7 @@ describe("Vault", () => { const sharedState = await buildTestAuthenticatedSharedSate( (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); - factory.setupDirectoryClientMock(); + factory.setupLegalOfficerClientMock(); factory.setupAxiosFactoryMock(); factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); }, @@ -302,7 +302,7 @@ describe("Vault", () => { const sharedState = await buildTestAuthenticatedSharedSate( (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); - factory.setupDirectoryClientMock(); + factory.setupLegalOfficerClientMock(); factory.setupAxiosFactoryMock(); const nodeApi = factory.setupNodeApiMock(LOGION_CLIENT_CONFIG); diff --git a/packages/client/test/Voter.spec.ts b/packages/client/test/Voter.spec.ts index 4beb07d..052c3ad 100644 --- a/packages/client/test/Voter.spec.ts +++ b/packages/client/test/Voter.spec.ts @@ -61,7 +61,7 @@ async function buildSharedState(): Promise { (factory: TestConfigFactory) => { factory.setupDefaultNetworkState(); factory.setupFileUploaderMock(); - factory.setupAuthenticatedDirectoryClientMock(token); + factory.setupAuthenticatedLegalOfficerClientMock(token); const axiosFactoryMock = factory.setupAxiosFactoryMock();