forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment-integration.test.ts
More file actions
105 lines (94 loc) · 3.32 KB
/
Copy pathpayment-integration.test.ts
File metadata and controls
105 lines (94 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Payment Integration Tests
* These tests demonstrate the payment processing flow
*/
import { Test, TestingModule } from '@nestjs/testing';
import { Repository } from 'typeorm';
import { getRepositoryToken } from '@nestjs/typeorm';
import { StellarService } from '../stellar/stellar.service';
import { PaymentProcessorService } from '../payments/payment-processor.service';
import { PaymentGateway } from '../websocket/payment.gateway';
import { Payment } from '../entities/payment.entity';
import { Participant } from '../entities/participant.entity';
import { Split } from '../entities/split.entity';
describe('Payment Integration Tests', () => {
let service: PaymentProcessorService;
let stellarService: StellarService;
let paymentGateway: PaymentGateway;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
PaymentProcessorService,
{
provide: StellarService,
useValue: {
verifyTransaction: jest.fn(),
},
},
{
provide: PaymentGateway,
useValue: {
emitPaymentNotification: jest.fn(),
emitSplitCompletion: jest.fn(),
},
},
{
provide: getRepositoryToken(Payment),
useClass: Repository,
},
{
provide: getRepositoryToken(Participant),
useClass: Repository,
},
{
provide: getRepositoryToken(Split),
useClass: Repository,
},
],
}).compile();
service = module.get<PaymentProcessorService>(PaymentProcessorService);
stellarService = module.get<StellarService>(StellarService);
paymentGateway = module.get<PaymentGateway>(PaymentGateway);
});
it('should process a complete payment', async () => {
// Mock the Stellar service to return a valid transaction
jest.spyOn(stellarService, 'verifyTransaction').mockResolvedValue({
valid: true,
amount: 50.00,
asset: 'XLM-USDC',
sender: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
receiver: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
timestamp: '2023-01-01T00:00:00Z',
});
// In a real test, we would mock repository methods and test the full flow
expect(service).toBeDefined();
});
it('should handle partial payments', async () => {
// Mock a transaction with amount less than owed
jest.spyOn(stellarService, 'verifyTransaction').mockResolvedValue({
valid: true,
amount: 25.00, // Less than owed amount
asset: 'XLM-USDC',
sender: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
receiver: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
timestamp: '2023-01-01T00:00:00Z',
});
expect(service).toBeDefined();
});
it('should reject invalid transactions', async () => {
// Mock an invalid transaction
jest.spyOn(stellarService, 'verifyTransaction').mockResolvedValue({
valid: false,
amount: 0,
asset: '',
sender: '',
receiver: '',
timestamp: '2023-01-01T00:00:00Z',
});
expect(service).toBeDefined();
});
it('should prevent duplicate transactions', async () => {
// This test would verify that the service prevents duplicate submissions
expect(service).toBeDefined();
});
});