@sports-alliance/sports-lib
Version:
A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc
88 lines (87 loc) • 5.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const importer_fit_1 = require("./importer.fit");
const activity_1 = require("../../../../activities/activity");
const activity_types_1 = require("../../../../activities/activity.types");
const creator_1 = require("../../../../creators/creator");
const data_avg_respiration_rate_1 = require("../../../../data/data.avg-respiration-rate");
const data_max_respiration_rate_1 = require("../../../../data/data.max-respiration-rate");
const data_min_respiration_rate_1 = require("../../../../data/data.min-respiration-rate");
const data_recovery_time_1 = require("../../../../data/data.recovery-time");
const data_vo2_max_1 = require("../../../../data/data.vo2-max");
describe('EventImporterFIT Zero Handling', () => {
let mockActivity;
beforeEach(() => {
mockActivity = new activity_1.Activity(new Date(), new Date(), activity_types_1.ActivityTypes.Running, new creator_1.Creator('Initial'));
});
describe('getStatsFromObject', () => {
it('should correctly handle 0 values for respiration rates', () => {
const fitObject = {
enhanced_avg_respiration_rate: 0,
enhanced_max_respiration_rate: 0,
enhanced_min_respiration_rate: 0,
};
const stats = importer_fit_1.EventImporterFIT.getStatsFromObject(fitObject, mockActivity, false);
const avgResp = stats.find(s => s.getType() === data_avg_respiration_rate_1.DataAvgRespirationRate.type);
const maxResp = stats.find(s => s.getType() === data_max_respiration_rate_1.DataMaxRespirationRate.type);
const minResp = stats.find(s => s.getType() === data_min_respiration_rate_1.DataMinRespirationRate.type);
expect(avgResp).toBeDefined();
expect(avgResp === null || avgResp === void 0 ? void 0 : avgResp.getValue()).toBe(0);
expect(maxResp).toBeDefined();
expect(maxResp === null || maxResp === void 0 ? void 0 : maxResp.getValue()).toBe(0);
expect(minResp).toBeDefined();
expect(minResp === null || minResp === void 0 ? void 0 : minResp.getValue()).toBe(0);
});
it('should correctly handle 0 values for respiration rates (fallback fields)', () => {
// mixed case where enhanced is undefined but standard is 0
const fitObject = {
avg_respiration_rate: 0,
max_respiration_rate: 0,
min_respiration_rate: 0,
};
const stats = importer_fit_1.EventImporterFIT.getStatsFromObject(fitObject, mockActivity, false);
const avgResp = stats.find(s => s.getType() === data_avg_respiration_rate_1.DataAvgRespirationRate.type);
const maxResp = stats.find(s => s.getType() === data_max_respiration_rate_1.DataMaxRespirationRate.type);
const minResp = stats.find(s => s.getType() === data_min_respiration_rate_1.DataMinRespirationRate.type);
expect(avgResp).toBeDefined();
expect(avgResp === null || avgResp === void 0 ? void 0 : avgResp.getValue()).toBe(0);
expect(maxResp).toBeDefined();
expect(maxResp === null || maxResp === void 0 ? void 0 : maxResp.getValue()).toBe(0);
expect(minResp).toBeDefined();
expect(minResp === null || minResp === void 0 ? void 0 : minResp.getValue()).toBe(0);
});
it('should ignore 0 values for VO2 max and recovery time', () => {
const fitObject = {
estimated_vo2_max: 0,
recovery_time: 0,
};
const stats = importer_fit_1.EventImporterFIT.getStatsFromObject(fitObject, mockActivity, false);
const vo2 = stats.find(s => s.getType() === data_vo2_max_1.DataVO2Max.type);
const recovery = stats.find(s => s.getType() === data_recovery_time_1.DataRecoveryTime.type);
expect(vo2).toBeUndefined();
expect(recovery).toBeUndefined();
});
it('should ignore irrational VO2 max values', () => {
const fitObject = {
estimated_vo2_max: 114688,
vo2_max_cycling: 500,
};
const stats = importer_fit_1.EventImporterFIT.getStatsFromObject(fitObject, mockActivity, false);
const vo2 = stats.find(s => s.getType() === data_vo2_max_1.DataVO2Max.type);
expect(vo2).toBeUndefined();
});
it('should keep positive values for VO2 max and recovery time', () => {
const fitObject = {
estimated_vo2_max: 57.2,
recovery_time: 7200,
};
const stats = importer_fit_1.EventImporterFIT.getStatsFromObject(fitObject, mockActivity, false);
const vo2 = stats.find(s => s.getType() === data_vo2_max_1.DataVO2Max.type);
const recovery = stats.find(s => s.getType() === data_recovery_time_1.DataRecoveryTime.type);
expect(vo2).toBeDefined();
expect(vo2 === null || vo2 === void 0 ? void 0 : vo2.getValue()).toBe(57.2);
expect(recovery).toBeDefined();
expect(recovery === null || recovery === void 0 ? void 0 : recovery.getValue()).toBe(7200);
});
});
});