Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • eclipse/xfsc/ocm/ocm-engine
  • zdravko61/ocm-engine
  • mjuergenscg/ocm-engine
  • tsabolov/ocm-engine
  • mikesell/ocm-engine
5 results
Show changes
Showing
with 0 additions and 994 deletions
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';
export default class SchemaDto {
@IsString()
@IsNotEmpty()
public id: string;
@IsString()
@IsNotEmpty()
public schemaID: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
public name: string;
@IsString()
@ApiProperty()
public createdBy: string;
@IsString()
public createdDate: Date;
@IsString()
public updatedBy?: string;
@IsString()
public updatedDate: Date;
@IsString()
@ApiProperty()
public version: string;
@IsString()
@ApiProperty()
public attributes: string[];
@IsString()
public pageSize?: string;
@IsString()
public page?: string;
@IsString()
@ApiPropertyOptional()
public type?: string;
}
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import NatsClientService from '../client/nats.client.js';
import RestClientService from '../client/rest.client.js';
import { NATSServices } from '../common/constants.js';
import config from '../config/config.js';
import PrismaService from '../prisma/prisma.service.js';
import SchemasController from './controller/controller.js';
import SchemasService from './services/service.js';
@Module({
imports: [
HttpModule,
ClientsModule.register([
{
name: NATSServices.SERVICE_NAME,
transport: Transport.NATS,
options: {
servers: [config().nats.url as string],
},
},
]),
],
controllers: [SchemasController],
providers: [
SchemasService,
PrismaService,
NatsClientService,
RestClientService,
],
})
export default class SchemasModule {}
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import PrismaService from '../../prisma/prisma.service.js';
@Injectable()
export default class SchemaRepository {
public constructor(private readonly prismaService: PrismaService) {}
public async createSchema(data: Prisma.SchemaCreateInput) {
return this.prismaService.schema.create({
data,
include: {
attribute: {
select: {
name: true,
},
},
},
});
}
public async findSchemas(params: {
skip?: number;
take?: number;
cursor?: Prisma.SchemaWhereUniqueInput;
where?: Prisma.SchemaWhereInput;
orderBy?: Prisma.SchemaOrderByWithRelationInput;
}) {
const { skip, take, cursor, where, orderBy } = params;
return this.prismaService.$transaction([
this.prismaService.schema.count({
where,
}),
this.prismaService.schema.findMany({
skip,
take,
cursor,
where,
orderBy,
include: {
attribute: {
select: {
name: true,
},
},
},
}),
]);
}
public async findUniqueSchema(params: {
where: Prisma.SchemaWhereUniqueInput;
}) {
const { where } = params;
return this.prismaService.schema.findUnique({
where,
include: {
attribute: {
select: {
name: true,
},
},
},
});
}
}
import type SchemaDto from '../entities/schema-entity.js';
import type { Prisma } from '@prisma/client';
import { BadRequestException, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js';
import PrismaService from '../../prisma/prisma.service.js';
import pagination from '../../utils/pagination.js';
import SchemaRepository from '../repository/schema.respository.js';
@Injectable()
export default class SchemasService {
private schemaRepository: SchemaRepository;
private credentialTypeRepository: CredentialTypeRepository;
public constructor(
private readonly prismaService: PrismaService,
private readonly restClient: RestClientService,
private readonly natsClient: NatsClientService,
private readonly configService: ConfigService,
) {
this.schemaRepository = new SchemaRepository(this.prismaService);
this.credentialTypeRepository = new CredentialTypeRepository(
this.prismaService,
);
}
public async createSchemas(schema: SchemaDto) {
const query: {
schemaID: string;
name: string;
createdBy: string;
attribute: {
create: {
schemaID: string;
name: string;
createdBy: string;
}[];
};
} = {
schemaID: schema.schemaID,
name: schema.name,
createdBy: schema.createdBy,
attribute: {
create: [],
},
};
schema.attributes.forEach((element) => {
query.attribute.create.push({
schemaID: schema.schemaID,
name: element,
createdBy: schema.createdBy,
});
});
if (
schema.type &&
typeof schema.type === 'string' &&
schema.type.trim().length > 0
) {
await this.credentialTypeRepository.createOrUpdateCredentialsType({
schemaId: query.schemaID,
type: schema.type.trim(),
});
}
return this.schemaRepository.createSchema(query);
}
public async findSchemas(pageSize: number, page: number) {
let query: {
skip?: number;
take?: number;
cursor?: Prisma.SchemaWhereUniqueInput;
where?: Prisma.SchemaWhereInput;
orderBy?: Prisma.SchemaOrderByWithRelationInput;
} = {};
query = { ...query, ...pagination(pageSize, page) };
return this.schemaRepository.findSchemas(query);
}
public async findSchemasById(id: string) {
return this.schemaRepository.findSchemas({
where: { schemaID: id },
});
}
public async getDidsForSchemasId(id: string) {
return this.prismaService.schema.findMany({
where: { schemaID: id },
include: {
attribute: true,
credential_defs: {
include: {
credentials: {
distinct: 'principalDid',
},
},
},
},
});
}
public findBySchemaId(schemaID: string) {
const query = { where: { schemaID } };
return this.schemaRepository.findUniqueSchema(query);
}
public async checkSchemasByNameAndVersion(schemaDto: SchemaDto) {
return this.schemaRepository.findSchemas({
where: {
schemaID: {
endsWith: `:${schemaDto.version}`,
mode: 'insensitive', // Default value: default
},
name: {
equals: schemaDto.name, // Default mode
},
},
});
}
public async createSchemaOnLedger(schemaDto: SchemaDto) {
const agentUrl = this.configService.get('agent.AGENT_URL');
const responseData = await this.restClient.post(
`${agentUrl}/schemas/`,
schemaDto,
);
return responseData;
}
public async getSchemaAndAttributesBySchemaIDFromLedger(schemaID: string) {
const agentUrl = this.configService.get('agent.AGENT_URL');
const responseData = await this.restClient.get(
`${agentUrl}/schemas/${schemaID}`,
);
if (!responseData?.id) {
throw new BadRequestException('Invalid schema ID');
}
return responseData;
}
}
import schemaDto from '../stubs/schema-dto.js';
const SchemasServiceMock = jest.fn().mockReturnValue({
findSchemas: jest.fn().mockReturnValue([1, [schemaDto()]]),
findSchemasById: jest.fn().mockReturnValue([1, [schemaDto()]]),
findBySchemaId: jest.fn().mockReturnValue(schemaDto()),
checkSchemasByNameAndVersion: jest.fn().mockReturnValue([0, []]),
createSchemaOnLedger: jest.fn().mockReturnValue({ id: schemaDto().schemaID }),
createSchemas: jest.fn().mockReturnValue(schemaDto()),
});
export default SchemasServiceMock;
import type SchemaDto from '../entities/schema-entity.js';
import type { TestingModule } from '@nestjs/testing';
import type { Response } from 'express';
import { HttpStatus } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { createResponse } from 'node-mocks-http';
import SchemasController from '../controller/controller.js';
import SchemasService from '../services/service.js';
import SchemasServiceMock from './__mocks__/service.js';
import schemaDto from './stubs/schema-dto.js';
describe('SchemasController', () => {
let schemasController: SchemasController;
let schemasService: SchemasService;
beforeEach(async () => {
const SchemasServiceProvider = {
provide: SchemasService,
useFactory: SchemasServiceMock,
};
const module: TestingModule = await Test.createTestingModule({
controllers: [SchemasController],
providers: [SchemasServiceProvider],
}).compile();
schemasController = module.get<SchemasController>(SchemasController);
schemasService = module.get<SchemasService>(SchemasService);
jest.clearAllMocks();
});
it('should be defined', () => {
expect(schemasController).toBeDefined();
});
describe('findSchemas()', () => {
let schemasResponse: Response<string, Record<string, unknown>>;
let query: SchemaDto;
let response: Response<string, Record<string, unknown>>;
beforeEach(async () => {
query = schemaDto();
response = createResponse();
schemasResponse = await schemasController.findSchemas(query, response);
});
it('should call findSchemas() from service', async () => {
expect(schemasService.findSchemas).toHaveBeenCalled();
});
it('should retrieve schemas by query', async () => {
expect(
schemasService.findSchemas(
query.pageSize ? parseInt(query.pageSize, 10) : 10,
query.page ? parseInt(query.page, 10) : 0,
),
).toEqual([1, [schemaDto()]]);
});
it(`should retrieve HTTP status OK(${HttpStatus.OK})`, async () => {
expect(schemasResponse?.statusCode).toEqual(HttpStatus.OK);
});
});
describe('findSchemasById()', () => {
let schemasResponse: Response<string, Record<string, unknown>>;
let id: string;
let response: Response<string, Record<string, unknown>>;
beforeEach(async () => {
id = schemaDto().schemaID || '';
response = createResponse();
schemasResponse = await schemasController.findSchemasById(id, response);
});
it('should call findSchemasById() from service', async () => {
expect(schemasService.findSchemasById).toHaveBeenCalled();
});
it('should retrieve schema by ID', async () => {
expect(schemasService.findSchemasById(id)).toEqual([1, [schemaDto()]]);
});
it(`should retrieve HTTP status OK(${HttpStatus.OK})`, async () => {
expect(schemasResponse?.statusCode).toEqual(HttpStatus.OK);
});
});
describe('createSchema()', () => {
let schemasResponse: Response<string, Record<string, unknown>>;
let createSchema: SchemaDto;
let response: Response<string, Record<string, unknown>>;
beforeEach(async () => {
createSchema = schemaDto();
response = createResponse();
schemasResponse = await schemasController.createSchema(
createSchema,
response,
);
});
it('should call checkSchemasByNameAndVersion() from service', async () => {
expect(schemasService.checkSchemasByNameAndVersion).toHaveBeenCalled();
});
it('should not retrieve any existing schema', async () => {
expect(
schemasService.checkSchemasByNameAndVersion(createSchema),
).toContain(0);
});
it('should call createSchemaOnLedger() from service', async () => {
expect(schemasService.createSchemaOnLedger).toHaveBeenCalled();
});
it('should retrieve schema with ID', async () => {
expect(schemasService.createSchemaOnLedger(createSchema)).toEqual({
id: schemaDto().schemaID,
});
});
it('should call createSchemas() from service', async () => {
expect(schemasService.createSchemas).toHaveBeenCalled();
});
it('should retrieve created schema', async () => {
expect(schemasService.createSchemas(createSchema)).toEqual(schemaDto());
});
it(`should retrieve HTTP status created(${HttpStatus.CREATED})`, async () => {
expect(schemasResponse?.statusCode).toEqual(HttpStatus.CREATED);
});
});
});
import type { TestingModule } from '@nestjs/testing';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
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 PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import SchemasModule from '../module.js';
import SchemasService from '../services/service.js';
import SchemasServiceMock from './__mocks__/service.js';
describe('SchemasModule', () => {
let schemasModule: SchemasModule;
const SchemasServiceProvider = {
provide: SchemasService,
useFactory: SchemasServiceMock,
};
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: [
SchemasModule,
SchemasServiceProvider,
PrismaServiceProvider,
NatsClientServiceProvider,
RestClientServiceProvider,
ConfigService,
],
}).compile();
schemasModule = module.get<SchemasModule>(SchemasModule);
});
it('should be defined', () => {
expect(schemasModule).toBeDefined();
});
});
import type { ResponseType } from '../../common/response.js';
import type { TestingModule } from '@nestjs/testing';
import type { Schema } from 'joi';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
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 PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import SchemasService from '../services/service.js';
import schemaDto from './stubs/schema-dto.js';
describe('SchemasService', () => {
let schemasService: SchemasService;
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: [
SchemasService,
PrismaServiceProvider,
RestClientServiceProvider,
NatsClientServiceProvider,
ConfigService,
],
}).compile();
schemasService = module.get<SchemasService>(SchemasService);
});
it('should be defined', () => {
expect(schemasService).toBeDefined();
});
describe('createSchemas()', () => {
let schemasResponse: Schema;
beforeEach(async () => {
schemasResponse = await schemasService.createSchemas(schemaDto());
});
it('should call create() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.create).toHaveBeenCalled();
});
it('should retrieve created schema', async () => {
expect(schemasResponse).toEqual([schemaDto()]);
});
});
describe('findSchemas()', () => {
let schemasResponse: Array<number | Schema[]>;
beforeEach(async () => {
const pageSize = parseInt(schemaDto().pageSize || '', 10);
const page = parseInt(schemaDto().page || '', 10);
schemasResponse = await schemasService.findSchemas(pageSize, page);
});
it('should call findMany() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve schemas by participantId', async () => {
expect(schemasResponse).toEqual([1, [schemaDto()]]);
});
});
describe('findSchemasById()', () => {
let schemasResponse: Array<number | Schema[]>;
let id: string;
beforeEach(async () => {
id = schemaDto().schemaID || '';
schemasResponse = await schemasService.findSchemasById(id);
});
it('should call findMany() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve schema by Schema ID', async () => {
expect(schemasResponse).toEqual([1, [schemaDto()]]);
});
});
describe('checkSchemasByNameAndVersion()', () => {
let schemasResponse: Array<number | Schema[]>;
beforeEach(async () => {
schemasResponse =
await schemasService.checkSchemasByNameAndVersion(schemaDto());
});
it('should call findMany() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.findMany).toHaveBeenCalled();
});
it('should call count() from PrismaService.schema', async () => {
expect(PrismaServiceMock().schema.count).toHaveBeenCalled();
});
it('should call $transaction() from PrismaService', async () => {
expect(PrismaServiceMock().$transaction).toHaveBeenCalled();
});
it('should retrieve schemas by Name and Version', async () => {
expect(schemasResponse).toEqual([1, [schemaDto()]]);
});
});
describe('createSchemaOnLedger()', () => {
let schemasResponse: ResponseType;
beforeEach(async () => {
schemasResponse = await schemasService.createSchemaOnLedger(schemaDto());
});
it('should call post() from restClient', async () => {
expect(RestClientServiceMock().post).toHaveBeenCalled();
});
it('should get a response from AFJ', async () => {
expect(schemasResponse).not.toBe(null);
});
});
});
import type SchemaDto from '../../entities/schema-entity.js';
const schemaDto = (): SchemaDto => ({
id: 'schema-db-id',
schemaID: 'schema-ledger-id',
name: 'schema-name',
createdBy: 'created-by',
createdDate: new Date(2022),
updatedBy: 'updated-by',
updatedDate: new Date(2022),
version: '0.0.1',
attributes: ['attr1', 'attr2', 'attr3'],
pageSize: '3',
page: '3',
type: 'testing',
});
export default schemaDto;
import schemaDto from './schema-dto.js';
const schemaAgentDto = {
ver: '1.0',
id: schemaDto().schemaID,
name: schemaDto().name,
version: schemaDto().version,
attrNames: [...schemaDto().attributes, 'expirationDate'],
seqNo: 335519,
};
export default schemaAgentDto;
import { Observable } from 'rxjs';
const HttpServiceMock = jest.fn().mockReturnValue({
post: jest.fn().mockReturnValue(
new Observable((subscriber) => {
subscriber.next({
data: {
sample: 'data',
},
});
subscriber.complete();
}),
),
});
export default HttpServiceMock;
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type { Response } from 'express';
import {
BadRequestException,
Body,
Controller,
HttpException,
HttpStatus,
InternalServerErrorException,
Post,
Res,
Version,
} from '@nestjs/common';
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Prisma } from '@prisma/client';
import { isUUID } from 'class-validator';
import { AutoAcceptCredential } from '../../common/constants.js';
import logger from '../../utils/logger.js';
import UserInfoDto from '../entities/userInfo.entity.js';
import UserInfoService from '../services/service.js';
@ApiTags('userInfo (to be deprecated)')
@Controller('userInfo')
export default class UserInfoController {
public constructor(private readonly userInfoService: UserInfoService) {}
@Version(['1'])
@ApiBody({ type: UserInfoDto })
@Post('')
@ApiOperation({
summary: 'Add user information to a connection',
description:
'This call provides the capability to add any additional information to connection. The format of added data is just a simple json',
})
public async createUserInfo(
@Body() userInfoDto: UserInfoDto,
@Res() response: Response,
) {
try {
logger.info(`UserInfoDto: ${JSON.stringify(UserInfoDto)}`);
const { autoAcceptCredential, connectionId, userInfo } = userInfoDto;
if (!connectionId || !isUUID(connectionId)) {
throw new BadRequestException('Invalid connection ID');
}
if (
autoAcceptCredential &&
autoAcceptCredential in AutoAcceptCredential
) {
throw new BadRequestException('Invalid autoAcceptCredential');
}
if (!userInfo || Object.values(userInfo).length === 0) {
throw new BadRequestException('Invalid userInfo');
}
const res = {
statusCode: HttpStatus.CREATED,
message: 'User info created successfully',
data: await this.userInfoService.createUserInfo(userInfoDto),
};
return response.send(res);
} catch (error: unknown) {
if (error instanceof Prisma.PrismaClientUnknownRequestError) {
throw new InternalServerErrorException(error.message);
} else {
throw new HttpException(
Reflect.get(error || {}, 'message') || 'Internal server error',
Reflect.get(error || {}, 'status') || 500,
);
}
}
}
}
type UserInfo = {
[key: string]: unknown;
};
export default class UpdateUserInfoDto {
public connectionId: string;
public status: string;
public credentialDefinitionId: string;
public userInfo: UserInfo;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
type UserInfo = {
[key: string]: unknown;
};
export default class UserInfoDto {
@IsString()
@IsNotEmpty()
@ApiProperty()
public connectionId: string;
@IsEnum(['always', 'contentApproved', 'never'])
@IsNotEmpty()
@ApiProperty()
public autoAcceptCredential: string;
@IsNotEmpty()
@ApiProperty({ type: {} })
public userInfo: UserInfo;
}
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import NatsClientService from '../client/nats.client.js';
import RestClientService from '../client/rest.client.js';
import { NATSServices } from '../common/constants.js';
import config from '../config/config.js';
import PrismaService from '../prisma/prisma.service.js';
import SchemasService from '../schemas/services/service.js';
import UserInfoController from './controller/controller.js';
import UserInfoService from './services/service.js';
@Module({
imports: [
HttpModule,
ClientsModule.register([
{
name: NATSServices.SERVICE_NAME,
transport: Transport.NATS,
options: {
servers: [config().nats.url as string],
},
},
]),
],
controllers: [UserInfoController],
providers: [
UserInfoService,
PrismaService,
NatsClientService,
RestClientService,
SchemasService,
],
})
export default class UserInfoModule {}
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import PrismaService from '../../prisma/prisma.service.js';
@Injectable()
export default class UserInfoRepository {
public constructor(private readonly prismaService: PrismaService) {}
public async createUserInfo(data: Prisma.UserInfoCreateInput) {
const userInfo = await this.prismaService.userInfo.create({
data,
});
return userInfo;
}
public async updateUserInfo(data: Prisma.UserInfoUncheckedUpdateManyInput) {
const userInfo = await this.prismaService.userInfo.updateMany({
where: {
connectionId: data.connectionId as string,
},
data,
});
return userInfo;
}
public async getUserInfo(params: { where: Prisma.UserInfoWhereInput }) {
const { where } = params;
return this.prismaService.userInfo.findFirst({
where,
});
}
}
import type UpdateUserInfoDto from '../entities/update-unserInfo.dto.js';
import type UserInfoDto from '../entities/userInfo.entity.js';
import { Injectable } from '@nestjs/common';
import PrismaService from '../../prisma/prisma.service.js';
import logger from '../../utils/logger.js';
import UserInfoRepository from '../repository/userInfo.respository.js';
@Injectable()
export default class UserInfoService {
private userInfoRepository: UserInfoRepository;
public constructor(private readonly prismaService: PrismaService) {
this.userInfoRepository = new UserInfoRepository(this.prismaService);
}
public async createUserInfo(userInfoDto: UserInfoDto) {
logger.info(`In user info service, ${JSON.stringify(userInfoDto)}`);
return this.userInfoRepository.createUserInfo({
autoAcceptCredential: userInfoDto.autoAcceptCredential,
connectionId: userInfoDto.connectionId,
userInfo: userInfoDto.userInfo as object,
});
}
public async updateUserInfo(userInfoDto: UpdateUserInfoDto) {
logger.info(`In user info service, ${userInfoDto}`);
return this.userInfoRepository.updateUserInfo({
connectionId: userInfoDto.connectionId,
credentialDefinitionId: userInfoDto.credentialDefinitionId,
status: userInfoDto.status,
userInfo: userInfoDto.userInfo as object,
});
}
public async getUserInfo(connectionId: string) {
logger.info(`In get user info service, ${connectionId}`);
return this.userInfoRepository.getUserInfo({
where: {
connectionId,
},
});
}
}
import userInfo from '../stubs/user-info-dto.stub.js';
const UserInfoServiceMock = jest.fn().mockReturnValue({
createUserInfo: jest.fn().mockReturnValue(userInfo),
updateUserInfo: jest.fn().mockReturnValue(userInfo()),
getUserInfo: jest.fn().mockReturnValue(userInfo()),
});
export default UserInfoServiceMock;
import type UserInfoDto from '../../entities/userInfo.entity.js';
import credentialDto from '../../../issue-credential/tests/stubs/credential-dto.js';
import offerCredentialDto from '../../../issue-credential/tests/stubs/offer-credential-dto.js';
import schemaDto from '../../../schemas/tests/stubs/schema-dto.js';
const userInfo = (): UserInfoDto => ({
autoAcceptCredential: offerCredentialDto().autoAcceptCredential,
connectionId: credentialDto().connectionId,
userInfo: {
...schemaDto().attributes.map((attr: string | symbol | number) => ({
[attr]: attr,
})),
},
});
export default userInfo;
import moment from 'moment';
const calculateExpiry = (expiry: string) => {
if (!expiry || expiry === '-1') return 'NA';
// Adding 'expiryHours' as number of hours to the Credential Definition
const expirationDate = moment().add(Number(expiry), 'h').toDate();
return expirationDate;
};
export default { calculateExpiry };