import { veeqoMethods } from '../src/methods/veeqo';
import { VeeqoClient } from '../src/clients/veeqoClient';
import { ValidationError } from '../src/utils/errors';
// Mock the Veeqo client
jest.mock('../src/clients/veeqoClient');
describe('Veeqo Methods', () => {
const mockClient = VeeqoClient as jest.MockedClass<typeof VeeqoClient>;
beforeEach(() => {
mockClient.mockClear();
});
describe('createOrder', () => {
it('should create an order successfully', async () => {
const mockOrder = {
id: 'ord_123',
number: 'V123456',
status: 'pending',
channel_order_code: 'CH123',
created_at: '2023-01-01T00:00:00Z',
updated_at: '2023-01-01T00:00:00Z'
};
mockClient.prototype.createOrder = jest.fn().mockResolvedValue(mockOrder);
const params = {
order: {
deliver_to: {
first_name: 'John',
last_name: 'Doe',
address1: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345',
country: 'US'
},
line_items_attributes: [
{ product_id: 'prod_1', quantity: 1 }
]
}
};
const result = await veeqoMethods.createOrder(params);
expect(result).toEqual({
id: 'ord_123',
number: 'V123456',
status: 'pending',
channel_order_code: 'CH123',
created_at: '2023-01-01T00:00:00Z',
updated_at: '2023-01-01T00:00:00Z'
});
});
it('should throw validation error if order is missing', async () => {
await expect(veeqoMethods.createOrder({} as any))
.rejects
.toThrow(ValidationError);
});
});
describe('getOrder', () => {
it('should get an order successfully', async () => {
const mockOrder = {
id: 'ord_123',
number: 'V123456',
status: 'pending',
channel_order_code: 'CH123',
deliver_to: {
first_name: 'John',
last_name: 'Doe',
address1: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345',
country: 'US'
},
line_items_attributes: [
{ product_id: 'prod_1', quantity: 1 }
],
created_at: '2023-01-01T00:00:00Z',
updated_at: '2023-01-01T00:00:00Z'
};
mockClient.prototype.getOrder = jest.fn().mockResolvedValue(mockOrder);
const result = await veeqoMethods.getOrder({ order_id: 'ord_123' });
expect(result).toEqual({
id: 'ord_123',
number: 'V123456',
status: 'pending',
channel_order_code: 'CH123',
deliver_to: {
first_name: 'John',
last_name: 'Doe',
address1: '123 Main St',
city: '