forked from StellarEdu/StellarEduPay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment-limits.test.js
More file actions
95 lines (81 loc) · 3.4 KB
/
Copy pathpayment-limits.test.js
File metadata and controls
95 lines (81 loc) · 3.4 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
'use strict';
process.env.MONGO_URI = process.env.MONGO_URI || 'mongodb://localhost:27017/test';
const { validatePaymentAmount, getPaymentLimits } = require('../backend/src/utils/paymentLimits');
describe('Payment Limits', () => {
describe('getPaymentLimits', () => {
it('should return configured payment limits', () => {
const limits = getPaymentLimits();
expect(limits).toHaveProperty('min');
expect(limits).toHaveProperty('max');
expect(typeof limits.min).toBe('number');
expect(typeof limits.max).toBe('number');
expect(limits.max).toBeGreaterThan(limits.min);
});
});
describe('validatePaymentAmount', () => {
it('should accept valid payment amounts within limits', () => {
const result = validatePaymentAmount(100);
expect(result.valid).toBe(true);
expect(result.error).toBeUndefined();
expect(result.code).toBeUndefined();
});
it('should reject payment amounts below minimum', () => {
const result = validatePaymentAmount(0.001);
expect(result.valid).toBe(false);
expect(result.error).toContain('below the minimum');
expect(result.code).toBe('AMOUNT_TOO_LOW');
});
it('should reject payment amounts above maximum', () => {
const result = validatePaymentAmount(200000);
expect(result.valid).toBe(false);
expect(result.error).toContain('exceeds the maximum');
expect(result.code).toBe('AMOUNT_TOO_HIGH');
});
it('should reject zero payment amounts', () => {
const result = validatePaymentAmount(0);
expect(result.valid).toBe(false);
expect(result.error).toContain('greater than zero');
expect(result.code).toBe('INVALID_AMOUNT');
});
it('should reject negative payment amounts', () => {
const result = validatePaymentAmount(-10);
expect(result.valid).toBe(false);
expect(result.error).toContain('greater than zero');
expect(result.code).toBe('INVALID_AMOUNT');
});
it('should reject non-numeric payment amounts', () => {
const result = validatePaymentAmount('invalid');
expect(result.valid).toBe(false);
expect(result.error).toContain('valid number');
expect(result.code).toBe('INVALID_AMOUNT');
});
it('should reject NaN payment amounts', () => {
const result = validatePaymentAmount(NaN);
expect(result.valid).toBe(false);
expect(result.error).toContain('valid number');
expect(result.code).toBe('INVALID_AMOUNT');
});
it('should accept payment amount at minimum limit', () => {
const limits = getPaymentLimits();
const result = validatePaymentAmount(limits.min);
expect(result.valid).toBe(true);
});
it('should accept payment amount at maximum limit', () => {
const limits = getPaymentLimits();
const result = validatePaymentAmount(limits.max);
expect(result.valid).toBe(true);
});
it('should reject payment amount just below minimum', () => {
const limits = getPaymentLimits();
const result = validatePaymentAmount(limits.min - 0.001);
expect(result.valid).toBe(false);
expect(result.code).toBe('AMOUNT_TOO_LOW');
});
it('should reject payment amount just above maximum', () => {
const limits = getPaymentLimits();
const result = validatePaymentAmount(limits.max + 0.001);
expect(result.valid).toBe(false);
expect(result.code).toBe('AMOUNT_TOO_HIGH');
});
});
});