trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
372 lines • 21.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-env jest */
const dtos_1 = require("../../../../src/api/common/snapshot/dtos");
const requests_1 = require("../../../../src/api/common/snapshot/requests");
const responses_1 = require("../../../../src/api/common/snapshot/responses");
const errors_1 = require("../../../../src/entities/errors");
// Mock dependencies
class MockMapper {
constructor() {
this.map = jest.fn();
}
}
// Since InPlaySnapshotApiClientImplementation extends BaseHttpClient, we need to mock the base functionality
jest.mock('@httpClient/base-http-client', () => {
return {
BaseHttpClient: jest.fn().mockImplementation(() => {
return {
postRequest: jest.fn(),
};
}),
};
});
describe('InPlaySnapshotApiClientImplementation', () => {
let inplaySnapshotApiClient;
let mockMapper;
let mockPostRequest;
beforeEach(() => {
mockMapper = new MockMapper();
mockPostRequest = jest.fn();
inplaySnapshotApiClient = {
getFixtures: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetFixtureRequest);
return mockPostRequest({
route: '/Inplay/GetFixtures',
responseBodyType: responses_1.GetFixturesResultElement,
requestBody: mappedRequest,
});
}),
getLivescores: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetLivescoreRequest);
return mockPostRequest({
route: '/Inplay/GetScores',
responseBodyType: responses_1.GetLivescoreResultElement,
requestBody: mappedRequest,
});
}),
getFixtureMarkets: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetMarketRequest);
return mockPostRequest({
route: '/Inplay/GetFixtureMarkets',
responseBodyType: responses_1.GetFixtureMarketsResultElement,
requestBody: mappedRequest,
});
}),
getEvents: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetInPlayEventRequest);
return mockPostRequest({
route: '/Inplay/GetEvents',
responseBodyType: responses_1.GetEventsResultElement,
requestBody: mappedRequest,
});
}),
getOutrightLeagues: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetOutrightLeaguesRequest);
return mockPostRequest({
route: '/Inplay/GetOutrightLeagues',
responseBodyType: responses_1.GetOutrightLeaguesResultElement,
requestBody: mappedRequest,
});
}),
getOutrightLeagueMarkets: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetOutrightLeagueMarketRequest);
return mockPostRequest({
route: '/Inplay/GetOutrightLeagueMarkets',
responseBodyType: responses_1.GetOutrightLeagueMarketsResultElement,
requestBody: mappedRequest,
});
}),
getOutrightLeagueEvents: jest.fn(async (requestDto) => {
const mappedRequest = mockMapper.map(requestDto, requests_1.GetOutrightLeagueEventsRequest);
return mockPostRequest({
route: '/Inplay/GetOutrightLeagueEvents',
responseBodyType: responses_1.GetOutrightLeagueEventsResultElement,
requestBody: mappedRequest,
});
}),
};
});
describe('getFixtures', () => {
it('should successfully call getFixtures with valid request', async () => {
const requestDto = new dtos_1.GetFixtureRequestDto();
const mappedRequest = new requests_1.GetFixtureRequest();
const expectedResponse = new responses_1.GetFixturesResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getFixtures(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetFixtureRequest);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetFixtures',
responseBodyType: responses_1.GetFixturesResultElement,
requestBody: mappedRequest,
});
expect(result).toBe(expectedResponse);
});
it('should handle mapper transformation correctly', async () => {
const requestDto = new dtos_1.GetFixtureRequestDto();
const mappedRequest = new requests_1.GetFixtureRequest();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(new responses_1.GetFixturesResultElement());
await inplaySnapshotApiClient.getFixtures(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetFixtureRequest);
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetFixtureRequestDto();
const error = new errors_1.HttpResponseError('API Error');
mockMapper.map.mockReturnValue(new requests_1.GetFixtureRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getFixtures(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetFixtureRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetFixtureRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getFixtures(requestDto);
expect(result).toBeUndefined();
});
});
describe('getLivescores', () => {
it('should successfully call getLivescores with valid request', async () => {
const requestDto = new dtos_1.GetLivescoreRequestDto();
const mappedRequest = new requests_1.GetLivescoreRequest();
const expectedResponse = new responses_1.GetLivescoreResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getLivescores(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetLivescoreRequest);
expect(result).toBe(expectedResponse);
});
it('should propagate mapper errors', async () => {
const requestDto = new dtos_1.GetLivescoreRequestDto();
const error = new Error('Mapping Error');
mockMapper.map.mockImplementation(() => {
throw error;
});
await expect(inplaySnapshotApiClient.getLivescores(requestDto)).rejects.toThrow(error);
expect(mockPostRequest).not.toHaveBeenCalled();
});
it('should handle null response', async () => {
const requestDto = new dtos_1.GetLivescoreRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetLivescoreRequest());
mockPostRequest.mockResolvedValue(null);
const result = await inplaySnapshotApiClient.getLivescores(requestDto);
expect(result).toBeNull();
});
it('should use correct route for livescores', async () => {
const requestDto = new dtos_1.GetLivescoreRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetLivescoreRequest());
mockPostRequest.mockResolvedValue(new responses_1.GetLivescoreResultElement());
await inplaySnapshotApiClient.getLivescores(requestDto);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetScores',
responseBodyType: responses_1.GetLivescoreResultElement,
requestBody: expect.any(requests_1.GetLivescoreRequest),
});
});
});
describe('getFixtureMarkets', () => {
it('should successfully call getFixtureMarkets with valid request', async () => {
const requestDto = new dtos_1.GetMarketRequestDto();
const mappedRequest = new requests_1.GetMarketRequest();
const expectedResponse = new responses_1.GetFixtureMarketsResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getFixtureMarkets(requestDto);
expect(result).toBe(expectedResponse);
});
it('should handle empty response data', async () => {
const requestDto = new dtos_1.GetMarketRequestDto();
const emptyResponse = new responses_1.GetFixtureMarketsResultElement();
emptyResponse.data = [];
mockMapper.map.mockReturnValue(new requests_1.GetMarketRequest());
mockPostRequest.mockResolvedValue(emptyResponse);
const result = await inplaySnapshotApiClient.getFixtureMarkets(requestDto);
expect(result?.data).toEqual([]);
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetMarketRequestDto();
const error = new errors_1.HttpResponseError('Network Error');
mockMapper.map.mockReturnValue(new requests_1.GetMarketRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getFixtureMarkets(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetMarketRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetMarketRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getFixtureMarkets(requestDto);
expect(result).toBeUndefined();
});
});
describe('getEvents', () => {
it('should successfully call getEvents with valid request', async () => {
const requestDto = new dtos_1.GetInPlayEventRequestDto();
const mappedRequest = new requests_1.GetInPlayEventRequest();
const expectedResponse = new responses_1.GetEventsResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getEvents(requestDto);
expect(result).toBe(expectedResponse);
});
it('should use correct route for events', async () => {
const requestDto = new dtos_1.GetInPlayEventRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetInPlayEventRequest());
mockPostRequest.mockResolvedValue(new responses_1.GetEventsResultElement());
await inplaySnapshotApiClient.getEvents(requestDto);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetEvents',
responseBodyType: responses_1.GetEventsResultElement,
requestBody: expect.any(requests_1.GetInPlayEventRequest),
});
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetInPlayEventRequestDto();
const error = new errors_1.HttpResponseError('Server Error');
mockMapper.map.mockReturnValue(new requests_1.GetInPlayEventRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getEvents(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetInPlayEventRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetInPlayEventRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getEvents(requestDto);
expect(result).toBeUndefined();
});
});
// NEW OUTRIGHT ENDPOINTS TESTS
describe('getOutrightLeagues', () => {
it('should successfully call getOutrightLeagues with valid request', async () => {
const requestDto = new dtos_1.GetOutrightLeaguesRequestDto();
const mappedRequest = new requests_1.GetOutrightLeaguesRequest();
const expectedResponse = new responses_1.GetOutrightLeaguesResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getOutrightLeagues(requestDto);
expect(result).toBe(expectedResponse);
});
it('should use correct route for outright leagues', async () => {
const requestDto = new dtos_1.GetOutrightLeaguesRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeaguesRequest());
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeaguesResultElement());
await inplaySnapshotApiClient.getOutrightLeagues(requestDto);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetOutrightLeagues',
responseBodyType: responses_1.GetOutrightLeaguesResultElement,
requestBody: expect.any(requests_1.GetOutrightLeaguesRequest),
});
});
it('should handle mapper transformation correctly', async () => {
const requestDto = new dtos_1.GetOutrightLeaguesRequestDto();
const mappedRequest = new requests_1.GetOutrightLeaguesRequest();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeaguesResultElement());
await inplaySnapshotApiClient.getOutrightLeagues(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetOutrightLeaguesRequest);
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetOutrightLeaguesRequestDto();
const error = new errors_1.HttpResponseError('Outright Leagues Error');
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeaguesRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getOutrightLeagues(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetOutrightLeaguesRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeaguesRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getOutrightLeagues(requestDto);
expect(result).toBeUndefined();
});
});
describe('getOutrightLeagueMarkets', () => {
it('should successfully call getOutrightLeagueMarkets with valid request', async () => {
const requestDto = new dtos_1.GetOutrightLeagueMarketRequestDto();
const mappedRequest = new requests_1.GetOutrightLeagueMarketRequest();
const expectedResponse = new responses_1.GetOutrightLeagueMarketsResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getOutrightLeagueMarkets(requestDto);
expect(result).toBe(expectedResponse);
});
it('should use correct route for outright league markets', async () => {
const requestDto = new dtos_1.GetOutrightLeagueMarketRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueMarketRequest());
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeagueMarketsResultElement());
await inplaySnapshotApiClient.getOutrightLeagueMarkets(requestDto);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetOutrightLeagueMarkets',
responseBodyType: responses_1.GetOutrightLeagueMarketsResultElement,
requestBody: expect.any(requests_1.GetOutrightLeagueMarketRequest),
});
});
it('should handle mapper transformation correctly', async () => {
const requestDto = new dtos_1.GetOutrightLeagueMarketRequestDto();
const mappedRequest = new requests_1.GetOutrightLeagueMarketRequest();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeagueMarketsResultElement());
await inplaySnapshotApiClient.getOutrightLeagueMarkets(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetOutrightLeagueMarketRequest);
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetOutrightLeagueMarketRequestDto();
const error = new errors_1.HttpResponseError('Outright League Markets Error');
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueMarketRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getOutrightLeagueMarkets(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetOutrightLeagueMarketRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueMarketRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getOutrightLeagueMarkets(requestDto);
expect(result).toBeUndefined();
});
});
describe('getOutrightLeagueEvents', () => {
it('should successfully call getOutrightLeagueEvents with valid request', async () => {
const requestDto = new dtos_1.GetOutrightLeagueEventsRequestDto();
const mappedRequest = new requests_1.GetOutrightLeagueEventsRequest();
const expectedResponse = new responses_1.GetOutrightLeagueEventsResultElement();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(expectedResponse);
const result = await inplaySnapshotApiClient.getOutrightLeagueEvents(requestDto);
expect(result).toBe(expectedResponse);
});
it('should use correct route for outright league events', async () => {
const requestDto = new dtos_1.GetOutrightLeagueEventsRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueEventsRequest());
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeagueEventsResultElement());
await inplaySnapshotApiClient.getOutrightLeagueEvents(requestDto);
expect(mockPostRequest).toHaveBeenCalledWith({
route: '/Inplay/GetOutrightLeagueEvents',
responseBodyType: responses_1.GetOutrightLeagueEventsResultElement,
requestBody: expect.any(requests_1.GetOutrightLeagueEventsRequest),
});
});
it('should handle mapper transformation correctly', async () => {
const requestDto = new dtos_1.GetOutrightLeagueEventsRequestDto();
const mappedRequest = new requests_1.GetOutrightLeagueEventsRequest();
mockMapper.map.mockReturnValue(mappedRequest);
mockPostRequest.mockResolvedValue(new responses_1.GetOutrightLeagueEventsResultElement());
await inplaySnapshotApiClient.getOutrightLeagueEvents(requestDto);
expect(mockMapper.map).toHaveBeenCalledWith(requestDto, requests_1.GetOutrightLeagueEventsRequest);
});
it('should propagate HTTP errors', async () => {
const requestDto = new dtos_1.GetOutrightLeagueEventsRequestDto();
const error = new errors_1.HttpResponseError('Outright League Events Error');
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueEventsRequest());
mockPostRequest.mockRejectedValue(error);
await expect(inplaySnapshotApiClient.getOutrightLeagueEvents(requestDto)).rejects.toThrow(error);
});
it('should handle undefined response', async () => {
const requestDto = new dtos_1.GetOutrightLeagueEventsRequestDto();
mockMapper.map.mockReturnValue(new requests_1.GetOutrightLeagueEventsRequest());
mockPostRequest.mockResolvedValue(undefined);
const result = await inplaySnapshotApiClient.getOutrightLeagueEvents(requestDto);
expect(result).toBeUndefined();
});
});
});
//# sourceMappingURL=inplay-snapshot.service.spec.js.map