From 80610ed709fb8c265d0b381547575572f974ce4e Mon Sep 17 00:00:00 2001 From: Benoit Devos Date: Wed, 12 Jun 2024 10:08:11 +0200 Subject: [PATCH 1/4] feat: add LLO controller. logion-network/logion-internal#1292 --- resources/mail/all-documented-vars.pug | 19 --- resources/mail/legal-officer-details.pug | 2 +- resources/schemas.json | 64 ++++++++ .../account_recovery.controller.ts | 2 - src/logion/controllers/components.ts | 34 ++++ .../controllers/legalofficer.controller.ts | 147 ++++++++++++++++++ .../1718188396630-AddLegalOfficers.ts | 14 ++ src/logion/model/legalofficer.model.ts | 131 +++++++++++++++- src/logion/services/directory.service.ts | 62 ++++++-- test/helpers/addresses.ts | 58 +++++++ test/integration/migration/migration.spec.ts | 2 +- .../legalofficer.controller.spec.ts | 146 +++++++++++++++++ test/unit/model/legalofficer.model.spec.ts | 23 +++ test/unit/services/notification-test-data.ts | 7 +- 14 files changed, 662 insertions(+), 49 deletions(-) create mode 100644 src/logion/controllers/legalofficer.controller.ts create mode 100644 src/logion/migration/1718188396630-AddLegalOfficers.ts create mode 100644 test/unit/controllers/legalofficer.controller.spec.ts create mode 100644 test/unit/model/legalofficer.model.spec.ts diff --git a/resources/mail/all-documented-vars.pug b/resources/mail/all-documented-vars.pug index 5c06c40b..67ce3b20 100644 --- a/resources/mail/all-documented-vars.pug +++ b/resources/mail/all-documented-vars.pug @@ -3,7 +3,6 @@ | === Legal Officer === | #{legalOfficer.address}; | #{legalOfficer.additionalDetails}; -| #{legalOfficer.node}; | | #{legalOfficer.userIdentity.firstName}; | #{legalOfficer.userIdentity.lastName}; @@ -17,26 +16,8 @@ | #{legalOfficer.postalAddress.city}; | #{legalOfficer.postalAddress.country}; | -| === Other Legal Officer === -| #{otherLegalOfficer.address}; -| #{otherLegalOfficer.additionalDetails}; -| #{otherLegalOfficer.node}; -| -| #{otherLegalOfficer.userIdentity.firstName}; -| #{otherLegalOfficer.userIdentity.lastName}; -| #{otherLegalOfficer.userIdentity.email}; -| #{otherLegalOfficer.userIdentity.phoneNumber}; -| -| #{otherLegalOfficer.postalAddress.company}; -| #{otherLegalOfficer.postalAddress.line1}; -| #{otherLegalOfficer.postalAddress.line2}; -| #{otherLegalOfficer.postalAddress.postalCode}; -| #{otherLegalOfficer.postalAddress.city}; -| #{otherLegalOfficer.postalAddress.country}; -| | === Account Recovery === | #{recovery.requesterAddress.address}; -| #{recovery.otherLegalOfficerAddress}; | #{recovery.addressToRecover}; | #{recovery.createdOn}; | diff --git a/resources/mail/legal-officer-details.pug b/resources/mail/legal-officer-details.pug index bbfc7597..4233d3c3 100644 --- a/resources/mail/legal-officer-details.pug +++ b/resources/mail/legal-officer-details.pug @@ -8,7 +8,7 @@ | | Identification key: | ******************** -| #{legalOfficer.address} +| #{legalOfficer.account.address} | | Email: | ******* diff --git a/resources/schemas.json b/resources/schemas.json index d2ff6599..bcf1e275 100644 --- a/resources/schemas.json +++ b/resources/schemas.json @@ -2049,6 +2049,70 @@ "description": "The ID of the Secret Recovery" } } + }, + "FetchLegalOfficersView": { + "type": "object", + "properties": { + "legalOfficers": { + "type": "array", + "description": "All the legal officers", + "items": { + "$ref": "#/components/schemas/LegalOfficerView" + } + } + }, + "title": "FetchLegalOfficersView", + "description": "The fetched Legal Officers" + }, + "LegalOfficerView": { + "type": "object", + "properties": { + "address": { + "type": "string", + "description": "The SS58 address of the legal officer" + }, + "userIdentity": { + "$ref": "#/components/schemas/UserIdentityView" + }, + "postalAddress": { + "$ref": "#/components/schemas/LegalOfficerPostalAddressView" + }, + "additionalDetails": { + "type": "string", + "description": "Any additional public info" + } + }, + "title": "LegalOfficerView", + "description": "The Legal Officer" + }, + "CreateOrUpdateLegalOfficerView": { + "type": "object", + "properties": { + "userIdentity": { + "$ref": "#/components/schemas/UserIdentityView" + }, + "postalAddress": { + "$ref": "#/components/schemas/LegalOfficerPostalAddressView" + }, + "additionalDetails": { + "type": "string", + "description": "Any additional public info" + } + }, + "title": "CreateOrUpdateLegalOfficerView", + "description": "The Legal Officer info to created or updated" + }, + "LegalOfficerPostalAddressView": { + "type": "object", + "allOf": [{ + "$ref": "#/components/schemas/PostalAddressView" + }], + "properties": { + "company": { + "type": "string", + "description": "The company of the Legal Officer" + } + } } } } diff --git a/src/logion/controllers/account_recovery.controller.ts b/src/logion/controllers/account_recovery.controller.ts index 52cf145a..0a6a661a 100644 --- a/src/logion/controllers/account_recovery.controller.ts +++ b/src/logion/controllers/account_recovery.controller.ts @@ -315,7 +315,6 @@ export class AccountRecoveryController extends ApiController { Promise<{ legalOfficerEMail: string, userEmail: string | undefined, data: LocalsObject }> { const legalOfficer = await this.directoryService.get(request.legalOfficerAddress) - const otherLegalOfficer = await this.directoryService.get(request.otherLegalOfficerAddress) const { userIdentity, userPostalAddress } = userPrivateData ? userPrivateData : await this.locRequestAdapter.getUserPrivateData(request.requesterIdentityLocId) return { legalOfficerEMail: legalOfficer.userIdentity.email, @@ -323,7 +322,6 @@ export class AccountRecoveryController extends ApiController { data: { recovery: { ...request, decision }, legalOfficer, - otherLegalOfficer, walletUser: userIdentity, walletUserPostalAddress: userPostalAddress } diff --git a/src/logion/controllers/components.ts b/src/logion/controllers/components.ts index 6f3b158b..f63364ed 100644 --- a/src/logion/controllers/components.ts +++ b/src/logion/controllers/components.ts @@ -1086,6 +1086,40 @@ export interface components { /** @description The ID of the Secret Recovery */ id?: string; }; + /** + * FetchLegalOfficersView + * @description The fetched Legal Officers + */ + FetchLegalOfficersView: { + /** @description All the legal officers */ + legalOfficers?: components["schemas"]["LegalOfficerView"][]; + }; + /** + * LegalOfficerView + * @description The Legal Officer + */ + LegalOfficerView: { + /** @description The SS58 address of the legal officer */ + address?: string; + userIdentity?: components["schemas"]["UserIdentityView"]; + postalAddress?: components["schemas"]["LegalOfficerPostalAddressView"]; + /** @description Any additional public info */ + additionalDetails?: string; + }; + /** + * CreateOrUpdateLegalOfficerView + * @description The Legal Officer info to created or updated + */ + CreateOrUpdateLegalOfficerView: { + userIdentity?: components["schemas"]["UserIdentityView"]; + postalAddress?: components["schemas"]["LegalOfficerPostalAddressView"]; + /** @description Any additional public info */ + additionalDetails?: string; + }; + LegalOfficerPostalAddressView: { + /** @description The company of the Legal Officer */ + company?: string; + } & components["schemas"]["PostalAddressView"]; }; responses: never; parameters: never; diff --git a/src/logion/controllers/legalofficer.controller.ts b/src/logion/controllers/legalofficer.controller.ts new file mode 100644 index 00000000..e362793e --- /dev/null +++ b/src/logion/controllers/legalofficer.controller.ts @@ -0,0 +1,147 @@ +import { addTag, setControllerTag, getDefaultResponses, setPathParameters, getRequestBody, AuthenticationService, requireDefined } from "@logion/rest-api-core"; +import { OpenAPIV3 } from "openapi-types"; +import { injectable } from "inversify"; +import { Controller, ApiController, HttpGet, Async, HttpPut } from "dinoloop"; +import { components } from "./components.js"; +import { + LegalOfficerRepository, + LegalOfficerDescription, + LegalOfficerFactory, +} from "../model/legalofficer.model.js"; +import { ValidAccountId } from "@logion/node-api"; +import { DirectoryService } from "../services/directory.service.js"; + +export function fillInSpec(spec: OpenAPIV3.Document): void { + const tagName = 'Legal Officers'; + addTag(spec, { + name: tagName, + description: "Retrieval and Management of Legal Officers details" + }); + setControllerTag(spec, /^\/api\/legal-officer.*/, tagName); + + LegalOfficerController.fetchLegalOfficers(spec); + LegalOfficerController.getLegalOfficer(spec); + LegalOfficerController.createOrUpdateLegalOfficer(spec); +} + +type LegalOfficerView = components["schemas"]["LegalOfficerView"] +type FetchLegalOfficersView = components["schemas"]["FetchLegalOfficersView"] +type CreateOrUpdateLegalOfficerView = components["schemas"]["CreateOrUpdateLegalOfficerView"] + +@injectable() +@Controller('/legal-officer') +export class LegalOfficerController extends ApiController { + + constructor( + private legalOfficerRepository: LegalOfficerRepository, + private legalOfficerFactory: LegalOfficerFactory, + private authenticationService: AuthenticationService, + private directoryService: DirectoryService, + ) { + super(); + } + + static fetchLegalOfficers(spec: OpenAPIV3.Document) { + const operationObject = spec.paths["/api/legal-officer"].get!; + operationObject.summary = "Gets the list of all legal officers"; + operationObject.description = "No authentication required."; + operationObject.responses = getDefaultResponses("FetchLegalOfficersView"); + } + + @HttpGet('') + @Async() + async fetchLegalOfficers(): Promise { + const legalOfficers = await this.legalOfficerRepository.findAll(); + return { legalOfficers: legalOfficers.map(legalOfficer => legalOfficer.getDescription()).map(this.toView) } + } + + static getLegalOfficer(spec: OpenAPIV3.Document) { + const operationObject = spec.paths["/api/legal-officer/{address}"].get!; + operationObject.summary = "Gets the details of one legal officer"; + operationObject.description = "No authentication required."; + operationObject.responses = getDefaultResponses("LegalOfficerView"); + setPathParameters(operationObject, { + address: "The Polkadot address of the expected Legal Officer" + }) + } + + @HttpGet('/:address') + @Async() + async getLegalOfficer(address: string): Promise { + const account = ValidAccountId.polkadot(address); + const legalOfficer = await this.legalOfficerRepository.findByAccount(account); + if (legalOfficer) { + return this.toView(legalOfficer.getDescription()); + } else { + throw new Error("No legal officer with given address"); + } + } + + private toView(description: LegalOfficerDescription): LegalOfficerView { + const userIdentity = description.userIdentity; + const postalAddress = description.postalAddress; + return { + address: description.account.address, + userIdentity: { + firstName: userIdentity.firstName, + lastName: userIdentity.lastName, + email: userIdentity.email, + phoneNumber: userIdentity.phoneNumber, + }, + postalAddress: { + company: postalAddress.company, + line1: postalAddress.line1, + line2: postalAddress.line2, + postalCode: postalAddress.postalCode, + city: postalAddress.city, + country: postalAddress.country, + }, + additionalDetails: description.additionalDetails, + } + } + + static createOrUpdateLegalOfficer(spec: OpenAPIV3.Document) { + const operationObject = spec.paths["/api/legal-officer"].put!; + operationObject.summary = "Creates or updates the details of a legal officer"; + operationObject.description = "."; + operationObject.requestBody = getRequestBody({ + description: "Legal Officer details to be created/updated", + view: "CreateOrUpdateLegalOfficerView" + }) + operationObject.responses = getDefaultResponses("LegalOfficerView"); + setPathParameters(operationObject, { + address: "The Polkadot address of the expected Legal Officer" + }) + } + + @HttpPut('') + @Async() + async createOrUpdateLegalOfficer(createOrUpdate: CreateOrUpdateLegalOfficerView): Promise { + const authenticatedUser = await this.authenticationService.authenticatedUser(this.request); + const account = (await authenticatedUser.requireLegalOfficerOnNode()).validAccountId; + const userIdentity = requireDefined(createOrUpdate.userIdentity); + const postalAddress = requireDefined(createOrUpdate.postalAddress); + const description: LegalOfficerDescription = { + account, + userIdentity: { + firstName: userIdentity.firstName || "", + lastName: userIdentity.lastName || "", + email: userIdentity.email || "", + phoneNumber: userIdentity.phoneNumber || "", + }, + postalAddress: { + company: postalAddress.company || "", + line1: postalAddress.line1 || "", + line2: postalAddress.line2 || "", + postalCode: postalAddress.postalCode || "", + city: postalAddress.city || "", + country: postalAddress.country || "", + }, + additionalDetails: createOrUpdate.additionalDetails || "", + } + const legalOfficer = this.legalOfficerFactory.newLegalOfficer(description); + await this.directoryService.createOrUpdateLegalOfficer(legalOfficer); + + return this.toView(legalOfficer.getDescription()); + } +} diff --git a/src/logion/migration/1718188396630-AddLegalOfficers.ts b/src/logion/migration/1718188396630-AddLegalOfficers.ts new file mode 100644 index 00000000..71581315 --- /dev/null +++ b/src/logion/migration/1718188396630-AddLegalOfficers.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddLegalOfficers1718188396630 implements MigrationInterface { + name = 'AddLegalOfficers1718188396630' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "legal_officer" ("address" character varying NOT NULL, "first_name" character varying(255) NOT NULL, "last_name" character varying(255) NOT NULL, "email" character varying(255) NOT NULL, "phone_number" character varying(255) NOT NULL, "company" character varying(255), "line1" character varying(255) NOT NULL, "line2" character varying(255), "postal_code" character varying(255) NOT NULL, "city" character varying(255) NOT NULL, "country" character varying(255) NOT NULL, "additional_details" character varying(255), CONSTRAINT "PK_legal_officer" PRIMARY KEY ("address"))`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "legal_officer"`); + } + +} diff --git a/src/logion/model/legalofficer.model.ts b/src/logion/model/legalofficer.model.ts index f7062f2d..42de0150 100644 --- a/src/logion/model/legalofficer.model.ts +++ b/src/logion/model/legalofficer.model.ts @@ -1,21 +1,136 @@ import { PostalAddress } from "./postaladdress.js"; import { UserIdentity } from "./useridentity.js"; import { ValidAccountId } from "@logion/node-api"; +import { appDataSource } from "@logion/rest-api-core"; +import { Entity, Column, PrimaryColumn, Repository } from "typeorm"; +import { injectable } from "inversify"; +import { DB_SS58_PREFIX } from "./supportedaccountid.model.js"; interface LegalOfficerPostalAddress extends PostalAddress { readonly company: string } -export interface LegalOfficer { - readonly address: string; - readonly userIdentity: UserIdentity - readonly postalAddress: LegalOfficerPostalAddress - readonly additionalDetails: string - readonly node: string -} - export interface LegalOfficerSettingId { id: string, legalOfficer: ValidAccountId, } +@Entity("legal_officer") +export class LegalOfficerAggregateRoot { + + @PrimaryColumn() + address?: string; + + @Column({ length: 255, name: "first_name" }) + firstName?: string; + + @Column({ length: 255, name: "last_name" }) + lastName?: string; + + @Column({ length: 255 }) + email?: string; + + @Column({ length: 255, name: "phone_number" }) + phoneNumber?: string; + + @Column({ length: 255, nullable: true }) + company?: string; + + @Column({ length: 255 }) + line1?: string; + + @Column({ length: 255, nullable: true }) + line2?: string; + + @Column({ length: 255, name: "postal_code" }) + postalCode?: string; + + @Column({ length: 255 }) + city?: string; + + @Column({ length: 255 }) + country?: string; + + @Column({ length: 255, name: "additional_details", nullable: true }) + additionalDetails?: string; + + getDescription(): LegalOfficerDescription { + return { + account: ValidAccountId.polkadot(this.address!), + userIdentity: { + firstName: this.firstName || "", + lastName: this.lastName || "", + email: this.email || "", + phoneNumber: this.phoneNumber || "", + }, + postalAddress: { + company: this.company || "", + line1: this.line1 || "", + line2: this.line2 || "", + postalCode: this.postalCode || "", + city: this.city || "", + country: this.country || "", + }, + additionalDetails: this.additionalDetails || "", + } + } +} + +export interface LegalOfficerDescription { + readonly account: ValidAccountId; + readonly userIdentity: UserIdentity; + readonly postalAddress: LegalOfficerPostalAddress; + readonly additionalDetails: string; +} + +@injectable() +export class LegalOfficerFactory { + + newLegalOfficer(description: LegalOfficerDescription): LegalOfficerAggregateRoot { + const legalOfficer = new LegalOfficerAggregateRoot(); + legalOfficer.address = description.account.getAddress(DB_SS58_PREFIX); + + const userIdentity = description.userIdentity; + legalOfficer.firstName = userIdentity.firstName; + legalOfficer.lastName = userIdentity.lastName; + legalOfficer.email = userIdentity.email; + legalOfficer.phoneNumber = userIdentity.phoneNumber; + + const postalAddress = description.postalAddress + legalOfficer.company = postalAddress.company; + legalOfficer.line1 = postalAddress.line1; + legalOfficer.line2 = postalAddress.line2; + legalOfficer.postalCode = postalAddress.postalCode; + legalOfficer.city = postalAddress.city; + legalOfficer.country = postalAddress.country; + + legalOfficer.additionalDetails = description.additionalDetails; + + return legalOfficer; + } +} + +@injectable() +export class LegalOfficerRepository { + + constructor() { + this.repository = appDataSource.getRepository(LegalOfficerAggregateRoot); + } + + readonly repository: Repository + + public findByAccount(address: ValidAccountId): Promise { + return this.repository.findOneBy({ address: address.getAddress(DB_SS58_PREFIX) }); + } + + public findAll(): Promise { + return this.repository.find(); + } + + public async save(root: LegalOfficerAggregateRoot): Promise { + await this.repository.save(root); + } + +} + + diff --git a/src/logion/services/directory.service.ts b/src/logion/services/directory.service.ts index 08df01b5..02ae719c 100644 --- a/src/logion/services/directory.service.ts +++ b/src/logion/services/directory.service.ts @@ -1,28 +1,35 @@ import { injectable } from "inversify"; -import { LegalOfficer } from "../model/legalofficer.model.js"; -import axios, { AxiosInstance } from "axios"; -import { badRequest, AuthenticationSystemFactory } from "@logion/rest-api-core"; +import { + LegalOfficerDescription, + LegalOfficerRepository, + LegalOfficerAggregateRoot +} from "../model/legalofficer.model.js"; +import { badRequest, AuthenticationSystemFactory, requireDefined, DefaultTransactional } from "@logion/rest-api-core"; import { AuthorityService } from "@logion/authenticator"; import { ValidAccountId } from "@logion/node-api"; -@injectable() -export class DirectoryService { +export abstract class DirectoryService { - private readonly axios: AxiosInstance; private readonly authorityService: Promise; - constructor(private authenticationSystemFactory: AuthenticationSystemFactory) { - if (process.env.DIRECTORY_URL === undefined) { - throw Error("Please set var DIRECTORY_URL"); - } - this.axios = axios.create({ baseURL: process.env.DIRECTORY_URL }); + constructor( + private authenticationSystemFactory: AuthenticationSystemFactory, + private legalOfficerRepository: LegalOfficerRepository, +) { const authenticationSystem = this.authenticationSystemFactory.authenticationSystem(); this.authorityService = authenticationSystem.then(system => system.authorityService); } - async get(account: ValidAccountId): Promise { - return await this.axios.get(`/api/legal-officer/${ account.address }`) - .then(response => response.data); + async createOrUpdateLegalOfficer(legalOfficer: LegalOfficerAggregateRoot): Promise { + await this.legalOfficerRepository.save(legalOfficer); + } + + async get(account: ValidAccountId): Promise { + const legalOfficer = requireDefined( + await this.legalOfficerRepository.findByAccount(account), + () => new Error(`Cannot find legal officer ${ account.address } in local database`) + ); + return legalOfficer.getDescription() } async requireLegalOfficerAddressOnNode(address: string | undefined): Promise { @@ -42,3 +49,30 @@ export class DirectoryService { return (await authorityService.isLegalOfficerOnNode(account)) } } + +@injectable() +export class TransactionalDirectoryService extends DirectoryService { + + constructor( + authenticationSystemFactory: AuthenticationSystemFactory, + legalOfficerRepository: LegalOfficerRepository + ) { + super(authenticationSystemFactory, legalOfficerRepository); + } + + @DefaultTransactional() + async createOrUpdateLegalOfficer(legalOfficer: LegalOfficerAggregateRoot): Promise { + return super.createOrUpdateLegalOfficer(legalOfficer); + } +} + +@injectable() +export class NonTransactionalDirectoryService extends DirectoryService { + + constructor( + authenticationSystemFactory: AuthenticationSystemFactory, + legalOfficerRepository: LegalOfficerRepository + ) { + super(authenticationSystemFactory, legalOfficerRepository); + } +} diff --git a/test/helpers/addresses.ts b/test/helpers/addresses.ts index 19e16dee..d481d8a7 100644 --- a/test/helpers/addresses.ts +++ b/test/helpers/addresses.ts @@ -1,4 +1,5 @@ import { ValidAccountId } from "@logion/node-api"; +import { LegalOfficerDescription } from "../../src/logion/model/legalofficer.model"; // Note to developers: Addresses are encoded // using a different custom prefix: 0 (= Polkadot) @@ -14,3 +15,60 @@ export const CHARLY = "14Gjs1TD93gnwEBfDMHoCgsuf1s2TVKUP6Z1qKmAZnZ8cW5q"; export const ALICE_ACCOUNT = ValidAccountId.polkadot(ALICE); export const BOB_ACCOUNT = ValidAccountId.polkadot(BOB); export const CHARLY_ACCOUNT = ValidAccountId.polkadot(CHARLY); + +export const LEGAL_OFFICERS: LegalOfficerDescription[] = [ + { + account: ALICE_ACCOUNT, + userIdentity: { + firstName: "Alice", + lastName: "Alice", + email: "alice@logion.network", + phoneNumber: "+32 498 00 00 00", + }, + postalAddress: { + company: "MODERO", + line1: "Huissier de Justice Etterbeek", + line2: "Rue Beckers 17", + postalCode: "1040", + city: "Etterbeek", + country: "Belgique" + }, + additionalDetails: "", + }, + { + account: BOB_ACCOUNT, + userIdentity: { + firstName: "Bob", + lastName: "Bob", + email: "bob@logion.network", + phoneNumber: "+33 4 00 00 00 00", + }, + postalAddress: { + company: "SELARL ADRASTEE", + line1: "Gare des Brotteaux", + line2: "14, place Jules Ferry", + postalCode: "69006", + city: "Lyon", + country: "France" + }, + additionalDetails: "", + }, + { + account: CHARLY_ACCOUNT, + userIdentity: { + firstName: "Charlie", + lastName: "Charlie", + email: "charlie@logion.network", + phoneNumber: "+33 2 00 00 00 00", + }, + postalAddress: { + company: "AUXILIA CONSEILS 18", + line1: "Huissiers de Justice associƩs", + line2: "7 rue Jean Francois Champollion Parc Comitec", + postalCode: "18000", + city: "Bourges", + country: "France" + }, + additionalDetails: "", + } +] diff --git a/test/integration/migration/migration.spec.ts b/test/integration/migration/migration.spec.ts index c6fa5ecc..a9158e6e 100644 --- a/test/integration/migration/migration.spec.ts +++ b/test/integration/migration/migration.spec.ts @@ -3,7 +3,7 @@ const { connect, disconnect, queryRunner, runAllMigrations, revertAllMigrations describe('Migration', () => { - const NUM_OF_TABLES = 24; + const NUM_OF_TABLES = 25; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; beforeEach(async () => { diff --git a/test/unit/controllers/legalofficer.controller.spec.ts b/test/unit/controllers/legalofficer.controller.spec.ts new file mode 100644 index 00000000..5dab2372 --- /dev/null +++ b/test/unit/controllers/legalofficer.controller.spec.ts @@ -0,0 +1,146 @@ +import { TestApp } from "@logion/rest-api-core"; +import request from "supertest"; +import { Container } from "inversify"; +import { Mock, It } from "moq.ts"; + +import { LegalOfficerController } from "../../../src/logion/controllers/legalofficer.controller.js"; +import { + LegalOfficerRepository, + LegalOfficerAggregateRoot, + LegalOfficerFactory, + LegalOfficerDescription, +} from "../../../src/logion/model/legalofficer.model.js"; +import { ValidAccountId } from "@logion/node-api"; +import { DB_SS58_PREFIX } from "../../../src/logion/model/supportedaccountid.model.js"; +import { LEGAL_OFFICERS } from "../../helpers/addresses.js"; +import { DirectoryService } from "../../../src/logion/services/directory.service.js"; + +const AUTHENTICATED_ADDRESS = LEGAL_OFFICERS[0].account; +const { setupApp, mockAuthenticationForUserOrLegalOfficer } = TestApp; + +describe("LegalOfficerController", () => { + + it("should fetch all legal officers", async () => { + + const app = setupApp(LegalOfficerController, mockForFetch) + await request(app) + .get("/api/legal-officer") + .expect(200) + .expect('Content-Type', /application\/json/) + .then(response => { + expect(response.body.legalOfficers.length).toBe(LEGAL_OFFICERS.length) + }); + }); + + it("should fetch one legal officer", async () => { + const app = setupApp(LegalOfficerController, mockForFetch) + await request(app) + .get("/api/legal-officer/vQx5kESPn8dWyX4KxMCKqUyCaWUwtui1isX6PVNcZh2Ghjitr") + .expect(200) + .expect('Content-Type', /application\/json/) + .then(response => { + expect(response.body.address).toBe("vQx5kESPn8dWyX4KxMCKqUyCaWUwtui1isX6PVNcZh2Ghjitr") + const userIdentity = response.body.userIdentity; + expect(userIdentity.firstName).toBe("Alice") + expect(userIdentity.lastName).toBe("Alice") + expect(userIdentity.email).toBe("alice@logion.network") + expect(userIdentity.phoneNumber).toBe("+32 498 00 00 00") + let postalAddress = response.body.postalAddress; + expect(postalAddress.company).toBe("MODERO") + expect(postalAddress.line1).toBe("Huissier de Justice Etterbeek") + expect(postalAddress.line2).toBe("Rue Beckers 17") + expect(postalAddress.postalCode).toBe("1040") + expect(postalAddress.city).toBe("Etterbeek") + expect(postalAddress.country).toBe("Belgique") + }); + }) + + it("creates or updates details for a legal officer", async () => { + const payload = { ...LEGAL_OFFICERS[0] } + const app = setupApp(LegalOfficerController, mockForCreateOrUpdate, mockAuthenticationForUserOrLegalOfficer(true, AUTHENTICATED_ADDRESS)) + await request(app) + .put("/api/legal-officer") + .send(payload) + .expect(200) + .expect('Content-Type', /application\/json/) + .then(response => { + expect(response.body.address).toBe(AUTHENTICATED_ADDRESS.address) + const userIdentity = response.body.userIdentity; + expect(userIdentity.firstName).toBe("Alice") + expect(userIdentity.lastName).toBe("Alice") + expect(userIdentity.email).toBe("alice@logion.network") + expect(userIdentity.phoneNumber).toBe("+32 498 00 00 00") + let postalAddress = response.body.postalAddress; + expect(postalAddress.company).toBe("MODERO") + expect(postalAddress.line1).toBe("Huissier de Justice Etterbeek") + expect(postalAddress.line2).toBe("Rue Beckers 17") + expect(postalAddress.postalCode).toBe("1040") + expect(postalAddress.city).toBe("Etterbeek") + expect(postalAddress.country).toBe("Belgique") + }); + }) + + it("fails to create or update details for a legal officer", async () => { + const payload = { ...LEGAL_OFFICERS[0] } + const app = setupApp(LegalOfficerController, mockForCreateOrUpdate, mockAuthenticationForUserOrLegalOfficer(false)) + await request(app) + .put("/api/legal-officer") + .send(payload) + .expect(401) + .expect('Content-Type', /application\/json/); + }) +}) + +function mockForFetch(container: Container) { + const repository = new Mock(); + container.bind(LegalOfficerRepository).toConstantValue(repository.object()); + + const legalOfficer0 = mockLegalOfficer(repository, 0); + const legalOfficers = [ + legalOfficer0, + mockLegalOfficer(repository, 1), + mockLegalOfficer(repository, 2), + ]; + repository.setup(instance => instance.findAll()) + .returns(Promise.resolve(legalOfficers)); + repository.setup(instance => instance.findByAccount(It.IsAny())) + .returns(Promise.resolve(legalOfficer0)); + + const factory = new Mock(); + container.bind(LegalOfficerFactory).toConstantValue(factory.object()); + + const directoryService = new Mock(); + container.bind(DirectoryService).toConstantValue(directoryService.object()); +} + +function mockForCreateOrUpdate(container: Container) { + const repository = new Mock(); + container.bind(LegalOfficerRepository).toConstantValue(repository.object()); + const legalOfficer0 = mockLegalOfficer(repository, 0); + const legalOfficers = [ + legalOfficer0, + mockLegalOfficer(repository, 1), + mockLegalOfficer(repository, 2), + ]; + repository.setup(instance => instance.findAll()) + .returns(Promise.resolve(legalOfficers)); + + const factory = new Mock(); + container.bind(LegalOfficerFactory).toConstantValue(factory.object()); + factory.setup(instance => instance.newLegalOfficer(It.IsAny())) + .returns(legalOfficer0); + + const directoryService = new Mock(); + container.bind(DirectoryService).toConstantValue(directoryService.object()); + directoryService.setup(instance => instance.createOrUpdateLegalOfficer(It.IsAny())) + .returns(Promise.resolve()); +} + +function mockLegalOfficer(repository: Mock, idx:number):LegalOfficerAggregateRoot { + const legalOfficer = new Mock(); + legalOfficer.setup(instance => instance.getDescription()).returns(LEGAL_OFFICERS[idx]); + legalOfficer.setup(instance => instance.address).returns(LEGAL_OFFICERS[idx].account.getAddress(DB_SS58_PREFIX)); + repository.setup(instance => instance.findByAccount(It.Is(account => account.equals(LEGAL_OFFICERS[idx].account)))) + .returns(Promise.resolve(legalOfficer.object())); + return legalOfficer.object(); +} diff --git a/test/unit/model/legalofficer.model.spec.ts b/test/unit/model/legalofficer.model.spec.ts new file mode 100644 index 00000000..2bc0c0a7 --- /dev/null +++ b/test/unit/model/legalofficer.model.spec.ts @@ -0,0 +1,23 @@ +import { LegalOfficerFactory, LegalOfficerDescription } from "../../../src/logion/model/legalofficer.model.js"; +import { LEGAL_OFFICERS } from "../../helpers/addresses.js"; +import { DB_SS58_PREFIX } from "../../../src/logion/model/supportedaccountid.model.js"; + +describe("LegalOfficerFactory", () => { + + let factory: LegalOfficerFactory = new LegalOfficerFactory(); + + it("succeeds to create a LegalOfficerAggregateRoot", async () => { + + LEGAL_OFFICERS.forEach(legalOfficer => { + testNewLegalOfficer(legalOfficer) + }) + }) + + function testNewLegalOfficer(legalOfficer: LegalOfficerDescription) { + let aggregate = factory.newLegalOfficer(legalOfficer) + expect(aggregate.address).toBe(legalOfficer.account.getAddress(DB_SS58_PREFIX)); + expect(aggregate.getDescription().userIdentity).toEqual(legalOfficer.userIdentity); + expect(aggregate.getDescription().postalAddress).toEqual(legalOfficer.postalAddress); + expect(aggregate.getDescription().additionalDetails).toEqual(legalOfficer.additionalDetails); + } +}) diff --git a/test/unit/services/notification-test-data.ts b/test/unit/services/notification-test-data.ts index 9e13a3cc..fec26185 100644 --- a/test/unit/services/notification-test-data.ts +++ b/test/unit/services/notification-test-data.ts @@ -2,7 +2,7 @@ import { AccountRecoveryRequestDescription, } from "../../../src/logion/model/account_recovery.model.js"; import { ALICE_ACCOUNT, BOB_ACCOUNT } from "../../helpers/addresses.js"; -import { LegalOfficer } from "../../../src/logion/model/legalofficer.model.js"; +import { LegalOfficerDescription } from "../../../src/logion/model/legalofficer.model.js"; import { VaultTransferRequestDescription } from "src/logion/model/vaulttransferrequest.model.js"; import { ValidAccountId } from "@logion/node-api"; import { LocRequestDecision, LocRequestDescription } from "src/logion/model/loc_vos.js"; @@ -25,11 +25,10 @@ export const recovery: AccountRecoveryRequestDescription & { decision: LegalOffi } } -export function notifiedLegalOfficer(address:string): LegalOfficer { +export function notifiedLegalOfficer(address:string): LegalOfficerDescription { return { - address, + account: ValidAccountId.polkadot(address), additionalDetails: "some details", - node: "http://localhost:8080", userIdentity: { firstName: address === BOB_ACCOUNT.address ? "Bob": "Alice", lastName: "Network", From 5d9fa5469c2ee2f8be4d2a052e161e5c304c8c1c Mon Sep 17 00:00:00 2001 From: Benoit Devos Date: Wed, 12 Jun 2024 15:39:13 +0200 Subject: [PATCH 2/4] feat: rename DirectoryService to LegalOfficerService. logion-network/logion-internal#1292 --- .env.sample | 1 - resources/mail/README.md | 3 +-- src/logion/app.support.ts | 3 +++ src/logion/container/app.container.ts | 10 ++++++++-- src/logion/controllers/account_recovery.controller.ts | 4 ++-- src/logion/controllers/legalofficer.controller.ts | 4 ++-- src/logion/controllers/locrequest.controller.ts | 4 ++-- src/logion/controllers/secret_recovery.controller.ts | 4 ++-- .../controllers/vaulttransferrequest.controller.ts | 4 ++-- .../services/accountrecoverysynchronization.service.ts | 4 ++-- .../{directory.service.ts => legalOfficerService.ts} | 6 +++--- src/logion/services/locsynchronization.service.ts | 4 ++-- .../controllers/account_recovery.controller.spec.ts | 8 ++++---- test/unit/controllers/legalofficer.controller.spec.ts | 10 +++++----- test/unit/controllers/locrequest.controller.shared.ts | 6 +++--- .../controllers/secret_recovery.controller.spec.ts | 8 ++++---- .../vaulttransferrequest.controller.spec.ts | 6 +++--- .../accountrecoverysynchronizer.service.spec.ts | 6 +++--- test/unit/services/locsynchronization.service.spec.ts | 4 ++-- 19 files changed, 53 insertions(+), 46 deletions(-) rename src/logion/services/{directory.service.ts => legalOfficerService.ts} (93%) diff --git a/.env.sample b/.env.sample index ab71c437..0b70aa41 100644 --- a/.env.sample +++ b/.env.sample @@ -6,7 +6,6 @@ JWT_ISSUER=12D3KooWDCuGU7WY3VaWjBS1E44x4EnmTgK3HRxWFqYG3dqXDfP1 # Replace this v JWT_TTL_SEC=3600 # TTL of issued JWT tokens OWNER=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice HEALTH_TOKEN="change-me-please" -DIRECTORY_URL=http://localhost:8090 BASE_URL=http://localhost:8080 # E-mail diff --git a/resources/mail/README.md b/resources/mail/README.md index 350caf4a..49d9bd49 100644 --- a/resources/mail/README.md +++ b/resources/mail/README.md @@ -9,9 +9,8 @@ contain only variables, which are replaced at runtime with their respective valu All possible variables are available (for copy/paste) in this template: [all-documented-vars.pug](all-documented-vars.pug) ### Legal Officer - legalOfficer.address + legalOfficer.account.address legalOfficer.additionalDetails - legalOfficer.node legalOfficer.userIdentity.firstName legalOfficer.userIdentity.lastName diff --git a/src/logion/app.support.ts b/src/logion/app.support.ts index 7c59978b..3e49fad9 100644 --- a/src/logion/app.support.ts +++ b/src/logion/app.support.ts @@ -26,6 +26,7 @@ import { fillInSpec as fillInSpecTokensRecord, TokensRecordController } from "./ import { fillInSpec as fillInSpecWorkload, WorkloadController } from "./controllers/workload.controller.js"; import { fillInSpec as fillInSpecSecretRecovery, SecretRecoveryController } from "./controllers/secret_recovery.controller.js"; import { fillInSpec as fillInSpecRecovery, RecoveryController } from "./controllers/recovery.controller.js"; +import { fillInSpec as fillInSpecLegalOfficer, LegalOfficerController } from "./controllers/legalofficer.controller.js"; const { logger } = Log; @@ -66,6 +67,7 @@ export function predefinedSpec(spec: OpenAPIV3.Document): OpenAPIV3.Document { fillInSpecWorkload(spec); fillInSpecSecretRecovery(spec); fillInSpecRecovery(spec); + fillInSpecLegalOfficer(spec); return spec; } @@ -130,6 +132,7 @@ export function setupApp(expressConfig?: ExpressConfig): Express { dino.registerController(WorkloadController); dino.registerController(SecretRecoveryController); dino.registerController(RecoveryController); + dino.registerController(LegalOfficerController); dino.dependencyResolver(AppContainer, (injector, type) => { diff --git a/src/logion/container/app.container.ts b/src/logion/container/app.container.ts index 3dc45b5e..c93a138f 100644 --- a/src/logion/container/app.container.ts +++ b/src/logion/container/app.container.ts @@ -20,7 +20,9 @@ import { TransactionController } from '../controllers/transaction.controller.js' import { CollectionRepository, CollectionFactory } from "../model/collection.model.js"; import { NotificationService } from "../services/notification.service.js"; import { MailService } from "../services/mail.service.js"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService, TransactionalLegalOfficerService } from "../services/legalOfficerService.js"; +import { LegalOfficerController } from "../controllers/legalofficer.controller.js"; +import { LegalOfficerRepository, LegalOfficerFactory } from "../model/legalofficer.model.js"; import { VaultTransferRequestController } from '../controllers/vaulttransferrequest.controller.js'; import { VaultTransferRequestFactory, VaultTransferRequestRepository } from '../model/vaulttransferrequest.model.js'; import { LoFileFactory, LoFileRepository } from "../model/lofile.model.js"; @@ -96,7 +98,10 @@ container.bind(CollectionFactory).toSelf() container.bind(LogionNodeCollectionService).toSelf(); container.bind(NotificationService).toSelf() container.bind(MailService).toSelf() -container.bind(DirectoryService).toSelf() +container.bind(LegalOfficerService).toService(TransactionalLegalOfficerService); +container.bind(TransactionalLegalOfficerService).toSelf(); +container.bind(LegalOfficerFactory).toSelf(); +container.bind(LegalOfficerRepository).toSelf(); container.bind(VaultTransferRequestRepository).toSelf(); container.bind(VaultTransferRequestFactory).toSelf(); container.bind(LoFileFactory).toSelf(); @@ -177,5 +182,6 @@ container.bind(TokensRecordController).toSelf().inTransientScope(); container.bind(WorkloadController).toSelf().inTransientScope(); container.bind(SecretRecoveryController).toSelf().inTransientScope(); container.bind(RecoveryController).toSelf().inTransientScope(); +container.bind(LegalOfficerController).toSelf().inTransientScope(); export { container as AppContainer }; diff --git a/src/logion/controllers/account_recovery.controller.ts b/src/logion/controllers/account_recovery.controller.ts index 0a6a661a..debd2639 100644 --- a/src/logion/controllers/account_recovery.controller.ts +++ b/src/logion/controllers/account_recovery.controller.ts @@ -25,7 +25,7 @@ import { } from '../model/account_recovery.model.js'; import { components } from './components.js'; import { NotificationService, Template, NotificationRecipient } from "../services/notification.service.js"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService } from "../services/legalOfficerService.js"; import { AccountRecoveryRequestService } from '../services/accountrecoveryrequest.service.js'; import { LocalsObject } from 'pug'; import { LocRequestAdapter, UserPrivateData } from "./adapters/locrequestadapter.js"; @@ -91,7 +91,7 @@ export class AccountRecoveryController extends ApiController { private accountRecoveryRequestFactory: AccountRecoveryRequestFactory, private authenticationService: AuthenticationService, private notificationService: NotificationService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, private accountRecoveryRequestService: AccountRecoveryRequestService, private locRequestAdapter: LocRequestAdapter, private locRequestRepository: LocRequestRepository, diff --git a/src/logion/controllers/legalofficer.controller.ts b/src/logion/controllers/legalofficer.controller.ts index e362793e..dfb063d9 100644 --- a/src/logion/controllers/legalofficer.controller.ts +++ b/src/logion/controllers/legalofficer.controller.ts @@ -9,7 +9,7 @@ import { LegalOfficerFactory, } from "../model/legalofficer.model.js"; import { ValidAccountId } from "@logion/node-api"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService } from "../services/legalOfficerService.js"; export function fillInSpec(spec: OpenAPIV3.Document): void { const tagName = 'Legal Officers'; @@ -36,7 +36,7 @@ export class LegalOfficerController extends ApiController { private legalOfficerRepository: LegalOfficerRepository, private legalOfficerFactory: LegalOfficerFactory, private authenticationService: AuthenticationService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, ) { super(); } diff --git a/src/logion/controllers/locrequest.controller.ts b/src/logion/controllers/locrequest.controller.ts index 1535bc29..918125d5 100644 --- a/src/logion/controllers/locrequest.controller.ts +++ b/src/logion/controllers/locrequest.controller.ts @@ -33,7 +33,7 @@ import { UserIdentity } from "../model/useridentity.js"; import { FileStorageService } from "../services/file.storage.service.js"; import { ForbiddenException } from "dinoloop/modules/builtin/exceptions/exceptions.js"; import { NotificationService, Template, NotificationRecipient } from "../services/notification.service.js"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService } from "../services/legalOfficerService.js"; import { CollectionRepository } from "../model/collection.model.js"; import { getUploadedFile } from "./fileupload.js"; import { PostalAddress } from "../model/postaladdress.js"; @@ -140,7 +140,7 @@ export class LocRequestController extends ApiController { private collectionRepository: CollectionRepository, private fileStorageService: FileStorageService, private notificationService: NotificationService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, private locRequestAdapter: LocRequestAdapter, private locRequestService: LocRequestService, private locAuthorizationService: LocAuthorizationService, diff --git a/src/logion/controllers/secret_recovery.controller.ts b/src/logion/controllers/secret_recovery.controller.ts index 84c7876b..ed4d5ed6 100644 --- a/src/logion/controllers/secret_recovery.controller.ts +++ b/src/logion/controllers/secret_recovery.controller.ts @@ -22,7 +22,7 @@ import moment from "moment"; import { NotificationRecipient, Template, NotificationService } from "../services/notification.service.js"; import { UserPrivateData } from "./adapters/locrequestadapter.js"; import { LocalsObject } from "pug"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService } from "../services/legalOfficerService.js"; import { UUID, ValidAccountId } from "@logion/node-api"; import { LegalOfficerDecisionDescription } from "../model/decision.js"; import { EMPTY_POSTAL_ADDRESS } from "../model/postaladdress.js"; @@ -62,7 +62,7 @@ export class SecretRecoveryController extends ApiController { private secretRecoveryRequestService: SecretRecoveryRequestService, private secretRecoveryRequestRepository: SecretRecoveryRequestRepository, private locRequestRepository: LocRequestRepository, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, private notificationService: NotificationService, private authenticationService: AuthenticationService, ) { diff --git a/src/logion/controllers/vaulttransferrequest.controller.ts b/src/logion/controllers/vaulttransferrequest.controller.ts index 6bbff5aa..5294673a 100644 --- a/src/logion/controllers/vaulttransferrequest.controller.ts +++ b/src/logion/controllers/vaulttransferrequest.controller.ts @@ -25,7 +25,7 @@ import { } from '../model/vaulttransferrequest.model.js'; import { components } from './components.js'; import { NotificationService } from "../services/notification.service.js"; -import { DirectoryService } from "../services/directory.service.js"; +import { LegalOfficerService } from "../services/legalOfficerService.js"; import { AccountRecoveryRequestDescription, AccountRecoveryRepository } from '../model/account_recovery.model.js'; import { VaultTransferRequestService } from '../services/vaulttransferrequest.service.js'; import { LocalsObject } from 'pug'; @@ -71,7 +71,7 @@ export class VaultTransferRequestController extends ApiController { private vaultTransferRequestFactory: VaultTransferRequestFactory, private authenticationService: AuthenticationService, private notificationService: NotificationService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, private accountRecoveryRepository: AccountRecoveryRepository, private vaultTransferRequestService: VaultTransferRequestService, private polkadotService: PolkadotService, diff --git a/src/logion/services/accountrecoverysynchronization.service.ts b/src/logion/services/accountrecoverysynchronization.service.ts index 8217c4d4..f16e30e0 100644 --- a/src/logion/services/accountrecoverysynchronization.service.ts +++ b/src/logion/services/accountrecoverysynchronization.service.ts @@ -5,7 +5,7 @@ import { AccountRecoveryRepository, FetchAccountRecoveryRequestsSpecification } import { Adapters, ValidAccountId } from '@logion/node-api'; import { JsonExtrinsic, toString } from "./types/responses/Extrinsic.js"; import { AccountRecoveryRequestService as AccountRecoveryService } from './accountrecoveryrequest.service.js'; -import { DirectoryService } from "./directory.service.js"; +import { LegalOfficerService } from "./legalOfficerService.js"; const { logger } = Log; @@ -15,7 +15,7 @@ export class AccountRecoverySynchronizer { constructor( private accountRecoveryRepository: AccountRecoveryRepository, private accountRecoveryService: AccountRecoveryService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, ) { } diff --git a/src/logion/services/directory.service.ts b/src/logion/services/legalOfficerService.ts similarity index 93% rename from src/logion/services/directory.service.ts rename to src/logion/services/legalOfficerService.ts index 02ae719c..d173d5e0 100644 --- a/src/logion/services/directory.service.ts +++ b/src/logion/services/legalOfficerService.ts @@ -8,7 +8,7 @@ import { badRequest, AuthenticationSystemFactory, requireDefined, DefaultTransac import { AuthorityService } from "@logion/authenticator"; import { ValidAccountId } from "@logion/node-api"; -export abstract class DirectoryService { +export abstract class LegalOfficerService { private readonly authorityService: Promise; @@ -51,7 +51,7 @@ export abstract class DirectoryService { } @injectable() -export class TransactionalDirectoryService extends DirectoryService { +export class TransactionalLegalOfficerService extends LegalOfficerService { constructor( authenticationSystemFactory: AuthenticationSystemFactory, @@ -67,7 +67,7 @@ export class TransactionalDirectoryService extends DirectoryService { } @injectable() -export class NonTransactionalDirectoryService extends DirectoryService { +export class NonTransactionalLegalOfficerService extends LegalOfficerService { constructor( authenticationSystemFactory: AuthenticationSystemFactory, diff --git a/src/logion/services/locsynchronization.service.ts b/src/logion/services/locsynchronization.service.ts index 39c7117e..16c003e7 100644 --- a/src/logion/services/locsynchronization.service.ts +++ b/src/logion/services/locsynchronization.service.ts @@ -9,7 +9,7 @@ import { LocRequestService } from './locrequest.service.js'; import { CollectionService } from './collection.service.js'; import { UserIdentity } from '../model/useridentity.js'; import { NotificationService } from './notification.service.js'; -import { DirectoryService } from './directory.service.js'; +import { LegalOfficerService } from './legalOfficerService.js'; import { VerifiedIssuerSelectionService } from './verifiedissuerselection.service.js'; import { TokensRecordService } from './tokensrecord.service.js'; import { EMPTY_ITEMS, LocItems } from '../model/loc_items.js'; @@ -24,7 +24,7 @@ export class LocSynchronizer { private locRequestService: LocRequestService, private collectionService: CollectionService, private notificationService: NotificationService, - private directoryService: DirectoryService, + private directoryService: LegalOfficerService, private verifiedIssuerSelectionService: VerifiedIssuerSelectionService, private tokensRecordService: TokensRecordService, ) {} diff --git a/test/unit/controllers/account_recovery.controller.spec.ts b/test/unit/controllers/account_recovery.controller.spec.ts index 5a7e90f0..592ad369 100644 --- a/test/unit/controllers/account_recovery.controller.spec.ts +++ b/test/unit/controllers/account_recovery.controller.spec.ts @@ -15,7 +15,7 @@ import { ALICE, BOB, BOB_ACCOUNT, ALICE_ACCOUNT } from '../../helpers/addresses. import { AccountRecoveryController } from '../../../src/logion/controllers/account_recovery.controller.js'; import { NotificationService, Template } from "../../../src/logion/services/notification.service.js"; import moment from "moment"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { notifiedLegalOfficer } from "../services/notification-test-data.js"; import { UserIdentity } from '../../../src/logion/model/useridentity.js'; import { PostalAddress } from '../../../src/logion/model/postaladdress.js'; @@ -96,7 +96,7 @@ function mockRecoveryRequestModel(container: Container, addressToRecover: ValidA root.setup(instance => instance.requesterIdentityLocId) .returns(identityLoc.id) - + factory.setup(instance => instance.newAccountRecoveryRequest( It.Is(params => { return params.addressToRecover !== null @@ -485,14 +485,14 @@ function mockNotificationAndDirectoryService(container: Container) { .returns(Promise.resolve()) container.bind(NotificationService).toConstantValue(notificationService.object()) - const directoryService = new Mock(); + const directoryService = new Mock(); directoryService .setup(instance => instance.get(It.IsAny())) .returns(Promise.resolve(notifiedLegalOfficer(ALICE_ACCOUNT.address))) directoryService .setup(instance => instance.requireLegalOfficerAddressOnNode(It.IsAny())) .returns(Promise.resolve(ALICE_ACCOUNT)); - container.bind(DirectoryService).toConstantValue(directoryService.object()) + container.bind(LegalOfficerService).toConstantValue(directoryService.object()) } function mockRecoveryRequest(): Mock { diff --git a/test/unit/controllers/legalofficer.controller.spec.ts b/test/unit/controllers/legalofficer.controller.spec.ts index 5dab2372..78fda495 100644 --- a/test/unit/controllers/legalofficer.controller.spec.ts +++ b/test/unit/controllers/legalofficer.controller.spec.ts @@ -13,7 +13,7 @@ import { import { ValidAccountId } from "@logion/node-api"; import { DB_SS58_PREFIX } from "../../../src/logion/model/supportedaccountid.model.js"; import { LEGAL_OFFICERS } from "../../helpers/addresses.js"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; const AUTHENTICATED_ADDRESS = LEGAL_OFFICERS[0].account; const { setupApp, mockAuthenticationForUserOrLegalOfficer } = TestApp; @@ -109,8 +109,8 @@ function mockForFetch(container: Container) { const factory = new Mock(); container.bind(LegalOfficerFactory).toConstantValue(factory.object()); - const directoryService = new Mock(); - container.bind(DirectoryService).toConstantValue(directoryService.object()); + const directoryService = new Mock(); + container.bind(LegalOfficerService).toConstantValue(directoryService.object()); } function mockForCreateOrUpdate(container: Container) { @@ -130,8 +130,8 @@ function mockForCreateOrUpdate(container: Container) { factory.setup(instance => instance.newLegalOfficer(It.IsAny())) .returns(legalOfficer0); - const directoryService = new Mock(); - container.bind(DirectoryService).toConstantValue(directoryService.object()); + const directoryService = new Mock(); + container.bind(LegalOfficerService).toConstantValue(directoryService.object()); directoryService.setup(instance => instance.createOrUpdateLegalOfficer(It.IsAny())) .returns(Promise.resolve()); } diff --git a/test/unit/controllers/locrequest.controller.shared.ts b/test/unit/controllers/locrequest.controller.shared.ts index 83d34944..d087e480 100644 --- a/test/unit/controllers/locrequest.controller.shared.ts +++ b/test/unit/controllers/locrequest.controller.shared.ts @@ -13,7 +13,7 @@ import { } from "../../../src/logion/model/locrequest.model.js"; import { FileStorageService } from "../../../src/logion/services/file.storage.service.js"; import { NotificationService, Template } from "../../../src/logion/services/notification.service.js"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { notifiedLegalOfficer } from "../services/notification-test-data.js"; import { CollectionRepository } from "../../../src/logion/model/collection.model.js"; import { LATEST_SEAL_VERSION, PersonalInfoSealService, Seal, } from "../../../src/logion/services/seal.service.js"; @@ -230,14 +230,14 @@ function mockOtherDependencies(container: Container, existingMocks?: { .returns(Promise.resolve()) container.bind(NotificationService).toConstantValue(notificationService.object()) - const directoryService = new Mock(); + const directoryService = new Mock(); directoryService .setup(instance => instance.get(It.IsAny())) .returns(Promise.resolve(notifiedLegalOfficer(ALICE_ACCOUNT.address))) directoryService .setup(instance => instance.requireLegalOfficerAddressOnNode(It.IsAny())) .returns(Promise.resolve(ALICE_ACCOUNT)); - container.bind(DirectoryService).toConstantValue(directoryService.object()) + container.bind(LegalOfficerService).toConstantValue(directoryService.object()) const collectionRepository = existingMocks?.collectionRepository ? existingMocks.collectionRepository : new Mock(); container.bind(CollectionRepository).toConstantValue(collectionRepository.object()) diff --git a/test/unit/controllers/secret_recovery.controller.spec.ts b/test/unit/controllers/secret_recovery.controller.spec.ts index 91483b5b..1343db4f 100644 --- a/test/unit/controllers/secret_recovery.controller.spec.ts +++ b/test/unit/controllers/secret_recovery.controller.spec.ts @@ -15,7 +15,7 @@ import { import { Mock, It, Times } from "moq.ts"; import request from "supertest"; import { ALICE_ACCOUNT, ALICE } from "../../helpers/addresses.js"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { NotificationService, Template } from "../../../src/logion/services/notification.service.js"; import moment from "moment"; import { notifiedLegalOfficer } from "../services/notification-test-data.js"; @@ -228,7 +228,7 @@ let identityLoc: Mock; let secretRecoveryRequestFactory: Mock; let secretRecoveryRequestRepository: Mock; let locRequestRepository: Mock; -let directoryService: Mock; +let directoryService: Mock; let notificationService: Mock; let secretRecoveryRequest: Mock; @@ -241,8 +241,8 @@ function createAndBindMocks(container: Container) { container.bind(SecretRecoveryRequestService).toConstantValue(new NonTransactionalSecretRecoveryRequestService(secretRecoveryRequestRepository.object())); locRequestRepository = new Mock(); container.bind(LocRequestRepository).toConstantValue(locRequestRepository.object()); - directoryService = new Mock(); - container.bind(DirectoryService).toConstantValue(directoryService.object()); + directoryService = new Mock(); + container.bind(LegalOfficerService).toConstantValue(directoryService.object()); notificationService = new Mock(); container.bind(NotificationService).toConstantValue(notificationService.object()); } diff --git a/test/unit/controllers/vaulttransferrequest.controller.spec.ts b/test/unit/controllers/vaulttransferrequest.controller.spec.ts index 9ca03122..ded192ad 100644 --- a/test/unit/controllers/vaulttransferrequest.controller.spec.ts +++ b/test/unit/controllers/vaulttransferrequest.controller.spec.ts @@ -14,7 +14,7 @@ import { ALICE, BOB_ACCOUNT, ALICE_ACCOUNT } from '../../helpers/addresses.js'; import { VaultTransferRequestController } from '../../../src/logion/controllers/vaulttransferrequest.controller.js'; import { NotificationService, Template } from "../../../src/logion/services/notification.service.js"; import moment from "moment"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { notifiedLegalOfficer } from "../services/notification-test-data.js"; import { FetchAccountRecoveryRequestsSpecification, @@ -247,14 +247,14 @@ function mockOtherDependencies(container: Container, repository: Mock(); + const directoryService = new Mock(); directoryService .setup(instance => instance.get(It.IsAny())) .returns(Promise.resolve(ALICE_LEGAL_OFFICER)); directoryService .setup(instance => instance.requireLegalOfficerAddressOnNode(It.IsAny())) .returns(Promise.resolve(ALICE_ACCOUNT)); - container.bind(DirectoryService).toConstantValue(directoryService.object()); + container.bind(LegalOfficerService).toConstantValue(directoryService.object()); const accountRecoveryRequest = new Mock(); accountRecoveryRequest.setup(instance => instance.getDescription()).returns(accountRecoveryRequestDescription); diff --git a/test/unit/services/accountrecoverysynchronizer.service.spec.ts b/test/unit/services/accountrecoverysynchronizer.service.spec.ts index 0e853798..450966d4 100644 --- a/test/unit/services/accountrecoverysynchronizer.service.spec.ts +++ b/test/unit/services/accountrecoverysynchronizer.service.spec.ts @@ -8,7 +8,7 @@ import { JsonExtrinsic } from '../../../src/logion/services/types/responses/Extr import { AccountRecoverySynchronizer } from '../../../src/logion/services/accountrecoverysynchronization.service.js'; import { BOB_ACCOUNT, ALICE_ACCOUNT } from '../../helpers/addresses.js'; import { NonTransactionalAccountRecoveryRequestService } from '../../../src/logion/services/accountrecoveryrequest.service.js'; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { ValidAccountId } from "@logion/node-api"; describe("AccountRecoverySynchronizer", () => { @@ -27,7 +27,7 @@ describe("AccountRecoverySynchronizer", () => { }); let protectionRequestRepository: Mock; -let directoryService: Mock; +let directoryService: Mock; function givenCreateRecoveryExtrinsic() { locExtrinsic = new Mock(); @@ -58,7 +58,7 @@ function givenProtectionRequest() { protectionRequestRepository.setup(instance => instance.findById(requestId)).returns(Promise.resolve(locRequest.object())); protectionRequestRepository.setup(instance => instance.save(locRequest.object())).returns(Promise.resolve()); - directoryService = new Mock(); + directoryService = new Mock(); directoryService.setup(instance => instance.isLegalOfficerAddressOnNode) .returns(account => Promise.resolve(account.equals(ALICE_ACCOUNT))); } diff --git a/test/unit/services/locsynchronization.service.spec.ts b/test/unit/services/locsynchronization.service.spec.ts index 1605a39d..2c7c9c6a 100644 --- a/test/unit/services/locsynchronization.service.spec.ts +++ b/test/unit/services/locsynchronization.service.spec.ts @@ -11,7 +11,7 @@ import { import { NonTransactionalLocRequestService } from "../../../src/logion/services/locrequest.service.js"; import { NonTransactionalCollectionService } from "../../../src/logion/services/collection.service.js"; import { NotificationService } from "../../../src/logion/services/notification.service.js"; -import { DirectoryService } from "../../../src/logion/services/directory.service.js"; +import { LegalOfficerService } from "../../../src/logion/services/legalOfficerService.js"; import { VerifiedIssuerSelectionService } from "src/logion/services/verifiedissuerselection.service.js"; import { NonTransactionalTokensRecordService } from "../../../src/logion/services/tokensrecord.service.js"; import { TokensRecordRepository } from "../../../src/logion/model/tokensrecord.model.js"; @@ -264,7 +264,7 @@ function locSynchronizer(): LocSynchronizer { } let notificationService: Mock; -let directoryService: Mock; +let directoryService: Mock; let verifiedIssuerSelectionService: Mock; let tokensRecordRepository: Mock; From bafcd20011a73b417792b3173e524b9274bf71f2 Mon Sep 17 00:00:00 2001 From: Benoit Devos Date: Tue, 18 Jun 2024 14:35:10 +0200 Subject: [PATCH 3/4] feat: rename var directoryService to legalOfficerService. logion-network/logion-internal#1292 --- .../account_recovery.controller.ts | 6 ++--- .../controllers/legalofficer.controller.ts | 4 ++-- .../controllers/locrequest.controller.ts | 8 +++---- .../controllers/secret_recovery.controller.ts | 4 ++-- .../vaulttransferrequest.controller.ts | 6 ++--- .../accountrecoverysynchronization.service.ts | 4 ++-- .../services/locsynchronization.service.ts | 10 ++++----- .../account_recovery.controller.spec.ts | 22 +++++++++---------- .../legalofficer.controller.spec.ts | 10 ++++----- .../locrequest.controller.shared.ts | 8 +++---- .../secret_recovery.controller.spec.ts | 8 +++---- .../vaulttransferrequest.controller.spec.ts | 8 +++---- ...ccountrecoverysynchronizer.service.spec.ts | 8 +++---- .../locsynchronization.service.spec.ts | 6 ++--- 14 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/logion/controllers/account_recovery.controller.ts b/src/logion/controllers/account_recovery.controller.ts index debd2639..88ca55c5 100644 --- a/src/logion/controllers/account_recovery.controller.ts +++ b/src/logion/controllers/account_recovery.controller.ts @@ -91,7 +91,7 @@ export class AccountRecoveryController extends ApiController { private accountRecoveryRequestFactory: AccountRecoveryRequestFactory, private authenticationService: AuthenticationService, private notificationService: NotificationService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, private accountRecoveryRequestService: AccountRecoveryRequestService, private locRequestAdapter: LocRequestAdapter, private locRequestRepository: LocRequestRepository, @@ -114,7 +114,7 @@ export class AccountRecoveryController extends ApiController { @HttpPost('') async createRequest(body: CreateAccountRecoveryRequestView): Promise { const requester = await this.authenticationService.authenticatedUser(this.request); - const legalOfficerAddress = await this.directoryService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress); + const legalOfficerAddress = await this.legalOfficerService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress); const requesterIdentityLoc = requireDefined(body.requesterIdentityLoc); const request = await this.accountRecoveryRequestFactory.newAccountRecoveryRequest({ id: uuid(), @@ -314,7 +314,7 @@ export class AccountRecoveryController extends ApiController { private async getNotificationInfo(request: AccountRecoveryRequestDescription, userPrivateData?: UserPrivateData, decision?: LegalOfficerDecisionDescription): Promise<{ legalOfficerEMail: string, userEmail: string | undefined, data: LocalsObject }> { - const legalOfficer = await this.directoryService.get(request.legalOfficerAddress) + const legalOfficer = await this.legalOfficerService.get(request.legalOfficerAddress) const { userIdentity, userPostalAddress } = userPrivateData ? userPrivateData : await this.locRequestAdapter.getUserPrivateData(request.requesterIdentityLocId) return { legalOfficerEMail: legalOfficer.userIdentity.email, diff --git a/src/logion/controllers/legalofficer.controller.ts b/src/logion/controllers/legalofficer.controller.ts index dfb063d9..90c18c14 100644 --- a/src/logion/controllers/legalofficer.controller.ts +++ b/src/logion/controllers/legalofficer.controller.ts @@ -36,7 +36,7 @@ export class LegalOfficerController extends ApiController { private legalOfficerRepository: LegalOfficerRepository, private legalOfficerFactory: LegalOfficerFactory, private authenticationService: AuthenticationService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, ) { super(); } @@ -140,7 +140,7 @@ export class LegalOfficerController extends ApiController { additionalDetails: createOrUpdate.additionalDetails || "", } const legalOfficer = this.legalOfficerFactory.newLegalOfficer(description); - await this.directoryService.createOrUpdateLegalOfficer(legalOfficer); + await this.legalOfficerService.createOrUpdateLegalOfficer(legalOfficer); return this.toView(legalOfficer.getDescription()); } diff --git a/src/logion/controllers/locrequest.controller.ts b/src/logion/controllers/locrequest.controller.ts index 918125d5..1b392576 100644 --- a/src/logion/controllers/locrequest.controller.ts +++ b/src/logion/controllers/locrequest.controller.ts @@ -140,7 +140,7 @@ export class LocRequestController extends ApiController { private collectionRepository: CollectionRepository, private fileStorageService: FileStorageService, private notificationService: NotificationService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, private locRequestAdapter: LocRequestAdapter, private locRequestService: LocRequestService, private locAuthorizationService: LocAuthorizationService, @@ -164,7 +164,7 @@ export class LocRequestController extends ApiController { @Async() async createLocRequest(createLocRequestView: CreateLocRequestView): Promise { const authenticatedUser = await this.authenticationService.authenticatedUser(this.request); - const ownerAddress = await this.directoryService.requireLegalOfficerAddressOnNode(createLocRequestView.ownerAddress); + const ownerAddress = await this.legalOfficerService.requireLegalOfficerAddressOnNode(createLocRequestView.ownerAddress); const locType = requireDefined(createLocRequestView.locType); const requesterAddress = !authenticatedUser.validAccountId.equals(ownerAddress) ? authenticatedUser.validAccountId : @@ -276,7 +276,7 @@ export class LocRequestController extends ApiController { @Async() async createOpenLoc(openLocView: OpenLocView): Promise { const authenticatedUser = await this.authenticationService.authenticatedUser(this.request); - const ownerAddress = await this.directoryService.requireLegalOfficerAddressOnNode(openLocView.ownerAddress); + const ownerAddress = await this.legalOfficerService.requireLegalOfficerAddressOnNode(openLocView.ownerAddress); const locType = requireDefined(openLocView.locType); const requesterAddress = authenticatedUser.validAccountId; const requesterIdentityLoc = await this.locRequestRepository.getValidPolkadotIdentityLoc(requesterAddress, ownerAddress); @@ -1555,7 +1555,7 @@ export class LocRequestController extends ApiController { private async getNotificationInfo(loc: LocRequestDescription, userIdentity: UserIdentity, decision?: LocRequestDecision): Promise<{ legalOfficerEMail: string, data: LocalsObject }> { - const legalOfficer = await this.directoryService.get(loc.ownerAddress); + const legalOfficer = await this.legalOfficerService.get(loc.ownerAddress); return { legalOfficerEMail: legalOfficer.userIdentity.email, data: { diff --git a/src/logion/controllers/secret_recovery.controller.ts b/src/logion/controllers/secret_recovery.controller.ts index ed4d5ed6..e1232bb3 100644 --- a/src/logion/controllers/secret_recovery.controller.ts +++ b/src/logion/controllers/secret_recovery.controller.ts @@ -62,7 +62,7 @@ export class SecretRecoveryController extends ApiController { private secretRecoveryRequestService: SecretRecoveryRequestService, private secretRecoveryRequestRepository: SecretRecoveryRequestRepository, private locRequestRepository: LocRequestRepository, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, private notificationService: NotificationService, private authenticationService: AuthenticationService, ) { @@ -142,7 +142,7 @@ export class SecretRecoveryController extends ApiController { private async getNotificationInfo(secretRecoveryRequest: SecretRecoveryRequestDescription, legalOfficerAccount: ValidAccountId, userPrivateData: UserPrivateData, decision?: LegalOfficerDecisionDescription): Promise<{ legalOfficerEMail: string, userEmail: string | undefined, data: LocalsObject }> { - const legalOfficer = await this.directoryService.get(legalOfficerAccount) + const legalOfficer = await this.legalOfficerService.get(legalOfficerAccount) const { userIdentity, userPostalAddress } = userPrivateData; return { legalOfficerEMail: legalOfficer.userIdentity.email, diff --git a/src/logion/controllers/vaulttransferrequest.controller.ts b/src/logion/controllers/vaulttransferrequest.controller.ts index 5294673a..e94af3b0 100644 --- a/src/logion/controllers/vaulttransferrequest.controller.ts +++ b/src/logion/controllers/vaulttransferrequest.controller.ts @@ -71,7 +71,7 @@ export class VaultTransferRequestController extends ApiController { private vaultTransferRequestFactory: VaultTransferRequestFactory, private authenticationService: AuthenticationService, private notificationService: NotificationService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, private accountRecoveryRepository: AccountRecoveryRepository, private vaultTransferRequestService: VaultTransferRequestService, private polkadotService: PolkadotService, @@ -96,7 +96,7 @@ export class VaultTransferRequestController extends ApiController { async createVaultTransferRequest(body: CreateVaultTransferRequestView): Promise { const origin = ValidAccountId.polkadot(requireDefined(body.origin, () => badRequest("Missing origin"))); const destination = ValidAccountId.polkadot(requireDefined(body.destination, () => badRequest("Missing destination"))); - const legalOfficerAddress = await this.directoryService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress); + const legalOfficerAddress = await this.legalOfficerService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress); const userData = await this.userAuthorizedAndProtected(origin, legalOfficerAddress); const request = this.vaultTransferRequestFactory.newVaultTransferRequest({ @@ -204,7 +204,7 @@ export class VaultTransferRequestController extends ApiController { decision?: VaultTransferRequestDecision ): Promise<{ legalOfficerEmail: string, userEmail: string | undefined, data: LocalsObject }> { - const legalOfficer = await this.directoryService.get(vaultTransfer.legalOfficerAddress); + const legalOfficer = await this.legalOfficerService.get(vaultTransfer.legalOfficerAddress); const { userIdentity, userPostalAddress } = userPrivateData; return { legalOfficerEmail: legalOfficer.userIdentity.email, diff --git a/src/logion/services/accountrecoverysynchronization.service.ts b/src/logion/services/accountrecoverysynchronization.service.ts index f16e30e0..90117cd8 100644 --- a/src/logion/services/accountrecoverysynchronization.service.ts +++ b/src/logion/services/accountrecoverysynchronization.service.ts @@ -15,7 +15,7 @@ export class AccountRecoverySynchronizer { constructor( private accountRecoveryRepository: AccountRecoveryRepository, private accountRecoveryService: AccountRecoveryService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, ) { } @@ -30,7 +30,7 @@ export class AccountRecoverySynchronizer { const legalOfficerAddresses = Adapters.asArray(extrinsic.call.args['legal_officers']).map(address => Adapters.asString(address)); for (const legalOfficerAddress of legalOfficerAddresses) { const legalOfficer = ValidAccountId.polkadot(legalOfficerAddress); - if (await this.directoryService.isLegalOfficerAddressOnNode(legalOfficer)) { + if (await this.legalOfficerService.isLegalOfficerAddressOnNode(legalOfficer)) { const signer = extrinsic.signer!; const requests = await this.accountRecoveryRepository.findBy(new FetchAccountRecoveryRequestsSpecification({ expectedRequesterAddress: ValidAccountId.polkadot(signer), diff --git a/src/logion/services/locsynchronization.service.ts b/src/logion/services/locsynchronization.service.ts index 16c003e7..f65314dd 100644 --- a/src/logion/services/locsynchronization.service.ts +++ b/src/logion/services/locsynchronization.service.ts @@ -24,7 +24,7 @@ export class LocSynchronizer { private locRequestService: LocRequestService, private collectionService: CollectionService, private notificationService: NotificationService, - private directoryService: LegalOfficerService, + private legalOfficerService: LegalOfficerService, private verifiedIssuerSelectionService: VerifiedIssuerSelectionService, private tokensRecordService: TokensRecordService, ) {} @@ -226,7 +226,7 @@ export class LocSynchronizer { private async notifyIssuerNominatedDismissed(extrinsic: JsonExtrinsic) { const nominated = extrinsic.call.method === "nominateIssuer"; const legalOfficerAddress = ValidAccountId.polkadot(requireDefined(extrinsic.signer)); - if(await this.directoryService.isLegalOfficerAddressOnNode(legalOfficerAddress)) { + if(await this.legalOfficerService.isLegalOfficerAddressOnNode(legalOfficerAddress)) { const issuerAccount = ValidAccountId.polkadot(Adapters.asString(extrinsic.call.args["issuer"])); const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAccount); logger.info("Handling nomination/dismissal of issuer %s", issuerAccount.address); @@ -262,7 +262,7 @@ export class LocSynchronizer { }) { const { legalOfficerAddress, nominated, issuer } = args; try { - const legalOfficer = await this.directoryService.get(legalOfficerAddress); + const legalOfficer = await this.legalOfficerService.get(legalOfficerAddress); const data = { legalOfficer, walletUser: issuer, @@ -279,7 +279,7 @@ export class LocSynchronizer { private async handleIssuerSelectedUnselected(extrinsic: JsonExtrinsic) { const legalOfficerAddress = ValidAccountId.polkadot(requireDefined(extrinsic.signer)); - if(await this.directoryService.isLegalOfficerAddressOnNode(legalOfficerAddress)) { + if(await this.legalOfficerService.isLegalOfficerAddressOnNode(legalOfficerAddress)) { const issuerAccount = ValidAccountId.polkadot(Adapters.asString(extrinsic.call.args["issuer"])); const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAccount); const selected = extrinsic.call.args["selected"] as boolean; @@ -305,7 +305,7 @@ export class LocSynchronizer { }) { const { legalOfficerAddress, selected, locRequest, issuer } = args; try { - const legalOfficer = await this.directoryService.get(legalOfficerAddress); + const legalOfficer = await this.legalOfficerService.get(legalOfficerAddress); const data = { legalOfficer, walletUser: issuer, diff --git a/test/unit/controllers/account_recovery.controller.spec.ts b/test/unit/controllers/account_recovery.controller.spec.ts index 592ad369..24c6ed46 100644 --- a/test/unit/controllers/account_recovery.controller.spec.ts +++ b/test/unit/controllers/account_recovery.controller.spec.ts @@ -105,7 +105,7 @@ function mockRecoveryRequestModel(container: Container, addressToRecover: ValidA }))) .returns(Promise.resolve(root.object())); container.bind(AccountRecoveryRequestFactory).toConstantValue(factory.object()); - mockNotificationAndDirectoryService(container); + mockNotificationAndLegalOfficerService(container); container.bind(AccountRecoveryRequestService).toConstantValue(new NonTransactionalAccountRecoveryRequestService(repository.object())); container.bind(LocRequestAdapter).toConstantValue(mockLocRequestAdapter()); @@ -253,7 +253,7 @@ function mockModelForFetch(container: Container): void { const factory = new Mock(); container.bind(AccountRecoveryRequestFactory).toConstantValue(factory.object()); - mockNotificationAndDirectoryService(container) + mockNotificationAndLegalOfficerService(container) container.bind(AccountRecoveryRequestService).toConstantValue(new NonTransactionalAccountRecoveryRequestService(repository.object())); container.bind(LocRequestAdapter).toConstantValue(mockLocRequestAdapter()); @@ -288,7 +288,7 @@ function mockModelForReview(container: Container): void { const factory = new Mock(); container.bind(AccountRecoveryRequestFactory).toConstantValue(factory.object()); - mockNotificationAndDirectoryService(container) + mockNotificationAndLegalOfficerService(container) container.bind(AccountRecoveryRequestService).toConstantValue(new NonTransactionalAccountRecoveryRequestService(repository.object())); container.bind(LocRequestAdapter).toConstantValue(mockLocRequestAdapter()); @@ -356,7 +356,7 @@ function mockModelForAccept(container: Container, verifies: boolean): void { const factory = new Mock(); container.bind(AccountRecoveryRequestFactory).toConstantValue(factory.object()); - mockNotificationAndDirectoryService(container); + mockNotificationAndLegalOfficerService(container); container.bind(AccountRecoveryRequestService).toConstantValue(new NonTransactionalAccountRecoveryRequestService(repository.object())); container.bind(LocRequestAdapter).toConstantValue(mockLocRequestAdapter()); @@ -471,28 +471,28 @@ function mockModelForReject(container: Container, verifies: boolean): void { const factory = new Mock(); container.bind(AccountRecoveryRequestFactory).toConstantValue(factory.object()); - mockNotificationAndDirectoryService(container); + mockNotificationAndLegalOfficerService(container); container.bind(AccountRecoveryRequestService).toConstantValue(new NonTransactionalAccountRecoveryRequestService(repository.object())); container.bind(LocRequestAdapter).toConstantValue(mockLocRequestAdapter()); container.bind(LocRequestRepository).toConstantValue(mockLocRequestRepository()); } -function mockNotificationAndDirectoryService(container: Container) { +function mockNotificationAndLegalOfficerService(container: Container) { notificationService = new Mock(); notificationService .setup(instance => instance.notify(It.IsAny(), It.IsAny