@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
37 lines (36 loc) • 2.57 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const activity_1 = require("../../../activities/activity");
const activity_types_1 = require("../../../activities/activity.types");
const creator_1 = require("../../../creators/creator");
const data_distance_1 = require("../../../data/data.distance");
const event_1 = require("../../event");
const file_type_enum_1 = require("../file-type.enum");
const exporter_json_1 = require("./exporter.json");
const stream_1 = require("../../../streams/stream");
describe('EventExporterJSON', () => {
it('should export the same JSON payload as event.toJSON()', () => {
const event = new event_1.Event('json-export', new Date(0), new Date(3000), file_type_enum_1.FileType.FIT);
const activity = new activity_1.Activity(new Date(0), new Date(3000), activity_types_1.ActivityTypes.Running, new creator_1.Creator('Test'));
activity.addStream(new stream_1.Stream(data_distance_1.DataDistance.type, [0, null, null, 30]));
event.addActivity(activity);
expect(exporter_json_1.EventExporterJSON.export(event)).toEqual(event.toJSON());
});
it('should stringify exported events without altering their JSON structure', () => __awaiter(void 0, void 0, void 0, function* () {
const event = new event_1.Event('json-export', new Date(0), new Date(3000), file_type_enum_1.FileType.FIT);
const activity = new activity_1.Activity(new Date(0), new Date(3000), activity_types_1.ActivityTypes.Running, new creator_1.Creator('Test'));
activity.addStream(new stream_1.Stream(data_distance_1.DataDistance.type, [0, 10, 20, 30]));
event.addActivity(activity);
const exported = exporter_json_1.EventExporterJSON.export(event);
yield expect(exporter_json_1.EventExporterJSON.getAsString(event)).resolves.toEqual(JSON.stringify(exported));
}));
});