diff --git a/frontend/src/__tests__/payment.spec.ts b/frontend/src/__tests__/payment.spec.ts new file mode 100644 index 0000000..fd1cd25 --- /dev/null +++ b/frontend/src/__tests__/payment.spec.ts @@ -0,0 +1,52 @@ +import { describe, it, expect } from 'vitest' +import { buildSwishPaymentUrl } from '@/api/payment' + +describe('buildSwishPaymentUrl', () => { + it('normalises Swedish national format to international', () => { + expect(buildSwishPaymentUrl('0701234567', 49, 'test')).toContain( + 'sw=46701234567', + ) + }) + + it('strips a leading + from international format', () => { + const url = buildSwishPaymentUrl('+46701234567', 49, 'test') + expect(url).toContain('sw=46701234567') + expect(url).not.toContain('sw=%2B') + expect(url).not.toContain('sw=+') + }) + + it('leaves already-international numbers unchanged', () => { + expect(buildSwishPaymentUrl('46701234567', 49, 'test')).toContain( + 'sw=46701234567', + ) + }) + + it('leaves Swish Business numbers (123…) unchanged', () => { + expect(buildSwishPaymentUrl('1234567890', 49, 'test')).toContain( + 'sw=1234567890', + ) + }) + + it('strips whitespace from the number', () => { + expect(buildSwishPaymentUrl('070 123 45 67', 49, 'test')).toContain( + 'sw=46701234567', + ) + }) + + it('includes the amount with two decimal places in amt', () => { + expect(buildSwishPaymentUrl('0701234567', 49, 'test')).toContain( + 'amt=49.00', + ) + }) + + it('URL-encodes the message in the msg parameter', () => { + const url = buildSwishPaymentUrl('0701234567', 49, 'ABC 123') + expect(url).toContain('msg=ABC+123') + }) + + it('uses the correct Swish C2B base URL', () => { + expect(buildSwishPaymentUrl('0701234567', 49, 'test')).toContain( + 'https://app.swish.nu/1/p/sw/?', + ) + }) +})