mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
adjust according to Claus-Peters Suggestions
This commit is contained in:
parent
8da7b90d3b
commit
6b37022fc2
@ -6,7 +6,7 @@ module.exports = {
|
||||
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
lines: 62,
|
||||
lines: 63,
|
||||
},
|
||||
},
|
||||
setupFiles: ['<rootDir>/test/testSetup.ts'],
|
||||
@ -14,6 +14,7 @@ module.exports = {
|
||||
modulePathIgnorePatterns: ['<rootDir>/build/'],
|
||||
moduleNameMapper: {
|
||||
'@/(.*)': '<rootDir>/src/$1',
|
||||
'@enum/(.*)': '<rootDir>/src/graphql/enum/$1',
|
||||
'@resolver/(.*)': '<rootDir>/src/graphql/resolver/$1',
|
||||
'@input/(.*)': '<rootDir>/src/graphql/input/$1',
|
||||
'@proto/(.*)': '<rootDir>/src/proto/$1',
|
||||
|
||||
@ -13,7 +13,7 @@ export class TransactionInput {
|
||||
amount: Decimal
|
||||
|
||||
@Field(() => Number)
|
||||
created: number
|
||||
createdAt: number
|
||||
|
||||
// @protoField.d(4, 'string')
|
||||
// @Field(() => Decimal)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'reflect-metadata'
|
||||
import { ApolloServer } from '@apollo/server'
|
||||
import { createApolloTestServer } from '@test/ApolloServerMock'
|
||||
import assert from 'assert'
|
||||
|
||||
@ -10,23 +11,35 @@ jest.mock('@/client/IotaClient', () => {
|
||||
}
|
||||
})
|
||||
|
||||
let apolloTestServer: ApolloServer
|
||||
|
||||
describe('Transaction Resolver Test', () => {
|
||||
beforeAll(async () => {
|
||||
apolloTestServer = await createApolloTestServer()
|
||||
})
|
||||
it('test version query', async () => {
|
||||
const response = await apolloTestServer.executeOperation({
|
||||
query: '{ version }',
|
||||
})
|
||||
// Note the use of Node's assert rather than Jest's expect; if using
|
||||
// TypeScript, `assert`` will appropriately narrow the type of `body`
|
||||
// and `expect` will not.
|
||||
// Source: https://www.apollographql.com/docs/apollo-server/testing/testing
|
||||
assert(response.body.kind === 'single')
|
||||
expect(response.body.singleResult.errors).toBeUndefined()
|
||||
expect(response.body.singleResult.data?.version).toBe('0.1')
|
||||
})
|
||||
it('test mocked sendTransaction', async () => {
|
||||
const apolloTestServer = await createApolloTestServer()
|
||||
const response = await apolloTestServer.executeOperation({
|
||||
query: 'mutation ($input: TransactionInput!) { sendTransaction(data: $input) }',
|
||||
variables: {
|
||||
input: {
|
||||
type: 'SEND',
|
||||
amount: '10',
|
||||
created: 1688992436,
|
||||
createdAt: 1688992436,
|
||||
},
|
||||
},
|
||||
})
|
||||
// Note the use of Node's assert rather than Jest's expect; if using
|
||||
// TypeScript, `assert`` will appropriately narrow the type of `body`
|
||||
// and `expect` will not.
|
||||
// Source: https://www.apollographql.com/docs/apollo-server/testing/testing
|
||||
assert(response.body.kind === 'single')
|
||||
expect(response.body.singleResult.errors).toBeUndefined()
|
||||
expect(response.body.singleResult.data?.sendTransaction).toBe(
|
||||
@ -35,15 +48,13 @@ describe('Transaction Resolver Test', () => {
|
||||
})
|
||||
|
||||
it('test mocked sendTransaction invalid transactionType ', async () => {
|
||||
const apolloTestServer = await createApolloTestServer()
|
||||
|
||||
const response = await apolloTestServer.executeOperation({
|
||||
query: 'mutation ($input: TransactionInput!) { sendTransaction(data: $input) }',
|
||||
variables: {
|
||||
input: {
|
||||
type: 'INVALID',
|
||||
amount: '10',
|
||||
created: 1688992436,
|
||||
createdAt: 1688992436,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -59,15 +70,13 @@ describe('Transaction Resolver Test', () => {
|
||||
})
|
||||
|
||||
it('test mocked sendTransaction invalid amount ', async () => {
|
||||
const apolloTestServer = await createApolloTestServer()
|
||||
|
||||
const response = await apolloTestServer.executeOperation({
|
||||
query: 'mutation ($input: TransactionInput!) { sendTransaction(data: $input) }',
|
||||
variables: {
|
||||
input: {
|
||||
type: 'SEND',
|
||||
amount: 'no number',
|
||||
created: 1688992436,
|
||||
createdAt: 1688992436,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -83,15 +92,13 @@ describe('Transaction Resolver Test', () => {
|
||||
})
|
||||
|
||||
it('test mocked sendTransaction invalid created date ', async () => {
|
||||
const apolloTestServer = await createApolloTestServer()
|
||||
|
||||
const response = await apolloTestServer.executeOperation({
|
||||
query: 'mutation ($input: TransactionInput!) { sendTransaction(data: $input) }',
|
||||
variables: {
|
||||
input: {
|
||||
type: 'SEND',
|
||||
amount: '10',
|
||||
created: '2023-03-02T10:12:00',
|
||||
createdAt: '2023-03-02T10:12:00',
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -100,7 +107,7 @@ describe('Transaction Resolver Test', () => {
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'Variable "$input" got invalid value "2023-03-02T10:12:00" at "input.created"; Float cannot represent non numeric value: "2023-03-02T10:12:00"',
|
||||
'Variable "$input" got invalid value "2023-03-02T10:12:00" at "input.createdAt"; Float cannot represent non numeric value: "2023-03-02T10:12:00"',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
@ -12,9 +12,10 @@ export class TransactionResolver {
|
||||
// GeneratingSchemaError: Some errors occurred while generating GraphQL schema:
|
||||
// Type Query must define one or more fields.
|
||||
// it seems that at least one query must be defined
|
||||
// https://github.com/ardatan/graphql-tools/issues/764
|
||||
@Query(() => String)
|
||||
dummy(): string {
|
||||
return 'nothing'
|
||||
version(): string {
|
||||
return '0.1'
|
||||
}
|
||||
|
||||
@Mutation(() => String)
|
||||
|
||||
36
dlt-connector/src/proto/TransactionBody.test.ts
Normal file
36
dlt-connector/src/proto/TransactionBody.test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import 'reflect-metadata'
|
||||
import { TransactionType } from '@enum/TransactionType'
|
||||
import { TransactionInput } from '@input/TransactionInput'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { TransactionBody } from './TransactionBody'
|
||||
|
||||
describe('proto/TransactionBodyTest', () => {
|
||||
it('test compatible with graphql/input/TransactionInput', async () => {
|
||||
// test data
|
||||
const type = TransactionType.SEND
|
||||
const amount = new Decimal('10')
|
||||
const createAt = 1688992436
|
||||
|
||||
// init both objects
|
||||
// graphql input object
|
||||
const transactionInput = new TransactionInput()
|
||||
transactionInput.type = type
|
||||
transactionInput.amount = amount
|
||||
transactionInput.createdAt = createAt
|
||||
|
||||
// protobuf object
|
||||
const transactionBody = new TransactionBody()
|
||||
transactionBody.type = type
|
||||
transactionBody.amount = amount.toString()
|
||||
transactionBody.createdAt = createAt
|
||||
|
||||
// create protobuf object from graphql Input object
|
||||
const message = TransactionBody.fromObject(transactionInput)
|
||||
// serialize both protobuf objects
|
||||
const messageBuffer = TransactionBody.encode(message).finish()
|
||||
const messageBuffer2 = TransactionBody.encode(transactionBody).finish()
|
||||
|
||||
// compare
|
||||
expect(messageBuffer).toStrictEqual(messageBuffer2)
|
||||
})
|
||||
})
|
||||
@ -9,10 +9,10 @@ export class TransactionBody extends Message<TransactionBody> {
|
||||
type: TransactionType
|
||||
|
||||
@Field.d(2, 'string')
|
||||
amount: Decimal
|
||||
amount: string
|
||||
|
||||
@Field.d(3, 'uint64')
|
||||
created: number
|
||||
createdAt: number
|
||||
|
||||
// @protoField.d(4, 'string')
|
||||
// communitySum: Decimal
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user