Skip to content
Snippets Groups Projects
Verified Commit 9b7dfd68 authored by Konstantin Tsabolov's avatar Konstantin Tsabolov
Browse files

chore: remove attestation manager

parent ebb39da2
Branches chore/remove-attestation-manager
No related tags found
No related merge requests found
Showing
with 0 additions and 2254 deletions
This diff is collapsed.
import schemaAgentDto from '../../../schemas/tests/stubs/schema-from-agent-dto.js';
import credentialDto from '../stubs/credential-dto.js';
import credentialTypeDto from '../stubs/credential-type-dto.js';
const AttestationServiceMock = jest.fn().mockReturnValue({
createOfferCredential: jest.fn().mockReturnValue({}),
acceptRequestCredential: jest.fn().mockReturnValue({}),
findCredentialById: jest.fn().mockReturnValue(credentialDto()),
createCredentialsType: jest.fn().mockReturnValue(credentialTypeDto()),
getPrincipalMemberShipCredentials: jest
.fn()
.mockReturnValue(credentialTypeDto()),
createCredential: jest.fn().mockReturnValue(credentialDto()),
updateCredential: jest.fn().mockReturnValue(credentialDto()),
issueMemberCredentials: jest.fn().mockReturnValue({}),
getSchemaAndAttributesBySchemaIDFromLedger: jest
.fn()
.mockReturnValue(schemaAgentDto),
});
export default AttestationServiceMock;
import type { ResponseType } from '../../common/response.js';
import type CredentialDto from '../entities/credential.entity.js';
import type CredentialStateDto from '../entities/credential.state.entity.js';
import type CredentialTypeDto from '../entities/credentialType.entity.js';
import type GetCredentialParams from '../entities/get.credential.params.js';
import type GetCredentialQuery from '../entities/get.credential.query.js';
import type { TestingModule } from '@nestjs/testing';
import type { Response } from 'express';
import { HttpStatus } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
import { createResponse } from 'node-mocks-http';
import { NATSServices } from '../../common/constants.js';
import CredentialDefService from '../../credentialDef/services/service.js';
import CredentialDefServiceMock from '../../credentialDef/tests/__mocks__/service.js';
import SchemasService from '../../schemas/services/service.js';
import SchemasServiceMock from '../../schemas/tests/__mocks__/service.js';
import UserInfoService from '../../userInfo/services/service.js';
import UserInfoServiceMock from '../../userInfo/tests/__mocks__/service.js';
import AttestationController from '../controller/controller.js';
import AttestationService from '../services/service.js';
import AttestationServiceMock from './__mocks__/service.js';
import credentialDto from './stubs/credential-dto.js';
import credentialStateDto from './stubs/credential-state-dto.js';
import credentialTypeDto from './stubs/credential-type-dto.js';
describe('AttestationController', () => {
let attestationController: AttestationController;
let attestationService: AttestationService;
beforeEach(async () => {
const AttestationServiceProvider = {
provide: AttestationService,
useFactory: AttestationServiceMock,
};
const CredentialDefServiceProvider = {
provide: CredentialDefService,
useFactory: CredentialDefServiceMock,
};
const UserInfoServiceProvider = {
provide: UserInfoService,
useFactory: UserInfoServiceMock,
};
const SchemasServiceProvider = {
provide: SchemasService,
useFactory: SchemasServiceMock,
};
const module: TestingModule = await Test.createTestingModule({
imports: [
ClientsModule.register([
{
name: NATSServices.SERVICE_NAME,
transport: Transport.NATS,
},
]),
],
controllers: [AttestationController],
providers: [
AttestationServiceProvider,
CredentialDefServiceProvider,
UserInfoServiceProvider,
SchemasServiceProvider,
ConfigService,
],
}).compile();
attestationController = module.get<AttestationController>(
AttestationController,
);
attestationService = module.get<AttestationService>(AttestationService);
jest.clearAllMocks();
});
it('should be defined', () => {
expect(attestationController).toBeDefined();
});
// describe('createOfferCredential()', () => {
// let attestationResponse: Response<string, Record<string, any>>;
// beforeEach(async () => {
// const response = httpMocks.createResponse();
// attestationResponse = await attestationController.createOfferCredential(
// offerCredentialDto(),
// response,
// );
// });
// it('should call createOfferCredential() from service', async () => {
// expect(attestationService.createOfferCredential).toHaveBeenCalled();
// });
// it('should retrieve created credential', async () => {
// expect(
// attestationService.createOfferCredential(offerCredentialDto()),
// ).not.toBe(null);
// });
// it(`should retrieve HTTP status created(${HttpStatus.CREATED})`, async () => {
// expect(attestationResponse?.statusCode).toEqual(HttpStatus.CREATED);
// });
// });
describe('acceptOfferCredential()', () => {
let attestationResponse: ResponseType;
let query: { credentialId: string };
beforeEach(async () => {
query = {
credentialId: credentialDto().credentialId,
};
attestationResponse =
await attestationController.acceptOfferCredential(query);
});
it('should call acceptRequestCredential() from service', async () => {
expect(attestationService.acceptRequestCredential).toHaveBeenCalled();
});
it('should retrieve created credential', async () => {
expect(
attestationService.acceptRequestCredential(
query.credentialId ? query.credentialId : '',
),
).not.toBe(null);
});
it(`should retrieve HTTP status accepted(${HttpStatus.ACCEPTED})`, async () => {
expect(attestationResponse?.statusCode).toEqual(HttpStatus.ACCEPTED);
});
});
describe('webHookCredentials()', () => {
let attestationResponse: ResponseType;
let body: { credentialRecord: CredentialStateDto };
let credentialObj: CredentialDto;
beforeEach(async () => {
body = { credentialRecord: credentialStateDto() };
credentialObj = {
credentialId: body.credentialRecord.id,
state: body.credentialRecord.state,
connectionId: body.credentialRecord.connectionId,
credDefId:
body.credentialRecord.metadata['_internal/indyCredential']
.credentialDefinitionId,
threadId: body.credentialRecord.threadId,
};
attestationResponse =
await attestationController.webHookCredentials(body);
});
it('should call createCredential() from service', async () => {
expect(attestationService.createCredential).toHaveBeenCalled();
});
it('should retrieve created credential', async () => {
expect(attestationService.createCredential(credentialObj)).toEqual(
credentialDto(),
);
});
it(`should retrieve HTTP status accepted(${HttpStatus.CREATED})`, async () => {
expect(attestationResponse?.statusCode).toEqual(HttpStatus.CREATED);
});
});
describe('getCredential()', () => {
let attestationResponse: Response<string, Record<string, unknown>>;
let params: GetCredentialParams;
let query: GetCredentialQuery;
beforeEach(async () => {
params = { id: credentialDto().credentialId };
query = {
state: credentialDto().state,
};
const response = createResponse();
attestationResponse = await attestationController.getCredential(
params,
query,
response,
);
});
it('should call findCredentialById() from service', async () => {
expect(attestationService.findCredentialById).toHaveBeenCalled();
});
it('should retrieve credential', async () => {
expect(attestationService.findCredentialById(params.id)).toEqual(
credentialDto(),
);
});
it(`should retrieve HTTP status OK(${HttpStatus.OK})`, async () => {
expect(attestationResponse?.statusCode).toEqual(HttpStatus.OK);
});
});
// describe('offerMemberShipCredentials()', () => {
// let data: {
// status: string;
// connectionId: string;
// theirLabel: string;
// participantDID: string;
// theirDid: string;
// };
// let attestationResponse: ResponseType;
// beforeEach(async () => {
// data = {
// status: 'status',
// connectionId: credentialDto().connectionId,
// theirLabel: credentialDto().principalDid || '',
// participantDID,
// theirDid: credentialDto().principalDid || '',
// };
// attestationResponse =
// await attestationController.offerMemberShipCredentials(data);
// });
// it('should call issueMemberCredentials() from service', async () => {
// expect(attestationService.issueMemberCredentials).toHaveBeenCalled();
// });
// it('should retrieve created credential', async () => {
// expect(
// attestationService.issueMemberCredentials({
// ...data,
// credDefId: credentialDto().credDefId,
// attributes: offerCredentialDto().attributes,
// autoAcceptCredential: offerCredentialDto().autoAcceptCredential,
// }),
// ).not.toBe(null);
// });
// it(`should retrieve HTTP status accepted(${HttpStatus.OK})`, async () => {
// expect(attestationResponse?.statusCode).toEqual(HttpStatus.OK);
// });
// });
describe('createCredentialType()', () => {
let attestationResponse: ResponseType;
let body: CredentialTypeDto;
beforeEach(async () => {
body = credentialTypeDto();
attestationResponse =
await attestationController.createCredentialType(body);
});
it('should call createCredentialsType() from service', async () => {
expect(attestationService.createCredentialsType).toHaveBeenCalled();
});
it('should retrieve created updated credential-type', async () => {
expect(attestationService.createCredentialsType(body)).toEqual(
credentialTypeDto(),
);
});
it(`should retrieve HTTP status created(${HttpStatus.CREATED})`, async () => {
expect(attestationResponse?.statusCode).toEqual(HttpStatus.CREATED);
});
});
// describe('getCredential()', () => {
// let attestationResponse: Response<string, Record<string, any>>;
// let query: { credentialId: string; participantId: string };
// beforeEach(async () => {
// query = {
// credentialId: credentialDto().credentialId,
// participantId: credentialDto().participantId || '',
// };
// attestationResponse = await attestationController.acceptOfferCredential(query);
// });
// });
});
import type { TestingModule } from '@nestjs/testing';
import { HttpModule } from '@nestjs/axios';
import { Test } from '@nestjs/testing';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js';
import RestClientServiceMock from '../../client/tests/__mocks__/rest.client.js';
import CredentialDefService from '../../credentialDef/services/service.js';
import CredentialDefServiceMock from '../../credentialDef/tests/__mocks__/service.js';
import PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import AttestationModule from '../module.js';
import AttestationService from '../services/service.js';
import AttestationServiceMock from './__mocks__/service.js';
describe('AttestationModule', () => {
let attestationModule: AttestationModule;
const AttestationServiceProvider = {
provide: AttestationService,
useFactory: AttestationServiceMock,
};
const CredentialDefServiceProvider = {
provide: CredentialDefService,
useFactory: CredentialDefServiceMock,
};
const PrismaServiceProvider = {
provide: PrismaService,
useFactory: PrismaServiceMock,
};
const NatsClientServiceProvider = {
provide: NatsClientService,
useFactory: NatsClientServiceMock,
};
const RestClientServiceProvider = {
provide: RestClientService,
useFactory: RestClientServiceMock,
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
providers: [
AttestationModule,
AttestationServiceProvider,
CredentialDefServiceProvider,
PrismaServiceProvider,
NatsClientServiceProvider,
RestClientServiceProvider,
],
}).compile();
attestationModule = module.get<AttestationModule>(AttestationModule);
});
it('should be defined', () => {
expect(attestationModule).toBeDefined();
});
});
This diff is collapsed.
import type CredentialDto from '../../entities/credential.entity.js';
import credDefStub from '../../../credentialDef/tests/stubs/credDef.stub.js';
import AttestationService from '../../services/service.js';
const credentialDto = (): CredentialDto => ({
credentialId: 'credential-id',
credDefId: credDefStub().id,
principalDid: 'principal-did',
threadId: 'thread-id',
state: AttestationService.status.OFFER_SENT,
connectionId: 'connection-id',
});
export default credentialDto;
import type CredentialStateDto from '../../entities/credential.state.entity.js';
import credDefStub from '../../../credentialDef/tests/stubs/credDef.stub.js';
import credentialDto from './credential-dto.js';
const credentialStateDto = (): CredentialStateDto => ({
id: 'credential-state-id',
metadata: {
'_internal/indyCredential': {
credentialDefinitionId: credentialDto().credDefId,
schemaId: credDefStub().schemaID,
},
},
credDefId: credentialDto().credDefId,
state: credentialDto().state,
threadId: 'thread-id',
connectionId: credentialDto().connectionId,
});
export default credentialStateDto;
import type CredentialTypeDto from '../../entities/credentialType.entity.js';
import schemaDto from '../../../schemas/tests/stubs/schema-dto.js';
const credentialsTypeDto = (): CredentialTypeDto => ({
id: 'credential-type-id',
schemaId: schemaDto().schemaID,
type: 'type',
});
export default credentialsTypeDto;
import type OfferCredentialDto from '../../entities/entity.js';
import schemaDto from '../../../schemas/tests/stubs/schema-dto.js';
import credentialDto from './credential-dto.js';
const offerCredentialDto = (): OfferCredentialDto => ({
connectionId: credentialDto().connectionId,
credentialDefinitionId: credentialDto().credDefId,
comment: 'Test Comment!!',
attributes: schemaDto().attributes.map((attr: string) => ({
name: attr,
value: attr,
})),
autoAcceptCredential: 'never',
});
export default offerCredentialDto;
const participantDID = 'participant-did';
export default participantDID;
This diff is collapsed.
This diff is collapsed.
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import PrismaService from './prisma.service.js';
@Module({
imports: [ConfigModule],
controllers: [],
providers: [PrismaService],
exports: [PrismaService],
})
export default class PrismaModule {}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment