mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
update tests
This commit is contained in:
parent
e019f40b41
commit
7b3597eb44
@ -18,6 +18,7 @@ module.exports = {
|
||||
'@input/(.*)': '<rootDir>/src/graphql/input/$1',
|
||||
'@proto/(.*)': '<rootDir>/src/proto/$1',
|
||||
'@test/(.*)': '<rootDir>/test/$1',
|
||||
'@client/(.*)': '<rootDir>/src/client/$1',
|
||||
'@entity/(.*)':
|
||||
// eslint-disable-next-line n/no-process-env
|
||||
process.env.NODE_ENV === 'development'
|
||||
|
||||
@ -2,26 +2,11 @@ import 'reflect-metadata'
|
||||
import { createApolloTestServer } from '@test/ApolloServerMock'
|
||||
import assert from 'assert'
|
||||
|
||||
jest.mock('@iota/client', () => {
|
||||
const mockMessageSender = jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
index: jest.fn().mockReturnThis(),
|
||||
data: jest.fn().mockReturnThis(),
|
||||
submit: jest.fn().mockReturnValue({
|
||||
messageId: '5498130bc3918e1a7143969ce05805502417e3e1bd596d3c44d6a0adeea22710',
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
const mockClient = {
|
||||
message: mockMessageSender,
|
||||
}
|
||||
const mockClientBuilder = {
|
||||
node: jest.fn().mockReturnThis(),
|
||||
build: jest.fn(() => mockClient),
|
||||
}
|
||||
jest.mock('@/client/IotaClient', () => {
|
||||
return {
|
||||
ClientBuilder: jest.fn(() => mockClientBuilder),
|
||||
sendMessage: jest.fn().mockReturnValue({
|
||||
messageId: '5498130bc3918e1a7143969ce05805502417e3e1bd596d3c44d6a0adeea22710',
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
@ -48,4 +33,76 @@ describe('Transaction Resolver Test', () => {
|
||||
'5498130bc3918e1a7143969ce05805502417e3e1bd596d3c44d6a0adeea22710',
|
||||
)
|
||||
})
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
})
|
||||
assert(response.body.kind === 'single')
|
||||
expect(response.body.singleResult).toMatchObject({
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'Variable "$input" got invalid value "INVALID" at "input.type"; Value "INVALID" does not exist in "TransactionType" enum.',
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
})
|
||||
assert(response.body.kind === 'single')
|
||||
expect(response.body.singleResult).toMatchObject({
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'Variable "$input" got invalid value "no number" at "input.amount"; Expected type "Decimal". [DecimalError] Invalid argument: no number',
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
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',
|
||||
},
|
||||
},
|
||||
})
|
||||
assert(response.body.kind === 'single')
|
||||
expect(response.body.singleResult).toMatchObject({
|
||||
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"',
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -24,7 +24,7 @@ export class TransactionResolver {
|
||||
): Promise<string> {
|
||||
const message = TransactionBody.fromObject(transaction)
|
||||
const messageBuffer = TransactionBody.encode(message).finish()
|
||||
const resultMessage = iotaSendMessage(messageBuffer)
|
||||
return (await resultMessage).messageId
|
||||
const resultMessage = await iotaSendMessage(messageBuffer)
|
||||
return resultMessage.messageId
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user