trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
79 lines • 4.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const class_transformer_1 = require("class-transformer");
const fixture_1 = require("../../../../src/entities/core-entities/fixture/fixture");
const subscription_1 = require("../../../../src/entities/core-entities/common/subscription");
const sport_1 = require("../../../../src/entities/core-entities/fixture/sport");
const location_1 = require("../../../../src/entities/core-entities/fixture/location");
const league_1 = require("../../../../src/entities/core-entities/fixture/league");
const participant_1 = require("../../../../src/entities/core-entities/fixture/participant");
const name_value_record_1 = require("../../../../src/entities/core-entities/common/name-value-record");
describe('Fixture Entity', () => {
it('should deserialize a plain object into a Fixture instance', () => {
const plain = {
Subscription: { id: 1 },
Sport: { id: 2, name: 'Football' },
Location: { id: 3, name: 'England' },
League: { id: 4, name: 'Premier League' },
StartDate: '2024-06-01T12:00:00Z',
LastUpdate: '2024-06-01T13:00:00Z',
Status: 'Scheduled',
Participants: [
{ id: 10, name: 'Team A' },
{ id: 11, name: 'Team B' },
],
FixtureExtraData: [{ name: 'Referee', value: 'John Doe' }],
};
const fixture = (0, class_transformer_1.plainToInstance)(fixture_1.Fixture, plain, { excludeExtraneousValues: true });
expect(fixture).toBeInstanceOf(fixture_1.Fixture);
expect(fixture.subscription).toBeInstanceOf(subscription_1.Subscription);
expect(fixture.sport).toBeInstanceOf(sport_1.Sport);
expect(fixture.location).toBeInstanceOf(location_1.Location);
expect(fixture.league).toBeInstanceOf(league_1.League);
expect(fixture.startDate).toBeInstanceOf(Date);
expect(fixture.startDate?.toISOString()).toBe('2024-06-01T12:00:00.000Z');
expect(fixture.lastUpdate).toBeInstanceOf(Date);
expect(fixture.lastUpdate?.toISOString()).toBe('2024-06-01T13:00:00.000Z');
expect(fixture.status).toBe('Scheduled');
expect(Array.isArray(fixture.participants)).toBe(true);
expect(fixture.participants?.[0]).toBeInstanceOf(participant_1.Participant);
expect(Array.isArray(fixture.fixtureExtraData)).toBe(true);
expect(fixture.fixtureExtraData?.[0]).toBeInstanceOf(name_value_record_1.NameValueRecord);
});
it('should handle missing optional properties', () => {
const plain = {
Sport: { id: 2, name: 'Football' },
Status: 'InProgress',
};
const fixture = (0, class_transformer_1.plainToInstance)(fixture_1.Fixture, plain, { excludeExtraneousValues: true });
expect(fixture.sport).toBeInstanceOf(sport_1.Sport);
expect(fixture.status).toBe('InProgress');
expect(fixture.subscription).toBeUndefined();
expect(fixture.location).toBeUndefined();
expect(fixture.league).toBeUndefined();
expect(fixture.startDate).toBeUndefined();
expect(fixture.lastUpdate).toBeUndefined();
expect(fixture.participants).toBeUndefined();
expect(fixture.fixtureExtraData).toBeUndefined();
});
it('should handle empty arrays for participants and fixtureExtraData', () => {
const plain = {
Participants: [],
FixtureExtraData: [],
};
const fixture = (0, class_transformer_1.plainToInstance)(fixture_1.Fixture, plain, { excludeExtraneousValues: true });
expect(Array.isArray(fixture.participants)).toBe(true);
expect(fixture.participants?.length).toBe(0);
expect(Array.isArray(fixture.fixtureExtraData)).toBe(true);
expect(fixture.fixtureExtraData?.length).toBe(0);
});
it('should ignore extraneous properties', () => {
const plain = {
Sport: { id: 2, name: 'Football' },
ExtraField: 'should be ignored',
};
const fixture = (0, class_transformer_1.plainToInstance)(fixture_1.Fixture, plain, { excludeExtraneousValues: true });
expect(fixture.ExtraField).toBeUndefined();
});
});
//# sourceMappingURL=fixture.spec.js.map