Last active
October 3, 2021 13:57
-
-
Save goldbergyoni/5408230b71f91d240a5ebdb27b34a513 to your computer and use it in GitHub Desktop.
Anti-pattern test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ❌ | |
| test('Should fail', () => { | |
| const transferRequest = testHelpers.factorMoneyTransfer({}); // ❌ | |
| serviceUnderTest.options.creditPolicy = 'zero'; // ❌ | |
| transferRequest.howMuch = 110; // ❌ | |
| // Let's use the library sinon to listen to calls to the DB save function | |
| const databaseRepositoryMock = sinon.stub(dbRepository, 'save');//❌ | |
| const transferResponse = serviceUnderTest.transfer(transferRequest); | |
| expect(transferResponse.currency).toBe('dollar'); // ❌ | |
| expect(transferResponse.id).not.toBeNull(); // ❌ | |
| expect(transferResponse.date.getDay()).toBe(new Date().getDay()); // ❌ | |
| expect(serviceUnderTest.numberOfDeclined).toBe(1); // ❌ | |
| expect(databaseRepositoryMock.calledOnce).toBe(false); // ❌ | |
| // Let's get the user transfer history | |
| const allUserTransfers = serviceUnderTest.getTransfers(transferRequest.sender.name); | |
| expect(allUserTransfers).not.toBeNull(); // ❌ Overlapping | |
| expect(allUserTransfers).toBeType('array'); // ❌ Overlapping | |
| // check that declined transfer is not in user history array ❌ | |
| let transferFound = false; | |
| allUserTransfers.forEach((transferToCheck) => { | |
| if (transferToCheck.id === transferRequest.id) { | |
| transferFound = true; | |
| } | |
| }); | |
| expect(transferFound).toBe(false); | |
| // Let's check that an email was sent ❌ | |
| if (transferRequest.options.sendMailOnDecline && transferResponse.status === 'declined') { | |
| const wasMailSent = testHelpers.verifyIfMailWasSentToTransfer(transferResponse.id); | |
| expect(wasMailSent).toBe(true); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment