correct and extent testcases

This commit is contained in:
Claus-Peter Huebner 2023-10-17 23:25:35 +02:00
parent e983e59173
commit fdefa0641d
3 changed files with 84 additions and 5 deletions

View File

@ -41,7 +41,9 @@ beforeAll(async () => {
afterAll(async () => {
// await cleanDB()
await con.destroy()
if (!testEnv.con || !testEnv.con.isConnected) {
await testEnv.con.close()
}
})
describe('SendCoinsResolver', () => {
@ -92,6 +94,7 @@ describe('SendCoinsResolver', () => {
sendUser = DbUser.create()
sendUser.alias = 'sendUser-alias'
sendUser.communityUuid = '56a55482-909e-46a4-bfa2-cd025e894eba'
sendUser.firstName = 'sendUser-FirstName'
sendUser.gradidoID = '56a55482-909e-46a4-bfa2-cd025e894ebc'
sendUser.lastName = 'sendUser-LastName'
@ -106,6 +109,7 @@ describe('SendCoinsResolver', () => {
recipUser = DbUser.create()
recipUser.alias = 'recipUser-alias'
recipUser.communityUuid = '56a55482-909e-46a4-bfa2-cd025e894ebb'
recipUser.firstName = 'recipUser-FirstName'
recipUser.gradidoID = '56a55482-909e-46a4-bfa2-cd025e894ebd'
recipUser.lastName = 'recipUser-LastName'
@ -182,7 +186,7 @@ describe('SendCoinsResolver', () => {
})
})
describe('valid X-Com-TX voted', () => {
describe('valid X-Com-TX voted per gradidoID', () => {
it('throws an error', async () => {
jest.clearAllMocks()
const args = new SendCoinsArgs()
@ -219,6 +223,82 @@ describe('SendCoinsResolver', () => {
)
})
})
describe('valid X-Com-TX voted per alias', () => {
it('throws an error', async () => {
jest.clearAllMocks()
const args = new SendCoinsArgs()
if (foreignCom.communityUuid) {
args.recipientCommunityUuid = foreignCom.communityUuid
}
args.recipientUserIdentifier = recipUser.alias
args.creationDate = new Date().toISOString()
args.amount = new Decimal(100)
args.memo = 'X-Com-TX memo'
if (homeCom.communityUuid) {
args.senderCommunityUuid = homeCom.communityUuid
}
args.senderUserUuid = sendUser.gradidoID
args.senderUserName = fullName(sendUser.firstName, sendUser.lastName)
args.senderAlias = sendUser.alias
expect(
await mutate({
mutation: voteForSendCoinsMutation,
variables: { args },
}),
).toEqual(
expect.objectContaining({
data: {
voteForSendCoins: {
recipGradidoID: '56a55482-909e-46a4-bfa2-cd025e894ebd',
recipFirstName: 'recipUser-FirstName',
recipLastName: 'recipUser-LastName',
recipAlias: 'recipUser-alias',
vote: true,
},
},
}),
)
})
})
describe('valid X-Com-TX voted per email', () => {
it('throws an error', async () => {
jest.clearAllMocks()
const args = new SendCoinsArgs()
if (foreignCom.communityUuid) {
args.recipientCommunityUuid = foreignCom.communityUuid
}
args.recipientUserIdentifier = recipContact.email
args.creationDate = new Date().toISOString()
args.amount = new Decimal(100)
args.memo = 'X-Com-TX memo'
if (homeCom.communityUuid) {
args.senderCommunityUuid = homeCom.communityUuid
}
args.senderUserUuid = sendUser.gradidoID
args.senderUserName = fullName(sendUser.firstName, sendUser.lastName)
args.senderAlias = sendUser.alias
expect(
await mutate({
mutation: voteForSendCoinsMutation,
variables: { args },
}),
).toEqual(
expect.objectContaining({
data: {
voteForSendCoins: {
recipGradidoID: '56a55482-909e-46a4-bfa2-cd025e894ebd',
recipFirstName: 'recipUser-FirstName',
recipLastName: 'recipUser-LastName',
recipAlias: 'recipUser-alias',
vote: true,
},
},
}),
)
})
})
})
describe('revertSendCoins', () => {
@ -588,7 +668,7 @@ async function newEmailContact(email: string, userId: number): Promise<DbUserCon
emailContact.email = email
emailContact.userId = userId
emailContact.type = 'EMAIL'
emailContact.emailChecked = false
emailContact.emailChecked = true
emailContact.emailOptInTypeId = 1
emailContact.emailVerificationCode = '1' + userId
return emailContact

View File

@ -41,7 +41,6 @@ export class SendCoinsResolver {
// first check if receiver community is correct
const homeCom = await DbCommunity.findOneBy({
communityUuid: args.recipientCommunityUuid,
foreign: false,
})
if (!homeCom) {
throw new LogError(

View File

@ -21,7 +21,7 @@ export async function storeForeignUser(args: SendCoinsArgs): Promise<boolean> {
)
let foreignUser = DbUser.create()
foreignUser.foreign = true
if (args.senderAlias !== null) {
if (args.senderAlias) {
foreignUser.alias = args.senderAlias
}
foreignUser.communityUuid = args.senderCommunityUuid