Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shadrach-tayo committed Jan 10, 2025
1 parent 776b5e5 commit e05efa1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 3 additions & 1 deletion desci-server/src/controllers/attestations/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const removeClaim = async (req: RequestWithUser, res: Response, _next: Ne
: await attestationService.unClaimAttestation(claim.id);

// trigger update radar entry
await communityService.addToRadar(claim.desciCommunityId, claim.nodeUuid);
await communityService.removeFromRadar(claim.desciCommunityId, claim.nodeUuid);

await saveInteraction(req, ActionType.REVOKE_CLAIM, body);

Expand Down Expand Up @@ -191,6 +191,8 @@ export const claimEntryRequirements = async (req: Request, res: Response, _next:
nodeUuid: uuid,
attestations: claims,
});
// trigger update radar entry
await communityService.addToRadar(communityId, uuid);

await saveInteraction(req, ActionType.CLAIM_ENTRY_ATTESTATIONS, {
communityId,
Expand Down
1 change: 1 addition & 0 deletions desci-server/src/controllers/communities/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const getCommunityNodeDetails = async (
uuid: true,
title: true,
NodeCover: true,
dpidAlias: true,
},
});

Expand Down
11 changes: 9 additions & 2 deletions desci-server/src/services/Communities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,15 @@ export class CommunityService {

if (!isEntriesClaimed) return undefined;

const radarEntry = await prisma.communityRadarEntry.create({
data: {
const radarEntry = await prisma.communityRadarEntry.upsert({
where: {
nodeUuid_desciCommunityId: { desciCommunityId, nodeUuid },
},
create: {
nodeUuid,
desciCommunityId,
},
update: {
desciCommunityId,
nodeUuid,
},
Expand Down
36 changes: 25 additions & 11 deletions desci-server/test/integration/Attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import request from 'supertest';

import { prisma } from '../../src/client.js';
import { NodeAttestationFragment } from '../../src/controllers/attestations/show.js';
import { Engagement, NodeRadar, NodeRadarItem } from '../../src/controllers/communities/types.js';
import { Engagement, NodeRadar, NodeRadarEntry, NodeRadarItem } from '../../src/controllers/communities/types.js';
import {
DuplicateReactionError,
DuplicateVerificationError,
Expand Down Expand Up @@ -129,7 +129,7 @@ const clearDatabase = async () => {
await prisma.$queryRaw`TRUNCATE TABLE "Node" CASCADE;`;
};

describe('Attestations Service', async () => {
describe.only('Attestations Service', async () => {
let baseManifest: ResearchObjectV1;
let baseManifestCid: string;
let users: User[];
Expand Down Expand Up @@ -264,6 +264,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node.uuid);

// publish new node version
nodeVersion2 = await prisma.nodeVersion.create({
Expand Down Expand Up @@ -1567,7 +1569,7 @@ describe('Attestations Service', async () => {
let fairMetadataAttestationVersion: AttestationVersion;

let res: request.Response;
let apiResponse: NodeRadar[];
let apiResponse: NodeRadarEntry[];

before(async () => {
node = nodes[0];
Expand Down Expand Up @@ -1621,6 +1623,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node.uuid);

// claim all entry requirements for node 2
[claim2, openDataAttestationClaim2] = await attestationService.claimAttestations({
Expand All @@ -1639,6 +1643,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author2.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node2.uuid);

// claim all entry requirements for node 3
[claim3, openDataAttestationClaim3] = await attestationService.claimAttestations({
Expand All @@ -1657,6 +1663,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author3.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node3.uuid);

// verify both claims for node 1
await attestationService.verifyClaim(claim.id, users[3].id);
Expand Down Expand Up @@ -1696,9 +1704,9 @@ describe('Attestations Service', async () => {
it('should return nodes in radar in ASC order of verified engagements sorted by last submission/claim date', async () => {
expect(res.status).to.equal(200);
expect(apiResponse.length).to.equal(3);
expect(apiResponse[0].nodeDpid10).to.be.equal('2');
expect(apiResponse[1].nodeDpid10).to.be.equal('3');
expect(apiResponse[2].nodeDpid10).to.be.equal('1');
expect(apiResponse[0].nodeUuid).to.be.equal(node2.uuid);
expect(apiResponse[1].nodeUuid).to.be.equal(node3.uuid);
expect(apiResponse[2].nodeUuid).to.be.equal(node.uuid);
});
});

Expand Down Expand Up @@ -2003,6 +2011,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node.uuid);

[claim2, openDataAttestationClaim2] = await attestationService.claimAttestations({
attestations: [
Expand All @@ -2020,6 +2030,8 @@ describe('Attestations Service', async () => {
nodeVersion,
claimerId: author2.id,
});
// trigger update radar entry
await communityService.addToRadar(desciCommunity.id, node2.uuid);

// verify both claims for node 1
await attestationService.verifyClaim(claim.id, users[1].id);
Expand Down Expand Up @@ -2074,24 +2086,26 @@ describe('Attestations Service', async () => {
expect(communityEngagementSignal.reactions).to.equal(0);
});

it('should remove node from radar and curated if an entry attestation claim is revoked', async () => {
it('should remove node from radar and curated if claim is revoked', async () => {
const res1 = await request(app)
.get(`/v1/communities/${desciCommunity.id}/radar`)
.set('authorization', authHeaderVal)
.field('communityId', desciCommunity.id);
const radar = res1.body.data.data as NodeRadar[];
console.log('radar', res1.body);
const radar = res1.body.data.data as NodeRadarEntry[];
expect(res1.status).to.equal(200);
expect(radar.length).to.equal(1);
const radarNode = radar[0];
expect(radarNode.nodeDpid10).to.be.equal('2');
expect(radarNode.nodeuuid).to.be.equal(node2.uuid);
// expect(radarNode.nodeDpid10).to.be.equal('2');
expect(radarNode.nodeUuid).to.be.equal(node2.uuid);

const res = await request(app)
.get(`/v1/communities/${desciCommunity.id}/feed`)
.set('authorization', authHeaderVal)
.field('communityId', desciCommunity.id);

const curatedNodes = res.body.data as NodeRadar[];
console.log('feed', res.body);
const curatedNodes = res.body.data.data as NodeRadarEntry[];
expect(res.status).to.equal(200);
expect(curatedNodes.length).to.equal(0);
});
Expand Down

0 comments on commit e05efa1

Please sign in to comment.