mirror of
https://github.com/duhanbalci/iyzico.git
synced 2026-03-03 20:29:18 +00:00
225 lines
7.2 KiB
TypeScript
225 lines
7.2 KiB
TypeScript
/**
|
|
* BIN Check integration tests
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { createTestClient, assertSuccessResponse } from '../setup';
|
|
import type { ErrorResponse } from '../../src/types';
|
|
|
|
describe('BIN Check Integration Tests', () => {
|
|
const client = createTestClient();
|
|
|
|
it('should check BIN for a valid card number', async () => {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '535805',
|
|
conversationId: 'test-bin-check-1',
|
|
});
|
|
|
|
assertSuccessResponse(response);
|
|
expect(response.binNumber).toBe('535805');
|
|
expect(response.cardType).toBeTruthy();
|
|
expect(response.cardAssociation).toBeTruthy();
|
|
});
|
|
|
|
it('should check BIN with price for installment details', async () => {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '535805',
|
|
price: 100.0,
|
|
conversationId: 'test-bin-check-2',
|
|
});
|
|
|
|
assertSuccessResponse(response);
|
|
expect(response.binNumber).toBe('535805');
|
|
if (response.installmentDetails && response.installmentDetails.length > 0) {
|
|
expect(response.installmentDetails[0].installmentPrices).toBeTruthy();
|
|
}
|
|
});
|
|
|
|
it('should handle invalid BIN number', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '000000',
|
|
conversationId: 'test-bin-check-invalid',
|
|
});
|
|
// If API doesn't reject invalid BINs, verify response structure
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
// If it's a success response, verify it has expected structure
|
|
if (response.status === 'success') {
|
|
expect(response.binNumber).toBe('000000');
|
|
}
|
|
} catch (error: any) {
|
|
// API might return an error for invalid BIN - verify it's an Iyzico error
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
// Verify error has proper structure
|
|
if (error.code) {
|
|
expect(typeof error.code).toBe('string');
|
|
}
|
|
}
|
|
});
|
|
|
|
describe('Edge Cases - Invalid Fields', () => {
|
|
it('should handle missing binNumber', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: undefined as any,
|
|
conversationId: 'test-missing-bin',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
if (response.status === 'failure') {
|
|
const errorResponse = response as unknown as ErrorResponse;
|
|
expect(errorResponse.errorCode || errorResponse.errorMessage).toBeTruthy();
|
|
}
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle empty binNumber', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '',
|
|
conversationId: 'test-empty-bin',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
if (response.status === 'failure') {
|
|
const errorResponse = response as unknown as ErrorResponse;
|
|
expect(errorResponse.errorCode || errorResponse.errorMessage).toBeTruthy();
|
|
}
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle binNumber that is too short', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '12345', // 5 digits, should be 6
|
|
conversationId: 'test-short-bin',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle binNumber that is too long', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '1234567', // 7 digits, should be 6
|
|
conversationId: 'test-long-bin',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle binNumber with non-numeric characters', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: 'ABC123',
|
|
conversationId: 'test-nonnumeric-bin',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
if (response.status === 'failure') {
|
|
const errorResponse = response as unknown as ErrorResponse;
|
|
expect(errorResponse.errorCode || errorResponse.errorMessage).toBeTruthy();
|
|
}
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle negative price', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '535805',
|
|
price: -100.0,
|
|
conversationId: 'test-negative-price',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
if (response.status === 'failure') {
|
|
const errorResponse = response as unknown as ErrorResponse;
|
|
expect(errorResponse.errorCode || errorResponse.errorMessage).toBeTruthy();
|
|
}
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle zero price', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'tr',
|
|
binNumber: '535805',
|
|
price: 0,
|
|
conversationId: 'test-zero-price',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle invalid locale', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: 'invalid' as any,
|
|
binNumber: '535805',
|
|
conversationId: 'test-invalid-locale',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
if (response.status === 'failure') {
|
|
const errorResponse = response as unknown as ErrorResponse;
|
|
expect(errorResponse.errorCode || errorResponse.errorMessage).toBeTruthy();
|
|
}
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
|
|
it('should handle missing locale', async () => {
|
|
try {
|
|
const response = await client.binCheck.check({
|
|
locale: undefined as any,
|
|
binNumber: '535805',
|
|
conversationId: 'test-missing-locale',
|
|
});
|
|
expect(response).toBeDefined();
|
|
expect(response.status).toBeDefined();
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error).toBeInstanceOf(Error);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|