2023-11-11 17:12:20 +01:00
|
|
|
import { describe, it, expect } from 'vitest'
|
2021-09-22 10:39:25 +02:00
|
|
|
|
2021-10-01 16:48:48 +02:00
|
|
|
import { translatedSports } from './fixtures'
|
2021-09-22 10:39:25 +02:00
|
|
|
|
|
|
|
import { formatRecord, getRecordsBySports } from '@/utils/records'
|
|
|
|
|
|
|
|
describe('formatRecord', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Average speed'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Farest distance'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/MM/dd',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km',
|
|
|
|
workout_date: '2019/07/08',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Longest duration'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 11,
|
|
|
|
record_type: 'LD',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: '1:01:00',
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/MM/dd',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 11,
|
|
|
|
record_type: 'LD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '1:01:00',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Max. speed'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'dd/MM/yyyy',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km/h',
|
2022-10-25 23:27:05 +02:00
|
|
|
workout_date: '08/07/2019',
|
2021-09-22 10:39:25 +02:00
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
2022-07-18 15:29:24 +02:00
|
|
|
{
|
|
|
|
description: "return formatted record for 'Highest ascent'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 13,
|
|
|
|
record_type: 'HA',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 100,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'MMM. do, yyyy',
|
2022-07-18 15:29:24 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 13,
|
|
|
|
record_type: 'HA',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2022-07-18 15:29:24 +02:00
|
|
|
value: '100 m',
|
2022-10-25 23:27:05 +02:00
|
|
|
workout_date: 'Jul. 7th, 2019',
|
2022-07-18 15:29:24 +02:00
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
2021-09-22 10:39:25 +02:00
|
|
|
]
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2021-09-22 10:39:25 +02:00
|
|
|
formatRecord(
|
|
|
|
testParams.inputParams.record,
|
2021-11-14 12:12:21 +01:00
|
|
|
testParams.inputParams.timezone,
|
2022-10-25 23:27:05 +02:00
|
|
|
false,
|
|
|
|
testParams.inputParams.date_format
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2021-11-14 12:12:21 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('formatRecord after conversion', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Average speed'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '11.18 mi/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Farest distance'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 17:52:36 +01:00
|
|
|
value: '11.185 mi',
|
2022-10-26 01:38:55 +02:00
|
|
|
workout_date: '2019/08/07',
|
2021-11-14 12:12:21 +01:00
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Longest duration'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 11,
|
|
|
|
record_type: 'LD',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: '1:01:00',
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 11,
|
|
|
|
record_type: 'LD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '1:01:00',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "return formatted record for 'Max. speed'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '11.18 mi/h',
|
2022-10-26 01:38:55 +02:00
|
|
|
workout_date: '2019/08/07',
|
2021-11-14 12:12:21 +01:00
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
2022-07-18 15:29:24 +02:00
|
|
|
{
|
|
|
|
description: "return formatted record for 'Highest ascent'",
|
|
|
|
inputParams: {
|
|
|
|
record: {
|
|
|
|
id: 13,
|
|
|
|
record_type: 'HA',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 100,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
timezone: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2022-07-18 15:29:24 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: 13,
|
|
|
|
record_type: 'HA',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2022-07-18 15:29:24 +02:00
|
|
|
value: '328.08 ft',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
},
|
2021-11-14 12:12:21 +01:00
|
|
|
]
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2021-11-14 12:12:21 +01:00
|
|
|
formatRecord(
|
|
|
|
testParams.inputParams.record,
|
|
|
|
testParams.inputParams.timezone,
|
2022-10-25 23:27:05 +02:00
|
|
|
true,
|
|
|
|
testParams.inputParams.date_format
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2021-09-22 10:39:25 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('formatRecord (invalid record type)', () => {
|
|
|
|
it('it throws an error if record type is invalid', () => {
|
|
|
|
expect(() =>
|
|
|
|
formatRecord(
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
record_type: 'M',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
2021-11-14 12:12:21 +01:00
|
|
|
'Europe/Paris',
|
2022-10-25 23:27:05 +02:00
|
|
|
false,
|
|
|
|
'yyyy/dd/MM'
|
2021-09-22 10:39:25 +02:00
|
|
|
)
|
|
|
|
).to.throw(
|
2022-07-18 15:37:30 +02:00
|
|
|
'Invalid record type, expected: "AS", "FD", "HA", "LD", "MD", got: "M"'
|
2021-09-22 10:39:25 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getRecordsBySports', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns empty object if no records',
|
|
|
|
input: {
|
|
|
|
records: [],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns record grouped by Sport',
|
|
|
|
input: {
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
'Cycling (Sport)': {
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns record grouped by Sport',
|
|
|
|
input: {
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
|
|
|
sport_id: 2,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'n6JcLPQt3QtZWFfiSnYm4C',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
'Cycling (Sport)': {
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
'Cycling (Transport)': {
|
2021-11-12 18:52:08 +01:00
|
|
|
color: '#000000',
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Transport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 2,
|
|
|
|
user: 'admin',
|
2021-09-22 10:39:25 +02:00
|
|
|
value: '18 km',
|
2022-10-26 01:38:55 +02:00
|
|
|
workout_date: '2019/08/07',
|
2021-09-22 10:39:25 +02:00
|
|
|
workout_id: 'n6JcLPQt3QtZWFfiSnYm4C',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testsParams.map((testParams) =>
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2021-09-22 10:39:25 +02:00
|
|
|
getRecordsBySports(
|
|
|
|
testParams.input.records,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedSports,
|
2021-11-14 12:12:21 +01:00
|
|
|
testParams.input.tz,
|
2022-07-23 08:20:02 +02:00
|
|
|
false,
|
2022-10-25 23:27:05 +02:00
|
|
|
true,
|
|
|
|
testParams.input.date_format
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2021-11-14 12:12:21 +01:00
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getRecordsBySports after conversion', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns empty object if no records',
|
|
|
|
input: {
|
|
|
|
records: [],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns record grouped by Sport',
|
|
|
|
input: {
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
'Cycling (Sport)': {
|
|
|
|
color: null,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '11.18 mi/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns record grouped by Sport',
|
|
|
|
input: {
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
|
|
|
sport_id: 2,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 22:00:00 GMT',
|
|
|
|
workout_id: 'n6JcLPQt3QtZWFfiSnYm4C',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2021-11-14 12:12:21 +01:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
'Cycling (Sport)': {
|
|
|
|
color: null,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '11.18 mi/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
record_type: 'MS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2021-11-14 12:12:21 +01:00
|
|
|
value: '11.18 mi/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
'Cycling (Transport)': {
|
|
|
|
color: '#000000',
|
|
|
|
label: 'Cycling (Transport)',
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 10,
|
|
|
|
record_type: 'FD',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 2,
|
|
|
|
user: 'admin',
|
2021-11-14 17:52:36 +01:00
|
|
|
value: '11.185 mi',
|
2022-10-26 01:38:55 +02:00
|
|
|
workout_date: '2019/08/07',
|
2021-11-14 12:12:21 +01:00
|
|
|
workout_id: 'n6JcLPQt3QtZWFfiSnYm4C',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testsParams.map((testParams) =>
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2021-11-14 12:12:21 +01:00
|
|
|
getRecordsBySports(
|
|
|
|
testParams.input.records,
|
|
|
|
translatedSports,
|
|
|
|
testParams.input.tz,
|
2022-07-23 08:20:02 +02:00
|
|
|
true,
|
2022-10-25 23:27:05 +02:00
|
|
|
true,
|
|
|
|
testParams.input.date_format
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2021-09-22 10:39:25 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
2022-07-23 08:20:02 +02:00
|
|
|
|
|
|
|
describe('getRecordsBySports with HA record', () => {
|
|
|
|
const testsParams = [
|
|
|
|
{
|
|
|
|
description: 'returns empty object if no records',
|
|
|
|
input: {
|
|
|
|
records: [],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2022-07-23 08:20:02 +02:00
|
|
|
},
|
|
|
|
expected: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns records except HA record',
|
|
|
|
input: {
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 18,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'HA',
|
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
|
|
|
value: 235,
|
|
|
|
workout_date: 'Sun, 07 Jul 2019 08:00:00 GMT',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tz: 'Europe/Paris',
|
2023-11-11 17:12:20 +01:00
|
|
|
date_format: 'yyyy/dd/MM',
|
2022-07-23 08:20:02 +02:00
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
'Cycling (Sport)': {
|
|
|
|
color: null,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
records: [
|
|
|
|
{
|
|
|
|
id: 9,
|
|
|
|
record_type: 'AS',
|
2023-11-11 20:16:18 +01:00
|
|
|
sport_id: 1,
|
|
|
|
user: 'admin',
|
2022-07-23 08:20:02 +02:00
|
|
|
value: '18 km/h',
|
|
|
|
workout_date: '2019/07/07',
|
|
|
|
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testsParams.map((testParams) =>
|
|
|
|
it(testParams.description, () => {
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2022-07-23 08:20:02 +02:00
|
|
|
getRecordsBySports(
|
|
|
|
testParams.input.records,
|
|
|
|
translatedSports,
|
|
|
|
testParams.input.tz,
|
|
|
|
false,
|
2022-10-25 23:27:05 +02:00
|
|
|
false,
|
|
|
|
testParams.input.date_format
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2022-07-23 08:20:02 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|