trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
60 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const class_transformer_1 = require("class-transformer");
const outright_participant_1 = require("../../../../src/entities/core-entities/outright-sport/outright-participant");
const name_value_record_1 = require("../../../../src/entities/core-entities/common/name-value-record");
const active_participant_1 = require("../../../../src/entities/core-entities/enums/active-participant");
describe('OutrightParticipant', () => {
it('should deserialize a plain object into an OutrightParticipant instance', () => {
const plain = {
Id: 1,
Name: 'Participant 1',
Position: '1st',
RotationId: 150,
IsActive: active_participant_1.ActiveParticipant.Active,
ExtraData: [{ Name: 'foo', Value: 'bar' }],
};
const participant = (0, class_transformer_1.plainToInstance)(outright_participant_1.OutrightParticipant, plain, {
excludeExtraneousValues: true,
});
expect(participant).toBeInstanceOf(outright_participant_1.OutrightParticipant);
expect(participant.id).toBe(1);
expect(participant.name).toBe('Participant 1');
expect(participant.position).toBe('1st');
expect(participant.rotationId).toBe(150);
expect(participant.isActive).toBe(active_participant_1.ActiveParticipant.Active);
expect(Array.isArray(participant.extraData)).toBe(true);
expect(participant.extraData?.[0]).toBeInstanceOf(name_value_record_1.NameValueRecord);
});
it('should handle missing properties', () => {
const plain = {};
const participant = (0, class_transformer_1.plainToInstance)(outright_participant_1.OutrightParticipant, plain, {
excludeExtraneousValues: true,
});
expect(participant.id).toBeUndefined();
expect(participant.name).toBeUndefined();
expect(participant.position).toBeUndefined();
expect(participant.rotationId).toBeUndefined();
expect(participant.isActive).toBeUndefined();
expect(participant.extraData).toBeUndefined();
});
it('should ignore extraneous properties', () => {
const plain = { Id: 2, Extra: 'ignore me' };
const participant = (0, class_transformer_1.plainToInstance)(outright_participant_1.OutrightParticipant, plain, {
excludeExtraneousValues: true,
});
expect(participant.Extra).toBeUndefined();
});
it('should deserialize rotationId property correctly', () => {
const plain = {
Id: 3,
Name: 'Participant 3',
RotationId: 300,
};
const participant = (0, class_transformer_1.plainToInstance)(outright_participant_1.OutrightParticipant, plain, {
excludeExtraneousValues: true,
});
expect(participant.rotationId).toBe(300);
});
});
//# sourceMappingURL=outright-participant.spec.js.map