Skip to content

Commit

Permalink
Merge pull request #185 from logion-network/feature/fix-list-vtp-locs
Browse files Browse the repository at this point in the history
Fix list of VTP LOCs
  • Loading branch information
gdethier authored Nov 25, 2022
2 parents e795dbb + 81b8ca2 commit b71c8c7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/logion/controllers/verifiedthirdparty.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ export class VerifiedThirdPartyController extends ApiController {
}

const verifiedThirdPartyLocId = identityLocs[0].id!;
const selections = await this.verifiedThirdPartySelectionRepository.findBy({ verifiedThirdPartyLocId });
const selections = await this.verifiedThirdPartySelectionRepository.findBy({
verifiedThirdPartyLocId,
selected: true,
});
const requests = [];
for(const selection of selections) {
const request = await this.locRequestRepository.findById(selection.id.locRequestId);
Expand Down
8 changes: 6 additions & 2 deletions src/logion/model/verifiedthirdpartyselection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class VerifiedThirdPartySelectionAggregateRoot {
selected?: boolean;
}

export interface FindBySpecification extends Partial<VerifiedThirdPartySelectionId> {
selected?: boolean;
}

@injectable()
export class VerifiedThirdPartySelectionRepository {

Expand All @@ -49,8 +53,8 @@ export class VerifiedThirdPartySelectionRepository {
return await this.repository.findOneBy(id);
}

async findBy(partialId: Partial<VerifiedThirdPartySelectionId>): Promise<VerifiedThirdPartySelectionAggregateRoot[]> {
return this.repository.findBy(partialId);
async findBy(spec: FindBySpecification): Promise<VerifiedThirdPartySelectionAggregateRoot[]> {
return this.repository.findBy(spec);
}

async unselectAll(verifiedThirdPartyLocId: string) {
Expand Down
12 changes: 10 additions & 2 deletions test/integration/model/verifiedthirdpartyselection.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe("VerifiedThirdPartySelectionRepository - read", () => {
const nominations = await repository.findBy({ verifiedThirdPartyLocId: "a4eb8352-a032-44a6-8087-c95a40da0744" });
expect(nominations.length).toBe(1);
});

it("finds selected only", async () => {
const nominations = await repository.findBy({
verifiedThirdPartyLocId: "f2b114f4-1196-4027-9972-e6741f868f0c",
selected: true,
});
expect(nominations.length).toBe(1);
});
});

describe("VerifiedThirdPartySelectionRepository - write", () => {
Expand All @@ -50,8 +58,8 @@ describe("VerifiedThirdPartySelectionRepository - write", () => {
await disconnect();
});

it("deletes by VTP LOC ID", async () => {
it("unselects by VTP LOC ID", async () => {
await repository.unselectAll("a4eb8352-a032-44a6-8087-c95a40da0744");
checkNumOfRows(`SELECT * FROM vtp_selection WHERE selected IS TRUE`, 2);
checkNumOfRows(`SELECT * FROM vtp_selection WHERE vtp_loc_id = 'a4eb8352-a032-44a6-8087-c95a40da0744' AND selected IS TRUE`, 0);
});
});
4 changes: 2 additions & 2 deletions test/integration/model/vtp_selection.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO vtp_selection (loc_request_id, vtp_loc_id)
VALUES ('a7b80f86-1c51-4aff-ba32-d8361bb462b1', 'a4eb8352-a032-44a6-8087-c95a40da0744');
INSERT INTO vtp_selection (loc_request_id, vtp_loc_id)
VALUES ('a7b80f86-1c51-4aff-ba32-d8361bb462b1', 'f2b114f4-1196-4027-9972-e6741f868f0c');
INSERT INTO vtp_selection (loc_request_id, vtp_loc_id, selected)
VALUES ('a7b80f86-1c51-4aff-ba32-d8361bb462b1', 'f2b114f4-1196-4027-9972-e6741f868f0c', false);
INSERT INTO vtp_selection (loc_request_id, vtp_loc_id)
VALUES ('eadcfcc9-ae0a-4de6-be21-8153f2159662', 'f2b114f4-1196-4027-9972-e6741f868f0c');
5 changes: 3 additions & 2 deletions test/unit/controllers/verifiedthirdparty.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { It, Mock } from "moq.ts";
import request from "supertest";
import { VerifiedThirdPartyController } from "../../../src/logion/controllers/verifiedthirdparty.controller";
import { buildMocks, buildMocksForFetch, buildMocksForUpdate, mockPolkadotIdentityLoc, mockRequestWithId, REQUEST_ID, setupRequest, userIdentities } from "./locrequest.controller.shared";
import { VerifiedThirdPartySelectionAggregateRoot, VerifiedThirdPartySelectionId, VerifiedThirdPartySelectionRepository } from "../../../src/logion/model/verifiedthirdpartyselection.model";
import { FindBySpecification, VerifiedThirdPartySelectionAggregateRoot, VerifiedThirdPartySelectionId, VerifiedThirdPartySelectionRepository } from "../../../src/logion/model/verifiedthirdpartyselection.model";
import { FetchLocRequestsSpecification, LocRequestAggregateRoot, LocRequestDescription, LocRequestRepository } from "../../../src/logion/model/locrequest.model";
import { ALICE } from "../../helpers/addresses";
import { NotificationService } from "../../../src/logion/services/notification.service";
Expand Down Expand Up @@ -225,9 +225,10 @@ function mockModelForGetVerifiedThirdPartyLocRequests(container: Container) {
locRequestId,
verifiedThirdPartyLocId,
});
verifiedThirdPartySelectionRepository.setup(instance => instance.findBy(It.Is<Partial<VerifiedThirdPartySelectionId>>(id =>
verifiedThirdPartySelectionRepository.setup(instance => instance.findBy(It.Is<FindBySpecification>(id =>
id.verifiedThirdPartyLocId === SELECTION_ID.verifiedThirdPartyLocId
&& id.locRequestId === undefined
&& id.selected === true
))).returnsAsync([ selection.object() ]);

const locWithSelection = new Mock<LocRequestAggregateRoot>();
Expand Down

0 comments on commit b71c8c7

Please sign in to comment.