From c113d95a3cfe8fead64fcc0b070e2c5ee3eba19f Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Thu, 7 Dec 2023 13:56:43 +0100 Subject: [PATCH] fix test, remove not longer used files --- dlt-connector/src/graphql/enum/AddressType.ts | 9 ------- .../src/graphql/enum/CrossGroupType.ts | 7 ----- .../src/graphql/enum/InputTransactionType.ts | 12 +++++++++ .../src/graphql/input/TransactionInput.ts | 27 ------------------- .../resolver/TransactionsResolver.test.ts | 12 ++++----- dlt-connector/src/utils/typeConverter.ts | 2 +- 6 files changed, 19 insertions(+), 50 deletions(-) delete mode 100644 dlt-connector/src/graphql/enum/AddressType.ts delete mode 100644 dlt-connector/src/graphql/enum/CrossGroupType.ts delete mode 100755 dlt-connector/src/graphql/input/TransactionInput.ts diff --git a/dlt-connector/src/graphql/enum/AddressType.ts b/dlt-connector/src/graphql/enum/AddressType.ts deleted file mode 100644 index 26efd2825..000000000 --- a/dlt-connector/src/graphql/enum/AddressType.ts +++ /dev/null @@ -1,9 +0,0 @@ -export enum AddressType { - NONE = 0, // if no address was found - COMMUNITY_HUMAN = 1, // creation account for human - COMMUNITY_GMW = 2, // community public budget account - COMMUNITY_AUF = 3, // community compensation and environment founds account - COMMUNITY_PROJECT = 4, // no creations allowed - SUBACCOUNT = 5, // no creations allowed - CRYPTO_ACCOUNT = 6, // user control his keys, no creations -} diff --git a/dlt-connector/src/graphql/enum/CrossGroupType.ts b/dlt-connector/src/graphql/enum/CrossGroupType.ts deleted file mode 100644 index 13e968509..000000000 --- a/dlt-connector/src/graphql/enum/CrossGroupType.ts +++ /dev/null @@ -1,7 +0,0 @@ -export enum CrossGroupType { - LOCAL = 0, - INBOUND = 1, - OUTBOUND = 2, - // for cross group transaction which haven't a direction like group friend update - // CROSS = 3, -} diff --git a/dlt-connector/src/graphql/enum/InputTransactionType.ts b/dlt-connector/src/graphql/enum/InputTransactionType.ts index 06d1bb44b..f35a26658 100755 --- a/dlt-connector/src/graphql/enum/InputTransactionType.ts +++ b/dlt-connector/src/graphql/enum/InputTransactionType.ts @@ -1,3 +1,4 @@ +import { LogError } from '@/server/LogError' import { registerEnumType } from 'type-graphql' export enum InputTransactionType { @@ -10,3 +11,14 @@ registerEnumType(InputTransactionType, { name: 'InputTransactionType', // this one is mandatory description: 'Type of the transaction', // this one is optional }) + +// from ChatGPT +export function getTransactionTypeString(id: InputTransactionType): string { + const key = Object.keys(InputTransactionType).find( + (key) => InputTransactionType[key as keyof typeof InputTransactionType] === id, + ) + if (key === undefined) { + throw new LogError('invalid transaction type id: ' + id.toString()) + } + return key +} diff --git a/dlt-connector/src/graphql/input/TransactionInput.ts b/dlt-connector/src/graphql/input/TransactionInput.ts deleted file mode 100755 index d20b6ff27..000000000 --- a/dlt-connector/src/graphql/input/TransactionInput.ts +++ /dev/null @@ -1,27 +0,0 @@ -// https://www.npmjs.com/package/@apollo/protobufjs - -import { Decimal } from 'decimal.js-light' -import { TransactionType } from '../enum/TransactionType' -import { InputType, Field } from 'type-graphql' -import { IsEnum, IsInt, Min } from 'class-validator' -import { IsPositiveDecimal } from '../validator/Decimal' - -@InputType() -export class TransactionInput { - @Field(() => TransactionType) - @IsEnum(TransactionType) - type: TransactionType - - @Field(() => Decimal) - @IsPositiveDecimal() - amount: Decimal - - @Field(() => Number) - @IsInt() - @Min(978346800) - createdAt: number - - // @protoField.d(4, 'string') - // @Field(() => Decimal) - // communitySum: Decimal -} diff --git a/dlt-connector/src/graphql/resolver/TransactionsResolver.test.ts b/dlt-connector/src/graphql/resolver/TransactionsResolver.test.ts index 88fb4ffb7..71044805c 100644 --- a/dlt-connector/src/graphql/resolver/TransactionsResolver.test.ts +++ b/dlt-connector/src/graphql/resolver/TransactionsResolver.test.ts @@ -10,11 +10,11 @@ import { CONFIG } from '@/config' import { UserFactory } from '@/data/User.factory' import { UserAccountDraft } from '../input/UserAccountDraft' import { UserLogic } from '@/data/User.logic' -import { AccountType } from '../enum/AccountType' +import { AccountType } from '@enum/AccountType' import { UserIdentifier } from '../input/UserIdentifier' import { CommunityDraft } from '../input/CommunityDraft' import { AddCommunityContext } from '@/interactions/backendToDb/community/AddCommunity.context' -import { InputTransactionType } from '../enum/InputTransactionType' +import { InputTransactionType, getTransactionTypeString } from '../enum/InputTransactionType' CONFIG.IOTA_HOME_COMMUNITY_SEED = 'aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899' @@ -82,7 +82,7 @@ describe('Transaction Resolver Test', () => { input: { senderUser, recipientUser, - type: InputTransactionType.SEND, + type: getTransactionTypeString(InputTransactionType.SEND), amount: '10', createdAt: '2012-04-17T17:12:00Z', backendTransactionId: 1, @@ -130,7 +130,7 @@ describe('Transaction Resolver Test', () => { input: { senderUser, recipientUser, - type: InputTransactionType.SEND, + type: getTransactionTypeString(InputTransactionType.SEND), amount: 'no number', createdAt: '2012-04-17T17:12:00Z', backendTransactionId: 1, @@ -156,7 +156,7 @@ describe('Transaction Resolver Test', () => { input: { senderUser, recipientUser, - type: InputTransactionType.SEND, + type: getTransactionTypeString(InputTransactionType.SEND), amount: '10', createdAt: 'not valid', backendTransactionId: 1, @@ -192,7 +192,7 @@ describe('Transaction Resolver Test', () => { input: { senderUser, recipientUser, - type: InputTransactionType.CREATION, + type: getTransactionTypeString(InputTransactionType.CREATION), amount: '10', createdAt: '2012-04-17T17:12:00Z', backendTransactionId: 1, diff --git a/dlt-connector/src/utils/typeConverter.ts b/dlt-connector/src/utils/typeConverter.ts index d21e7964b..ecf090c45 100644 --- a/dlt-connector/src/utils/typeConverter.ts +++ b/dlt-connector/src/utils/typeConverter.ts @@ -7,8 +7,8 @@ import { logger } from '@/server/logger' import { TransactionError } from '@/graphql/model/TransactionError' import { TransactionErrorType } from '@/graphql/enum/TransactionErrorType' import { AccountType } from '@/graphql/enum/AccountType' -import { AddressType } from '@/graphql/enum/AddressType' import { LogError } from '@/server/LogError' +import { AddressType } from '@/data/proto/3_3/enum/AddressType' export const uuid4ToBuffer = (uuid: string): Buffer => { // Remove dashes from the UUIDv4 string