diff --git a/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.test.ts b/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.test.ts index 2ab2cc8b3..e542542bc 100644 --- a/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/SendCoinsResolver.test.ts @@ -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 { ) let foreignUser = DbUser.create() foreignUser.foreign = true - if (args.senderAlias !== null) { + if (args.senderAlias) { foreignUser.alias = args.senderAlias } foreignUser.communityUuid = args.senderCommunityUuid