feat: add hevy pro api import
This commit is contained in:
1 parent
cb24bf12d7
commit
45f7541508
21 files changed
+1803
-3
No files matched your search
@@ -0,0 +1,291 @@
|
||||
// AUTO-GENERATED by scripts/build-hevy-id-map.mjs — do not edit by hand.
|
||||
// Hevy exercise_template id → openGym catalogue id.
|
||||
// Regenerated from the Hevy templates API + verified title aliases.
|
||||
// 283 mapped · 168 left unmatched (import as custom).
|
||||
// Source templates: 451 (built-in only).
|
||||
|
||||
export const HEVY_ID_MAP = {
|
||||
"018ADC12": "3017",
|
||||
"01A35BF9": "2404",
|
||||
"023943F1": "0572",
|
||||
"026FD047": "0407",
|
||||
"0393F233": "0218",
|
||||
"040BA2E3": "2612",
|
||||
"046E25A2": "0673",
|
||||
"0482DA98": "0826",
|
||||
"05293BCA": "3142",
|
||||
"059E835D": "0603",
|
||||
"062AB91A": "0594",
|
||||
"06745E58": "1372",
|
||||
"073032BB": "1457",
|
||||
"07B38369": "0314",
|
||||
"084A67CA": "0128",
|
||||
"08590920": "0472",
|
||||
"08A2974E": "0606",
|
||||
"091737FA": "0573",
|
||||
"09C9F635": "0865",
|
||||
"0B4C1902": "0294",
|
||||
"0B841777": "0095",
|
||||
"0B9B92BA": "0085",
|
||||
"0EB695C9": "2611",
|
||||
"0F24286A": "0099",
|
||||
"0FBF7195": "0748",
|
||||
"1006DF48": "0401",
|
||||
"10313AFD": "0550",
|
||||
"10347BAC": "0591",
|
||||
"10D76E8F": "1273",
|
||||
"112FC6B7": "0080",
|
||||
"11A123F3": "0586",
|
||||
"12017185": "0308",
|
||||
"123EE239": "0439",
|
||||
"1283BBA6": "0043",
|
||||
"150E076B": "3655",
|
||||
"18487FA7": "0301",
|
||||
"19372ABC": "0662",
|
||||
"19A38071": "0604",
|
||||
"1B2B1E7C": "0652",
|
||||
"1B89CA1B": "0521",
|
||||
"1D4B3D6B": "0313",
|
||||
"1DF4A847": "1350",
|
||||
"1E42FD5F": "0743",
|
||||
"1E9A6B8E": "0592",
|
||||
"20870ED5": "0752",
|
||||
"20C1A3CB": "0809",
|
||||
"21310F5F": "0607",
|
||||
"218DA87C": "0803",
|
||||
"22578A94": "0168",
|
||||
"234897AB": "0165",
|
||||
"23A48484": "0175",
|
||||
"23E92538": "0292",
|
||||
"243710DE": "3666",
|
||||
"286C1D0B": "0246",
|
||||
"28BB4A95": "0591",
|
||||
"29083183": "1326",
|
||||
"29472BE1": "0251",
|
||||
"2982AA23": "0687",
|
||||
"2A48E443": "0116",
|
||||
"2B4B7310": "0085",
|
||||
"2C37EC5E": "0017",
|
||||
"2CFED196": "0069",
|
||||
"2F8D3067": "0607",
|
||||
"2FA77B28": "0459",
|
||||
"3092FADD": "0607",
|
||||
"32B0B590": "0507",
|
||||
"32C4D4A2": "0298",
|
||||
"32HKJ34K": "1460",
|
||||
"3303376C": "2141",
|
||||
"33EDD7DB": "1460",
|
||||
"35B51B87": "0030",
|
||||
"3601968B": "0289",
|
||||
"36E8F14E": "0165",
|
||||
"3765684D": "0607",
|
||||
"37FCC2BB": "0294",
|
||||
"392887AA": "0662",
|
||||
"39C99849": "0493",
|
||||
"3A6FA3D1": "0757",
|
||||
"3D0C7C75": "1760",
|
||||
"3F5F8D40": "3142",
|
||||
"3FF6A22E": "0544",
|
||||
"40C6A9FC": "0127",
|
||||
"4180C405": "0044",
|
||||
"422B08F1": "0334",
|
||||
"425805F4": "0499",
|
||||
"43573BB8": "0003",
|
||||
"4377A52B": "2311",
|
||||
"4377A52C": "2311",
|
||||
"473CF5B8": "0673",
|
||||
"47B036EF": "0978",
|
||||
"49C922A1": "1409",
|
||||
"4B4BF8C2": "0019",
|
||||
"4E5257DE": "2616",
|
||||
"4F5866F8": "0573",
|
||||
"4F942934": "0070",
|
||||
"5046D0A9": "0042",
|
||||
"50C613D0": "2133",
|
||||
"50DFDFAB": "0047",
|
||||
"5122E7D9": "1451",
|
||||
"51A0EDAA": "0677",
|
||||
"542F3CD5": "1700",
|
||||
"55E6546F": "0027",
|
||||
"56808FD2": "0970",
|
||||
"582ADA23": "1636",
|
||||
"5E10D0E6": "3142",
|
||||
"5E1A7777": "0054",
|
||||
"5F4E6DD3": "0300",
|
||||
"5F8903BF": "0551",
|
||||
"6120CAAB": "0795",
|
||||
"6182EE83": "0607",
|
||||
"651F844C": "1269",
|
||||
"6575F52D": "0283",
|
||||
"6622E5A0": "3142",
|
||||
"67280085": "0375",
|
||||
"68B83EE0": "3193",
|
||||
"68F8A292": "0060",
|
||||
"6A6C31A5": "2330",
|
||||
"6AC96645": "0405",
|
||||
"6DA40660": "0417",
|
||||
"6E6EE645": "0054",
|
||||
"6FCD7755": "0251",
|
||||
"70D4EBBF": "0514",
|
||||
"72297E8C": "5201",
|
||||
"724CDE60": "0297",
|
||||
"729237D1": "0652",
|
||||
"72CFFAD5": "1459",
|
||||
"74103F24": "0052",
|
||||
"742E5BD5": "0767",
|
||||
"75A4F6C4": "0585",
|
||||
"78683336": "0596",
|
||||
"7952B5CD": "0872",
|
||||
"796E8E2C": "0834",
|
||||
"797F0782": "0437",
|
||||
"79D0BB3A": "0025",
|
||||
"7AB9A362": "0120",
|
||||
"7B8D84E8": "0091",
|
||||
"7C0028C3": "0593",
|
||||
"7C50F118": "1429",
|
||||
"7E3BC8B6": "0312",
|
||||
"7EB3F7C3": "0577",
|
||||
"818BA121": "0078",
|
||||
"8293E554": "0310",
|
||||
"875F585F": "0060",
|
||||
"878CD1D0": "0405",
|
||||
"89304423": "0529",
|
||||
"8A2E6481": "0180",
|
||||
"8BAB2735": "0318",
|
||||
"8BEBFED6": "0598",
|
||||
"8C331CD8": "0196",
|
||||
"8C9D2928": "1494",
|
||||
"90427D4A": "1675",
|
||||
"90B04F96": "0471",
|
||||
"90E506D5": "3305",
|
||||
"91237BDD": "2289",
|
||||
"914F3A96": "0327",
|
||||
"91AF29E0": "0091",
|
||||
"9237BAD1": "0603",
|
||||
"923874CA": "0562",
|
||||
"9273BA17": "0237",
|
||||
"9283BABA": "0858",
|
||||
"92D858EA": "0243",
|
||||
"9372FFAA": "0396",
|
||||
"93A552C6": "0241",
|
||||
"947DAC23": "0259",
|
||||
"95F2E076": "1426",
|
||||
"9694DA61": "3543",
|
||||
"98237BA2": "0826",
|
||||
"991833C2": "3220",
|
||||
"9930DF71": "0091",
|
||||
"99507114": "0032",
|
||||
"99B49684": "3663",
|
||||
"99C1F2AD": "0151",
|
||||
"99D5F10E": "0857",
|
||||
"9B13BA4B": "0548",
|
||||
"9DCE2D64": "0596",
|
||||
"9F48F858": "0206",
|
||||
"9F9C164B": "0631",
|
||||
"A01BE509": "0443",
|
||||
"A05C064D": "0573",
|
||||
"A0D8FA1B": "2271",
|
||||
"A127DA73": "0534",
|
||||
"A2D838BD": "0243",
|
||||
"A41C7261": "0972",
|
||||
"A57D38D5": "0815",
|
||||
"A5AC6449": "0031",
|
||||
"A69FF221": "2137",
|
||||
"A733CC5B": "1460",
|
||||
"A8814C06": "1003",
|
||||
"AA1EB7D8": "0571",
|
||||
"AA52E8D2": "0773",
|
||||
"ABB00838": "0028",
|
||||
"ABEC557F": "0406",
|
||||
"AC5A4C58": "0046",
|
||||
"ADA8623C": "0868",
|
||||
"AF328E3D": "0575",
|
||||
"B05C2C29": "0605",
|
||||
"B09A1304": "0766",
|
||||
"B123DD01": "2285",
|
||||
"B2398CD1": "0277",
|
||||
"B3B1D947": "3360",
|
||||
"B537D09F": "0336",
|
||||
"B582299E": "0383",
|
||||
"B5D3A742": "0410",
|
||||
"B5EFBF9C": "0194",
|
||||
"B74A95BB": "3211",
|
||||
"B8127AD1": "0586",
|
||||
"B82D6418": "0043",
|
||||
"B923B230": "0811",
|
||||
"BB792A36": "1160",
|
||||
"BB83BDDE": "0687",
|
||||
"BC10A922": "0277",
|
||||
"BD4E7E53": "0535",
|
||||
"BD86EFD5": "0041",
|
||||
"BE289E45": "0178",
|
||||
"BE640BA0": "0203",
|
||||
"BF6ECE89": "0431",
|
||||
"C315DC2A": "0602",
|
||||
"C43825EA": "0279",
|
||||
"C469EA70": "0597",
|
||||
"C6272009": "0032",
|
||||
"C628D768": "0648",
|
||||
"C6C9B8A0": "2135",
|
||||
"C7973E0E": "0739",
|
||||
"C7AE420A": "0688",
|
||||
"C8706C80": "0624",
|
||||
"CC35A01F": "0043",
|
||||
"CC55119B": "0979",
|
||||
"CD6DC8E5": "0830",
|
||||
"D04AC939": "0043",
|
||||
"D20D7BBE": "0117",
|
||||
"D23C609B": "0572",
|
||||
"D2FE7B2E": "2330",
|
||||
"D3095577": "0028",
|
||||
"D3E2AB55": "0319",
|
||||
"D4A2FE7E": "2143",
|
||||
"D53F2886": "0065",
|
||||
"D5D0354D": "0584",
|
||||
"D8281C62": "0602",
|
||||
"D82EA543": "0983",
|
||||
"D8460FA6": "0385",
|
||||
"D8911FC4": "0276",
|
||||
"D8F7F851": "2331",
|
||||
"D928C232": "0832",
|
||||
"D950429E": "0038",
|
||||
"DA0F0470": "0033",
|
||||
"DBB91A3C": "0162",
|
||||
"DBE341AA": "1495",
|
||||
"DBF9273A": "0310",
|
||||
"DCF3B31B": "0832",
|
||||
"DCFF3E9F": "0413",
|
||||
"DDCC3821": "0770",
|
||||
"DE68C825": "0192",
|
||||
"DF200976": "0977",
|
||||
"E05C2C38": "0605",
|
||||
"E3EDA509": "1775",
|
||||
"E53CCBE5": "1372",
|
||||
"E5988A0A": "0383",
|
||||
"E644F828": "1258",
|
||||
"E9E4089F": "0009",
|
||||
"EA820646": "0027",
|
||||
"EAC7D9C5": "3124",
|
||||
"EB43ADD4": "1452",
|
||||
"EB813C91": "1359",
|
||||
"F1258206": "1004",
|
||||
"F1D60854": "0218",
|
||||
"F1E57334": "0292",
|
||||
"F2A37357": "1410",
|
||||
"F30A4F01": "1460",
|
||||
"F3717B0E": "3888",
|
||||
"F49E31D6": "0630",
|
||||
"F4B4C6EE": "0597",
|
||||
"F5DEF1EB": "1489",
|
||||
"F8356514": "0472",
|
||||
"F8A0FCCA": "0549",
|
||||
"F99C211D": "0535",
|
||||
"FAB6EB2F": "0372",
|
||||
"FAF31231": "0033",
|
||||
"FB09C938": "0067",
|
||||
"FBF92739": "1299",
|
||||
"FE389074": "0074",
|
||||
"FFABC123": "0220",
|
||||
"FFC106CB": "0753",
|
||||
"FFDA283B": "0381",
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
// Import a Hevy account through the public API (https://api.hevyapp.com/docs/).
|
||||
//
|
||||
// Exercise identity is Hevy's `exercise_template_id`, looked up in the generated
|
||||
// `hevy-id-map.js` table — never the localized title on a set. Regenerate the map
|
||||
// with `node scripts/build-hevy-id-map.mjs`. The API key never leaves this module's
|
||||
// callers: nothing here stores it.
|
||||
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { uid } from './format.js'
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
import { HEVY_ID_MAP } from './hevy-id-map.js'
|
||||
|
||||
export { HEVY_ID_MAP }
|
||||
export const HEVY_API = 'https://api.hevyapp.com'
|
||||
export const HEVY_DEV_SETTINGS = 'https://hevy.com/settings?developer'
|
||||
|
||||
const LB_TO_KG = 0.45359237
|
||||
|
||||
/* --------------------------------------------------------------- auth/fetch -- */
|
||||
|
||||
class HevyApiError extends Error {
|
||||
constructor(status, message) {
|
||||
super(message || `Hevy API error ${status}`)
|
||||
this.name = 'HevyApiError'
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
|
||||
async function hevyGet(path, apiKey, params = {}) {
|
||||
const url = new URL(path, HEVY_API)
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v != null && v !== '') url.searchParams.set(k, String(v))
|
||||
}
|
||||
const res = await fetch(url, { headers: { 'api-key': apiKey } })
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
throw new HevyApiError(res.status, 'auth')
|
||||
}
|
||||
if (!res.ok) throw new HevyApiError(res.status, `http ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
/** Page through a Hevy list endpoint. `pageSize` caps differ per resource. */
|
||||
export async function fetchHevyPages(path, apiKey, {
|
||||
resultKey,
|
||||
pageSize = 10,
|
||||
onProgress,
|
||||
} = {}) {
|
||||
const items = []
|
||||
let page = 1
|
||||
let pageCount = 1
|
||||
while (page <= pageCount) {
|
||||
const data = await hevyGet(path, apiKey, { page, pageSize })
|
||||
pageCount = Math.max(1, data.page_count || 1)
|
||||
const batch = data[resultKey] || []
|
||||
items.push(...batch)
|
||||
onProgress && onProgress({ page, pageCount, loaded: items.length, resultKey })
|
||||
if (!batch.length) break
|
||||
page++
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
export async function fetchHevyAccount(apiKey, { onProgress } = {}) {
|
||||
const key = String(apiKey || '').trim()
|
||||
if (!key) throw new HevyApiError(0, 'empty')
|
||||
|
||||
const templates = await fetchHevyPages('/v1/exercise_templates', key, {
|
||||
resultKey: 'exercise_templates', pageSize: 100,
|
||||
onProgress: p => onProgress && onProgress({ stage: 'templates', ...p }),
|
||||
})
|
||||
const workouts = await fetchHevyPages('/v1/workouts', key, {
|
||||
resultKey: 'workouts', pageSize: 10,
|
||||
onProgress: p => onProgress && onProgress({ stage: 'workouts', ...p }),
|
||||
})
|
||||
const routines = await fetchHevyPages('/v1/routines', key, {
|
||||
resultKey: 'routines', pageSize: 10,
|
||||
onProgress: p => onProgress && onProgress({ stage: 'routines', ...p }),
|
||||
})
|
||||
let bodyMeasurements = []
|
||||
try {
|
||||
bodyMeasurements = await fetchHevyPages('/v1/body_measurements', key, {
|
||||
resultKey: 'body_measurements', pageSize: 10,
|
||||
onProgress: p => onProgress && onProgress({ stage: 'body', ...p }),
|
||||
})
|
||||
} catch (e) {
|
||||
// Older keys / accounts may lack measurements — workouts still import.
|
||||
if (!(e instanceof HevyApiError) || e.message === 'auth') throw e
|
||||
}
|
||||
return { templates, workouts, routines, bodyMeasurements }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- template → id -- */
|
||||
|
||||
// Hevy primary_muscle_group → openGym body-part for exercises we invent.
|
||||
const HEVY_BP = {
|
||||
biceps: 'upper arms', triceps: 'upper arms', forearms: 'lower arms',
|
||||
chest: 'chest', lats: 'back', upper_back: 'back', lower_back: 'back',
|
||||
traps: 'back', shoulders: 'shoulders',
|
||||
abdominals: 'waist', abs: 'waist', obliques: 'waist',
|
||||
quadriceps: 'upper legs', hamstrings: 'upper legs', glutes: 'upper legs',
|
||||
abductors: 'upper legs', adductors: 'upper legs', calves: 'lower legs',
|
||||
cardio: 'cardio', full_body: 'upper legs', other: 'upper legs', neck: 'neck',
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a Hevy exercise template to a catalogue id.
|
||||
*
|
||||
* Deterministic: only `HEVY_ID_MAP` (generated by scripts/build-hevy-id-map.mjs).
|
||||
* No runtime name guessing — unmatched templates become custom exercises.
|
||||
*/
|
||||
export function matchHevyTemplate(template) {
|
||||
if (!template?.id) return null
|
||||
const id = HEVY_ID_MAP[template.id]
|
||||
return id && EXIDX[id] ? id : null
|
||||
}
|
||||
|
||||
/** Build templateId → catalogue id (or null) from a templates list. */
|
||||
export function buildHevyExerciseMap(templates) {
|
||||
const map = new Map()
|
||||
for (const t of templates || []) {
|
||||
if (!t?.id) continue
|
||||
map.set(t.id, matchHevyTemplate(t))
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- parse ---- */
|
||||
|
||||
const p2 = n => String(n).padStart(2, '0')
|
||||
|
||||
/** Hevy ISO timestamps → local calendar date + ms-since-midnight (matches CSV import). */
|
||||
export function localWhen(iso) {
|
||||
const d = new Date(iso)
|
||||
if (isNaN(d.getTime())) return null
|
||||
const day = `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`
|
||||
const t = d.getHours() * 3600000 + d.getMinutes() * 60000 + d.getSeconds() * 1000
|
||||
return { d: day, t }
|
||||
}
|
||||
|
||||
function bpOfTemplate(t) {
|
||||
const g = String(t?.primary_muscle_group || '').toLowerCase()
|
||||
return HEVY_BP[g] || 'upper legs'
|
||||
}
|
||||
|
||||
/** Shared resolver: HEVY_ID_MAP hit, else one custom exercise per Hevy template id. */
|
||||
function makeResolver(templates) {
|
||||
const byId = new Map((templates || []).map(t => [t.id, t]))
|
||||
const created = new Map()
|
||||
const unmatched = new Set()
|
||||
const matchedIds = new Set()
|
||||
|
||||
const resolve = (templateId, fallbackTitle) => {
|
||||
const pinned = templateId && HEVY_ID_MAP[templateId]
|
||||
if (pinned && EXIDX[pinned]) {
|
||||
matchedIds.add(pinned)
|
||||
return pinned
|
||||
}
|
||||
const key = templateId || String(fallbackTitle || '').toLowerCase()
|
||||
if (!key) return null
|
||||
let c = created.get(key)
|
||||
if (!c) {
|
||||
const t = templateId ? byId.get(templateId) : null
|
||||
const name = (t?.title || fallbackTitle || 'exercise').toLowerCase()
|
||||
c = {
|
||||
id: 'im' + uid(), n: name, custom: true, eq: 'custom', tg: '', desc: '',
|
||||
bp: bpOfTemplate(t) || (t?.type === 'distance_duration' || t?.type === 'duration' ? 'cardio' : null)
|
||||
|| 'upper legs',
|
||||
}
|
||||
created.set(key, c)
|
||||
unmatched.add(t?.title || fallbackTitle || name)
|
||||
}
|
||||
return c.id
|
||||
}
|
||||
|
||||
return {
|
||||
resolve,
|
||||
byId,
|
||||
customEx: () => [...created.values()],
|
||||
unmatchedNames: () => [...unmatched].sort(),
|
||||
matchedCount: () => matchedIds.size,
|
||||
createdCount: () => created.size,
|
||||
}
|
||||
}
|
||||
|
||||
const toProfileWeight = (wKg, unit) => {
|
||||
if (wKg == null || !isFinite(wKg)) return 0
|
||||
if (unit === 'lb') return Math.round(wKg / LB_TO_KG * 10) / 10
|
||||
return Math.round(wKg * 10) / 10
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn Hevy API workouts into the same shape `mergeImport` already understands.
|
||||
* Mapping is by `exercise_template_id` through `HEVY_ID_MAP` only — localized
|
||||
* titles on each set are never used to pick a catalogue entry.
|
||||
*/
|
||||
export function parseHevyWorkouts(workouts, templates, { unit = 'kg' } = {}) {
|
||||
const R = makeResolver(templates)
|
||||
const byDate = new Map()
|
||||
let sets = 0, skipped = 0, matched = 0, warmups = 0, rpeSets = 0
|
||||
|
||||
for (const w of workouts || []) {
|
||||
const start = localWhen(w.start_time)
|
||||
const end = localWhen(w.end_time)
|
||||
if (!start) { skipped++; continue }
|
||||
|
||||
let day = byDate.get(start.d)
|
||||
if (!day) {
|
||||
day = { ex: new Map(), name: w.title || '', start: start.t, end: end?.t ?? null }
|
||||
byDate.set(start.d, day)
|
||||
} else if (!day.name && w.title) day.name = w.title
|
||||
if (end?.t != null) day.end = end.t
|
||||
|
||||
for (const ex of w.exercises || []) {
|
||||
const id = R.resolve(ex.exercise_template_id, ex.title)
|
||||
if (!id) { skipped++; continue }
|
||||
if (EXIDX[id] && !String(id).startsWith('im')) matched++
|
||||
|
||||
if (!day.ex.has(id)) day.ex.set(id, [])
|
||||
const list = day.ex.get(id)
|
||||
|
||||
for (const s of ex.sets || []) {
|
||||
const warmup = /warm/i.test(String(s.type || ''))
|
||||
if (warmup) warmups++
|
||||
const reps = s.reps != null ? Math.round(s.reps) : 0
|
||||
const wgt = toProfileWeight(s.weight_kg, unit)
|
||||
const secs = s.duration_seconds != null ? Number(s.duration_seconds) : 0
|
||||
const km = s.distance_meters != null ? Number(s.distance_meters) / 1000 : 0
|
||||
if (!wgt && !reps && !secs && !km) { skipped++; continue }
|
||||
|
||||
const isCardio = (km > 0 || secs > 0) && !reps
|
||||
const mins = secs > 0 ? Math.round(secs / 60 * 10) / 10 : 0
|
||||
const set = isCardio
|
||||
? { min: mins, speed: mins > 0 ? Math.round(km / (mins / 60) * 10) / 10 : 0, done: true, ...(warmup ? { phase: 'warmup' } : {}) }
|
||||
: { w: wgt, r: reps || 0, done: true, ...(warmup ? { phase: 'warmup' } : {}) }
|
||||
|
||||
if (!isCardio && s.rpe != null && isFinite(Number(s.rpe)) && Number(s.rpe) > 0) {
|
||||
set.rpe = Math.min(10, Math.round(Number(s.rpe) * 100) / 100)
|
||||
rpeSets++
|
||||
}
|
||||
list.push(set)
|
||||
sets++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dates = [...byDate.keys()].sort()
|
||||
const outWorkouts = dates.map(d => {
|
||||
const day = byDate.get(d)
|
||||
const entries = [...day.ex.entries()].map(([id, ss]) => {
|
||||
const mx = Math.max(0, ...ss.filter(s => !isWarmupRow(s)).map(s => s.w || 0))
|
||||
return { id, sets: ss, topW: mx || null }
|
||||
})
|
||||
const base = new Date(d + 'T00:00:00').getTime()
|
||||
const startMs = base + (day.start ?? 18 * 3600000)
|
||||
const endMs = day.end != null ? base + day.end : startMs
|
||||
const workout = {
|
||||
id: 'iw' + uid(), d, start: startMs, end: endMs > startMs ? endMs : startMs,
|
||||
routineId: null, name: day.name || 'Imported', entries, prs: [],
|
||||
}
|
||||
workout.vol = entries.reduce((a, e) => a + e.sets.reduce((b, s) => b + (s.w || 0) * (s.r || 0), 0), 0)
|
||||
return workout
|
||||
})
|
||||
|
||||
return {
|
||||
kind: 'workouts',
|
||||
source: 'Hevy',
|
||||
workouts: outWorkouts,
|
||||
customEx: R.customEx(),
|
||||
matched: R.matchedCount(),
|
||||
matchedSets: matched,
|
||||
created: R.createdCount(),
|
||||
unmatchedNames: R.unmatchedNames(),
|
||||
sets, skipped, warmups,
|
||||
fileUnit: 'kg',
|
||||
mixedUnits: false,
|
||||
converted: unit === 'lb',
|
||||
rpeSets, rirSets: 0,
|
||||
from: dates[0] || null,
|
||||
to: dates[dates.length - 1] || null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hevy routine → openGym routine config.
|
||||
* Work sets become `sets`×`reps`/`weight`; warm-ups become `warmupSets`;
|
||||
* supersets keep adjacency via `sg`. Always imported as *new* routines.
|
||||
*/
|
||||
export function parseHevyRoutines(routines, templates, { unit = 'kg' } = {}) {
|
||||
const R = makeResolver(templates)
|
||||
const out = []
|
||||
|
||||
for (const r of routines || []) {
|
||||
const ex = []
|
||||
const sgMap = new Map() // Hevy superset_id → openGym sg token
|
||||
|
||||
for (const he of r.exercises || []) {
|
||||
const id = R.resolve(he.exercise_template_id, he.title)
|
||||
if (!id) continue
|
||||
|
||||
const allSets = he.sets || []
|
||||
const warm = allSets.filter(s => /warm/i.test(String(s.type || ''))).length
|
||||
const work = allSets.filter(s => !/warm/i.test(String(s.type || '')))
|
||||
if (!work.length && !warm) continue
|
||||
|
||||
const sample = work[0] || allSets[0]
|
||||
const reps = sample?.reps != null ? Math.round(sample.reps) : 0
|
||||
const secs = sample?.duration_seconds != null ? Number(sample.duration_seconds) : 0
|
||||
const km = sample?.distance_meters != null ? Number(sample.distance_meters) / 1000 : 0
|
||||
const wgt = toProfileWeight(sample?.weight_kg, unit)
|
||||
const nWork = Math.max(1, work.length)
|
||||
|
||||
let cfg
|
||||
if (km > 0 && !reps) {
|
||||
const mins = secs > 0 ? Math.round(secs / 60 * 10) / 10 : 20
|
||||
cfg = {
|
||||
id, sets: nWork, min: mins || 20,
|
||||
speed: mins > 0 ? Math.round(km / (mins / 60) * 10) / 10 : 0,
|
||||
}
|
||||
} else if (secs > 0 && !reps && !wgt) {
|
||||
cfg = { id, sets: nWork, sec: Math.round(secs), weight: 0, mode: 'time' }
|
||||
} else {
|
||||
cfg = { id, sets: nWork, reps: reps || 10, weight: wgt || 0, mode: 'reps' }
|
||||
}
|
||||
if (warm > 0) cfg.warmupSets = Math.min(5, warm)
|
||||
if (he.notes) cfg.note = String(he.notes).slice(0, 280)
|
||||
|
||||
if (he.superset_id != null && he.superset_id !== '') {
|
||||
const key = String(he.superset_id)
|
||||
if (!sgMap.has(key)) sgMap.set(key, 'hs' + uid())
|
||||
cfg.sg = sgMap.get(key)
|
||||
}
|
||||
ex.push(cfg)
|
||||
}
|
||||
|
||||
if (!ex.length) continue
|
||||
// Drop singleton supersets (partner missing after drops).
|
||||
ex.forEach((e, i) => {
|
||||
if (e.sg && !(ex[i - 1]?.sg === e.sg || ex[i + 1]?.sg === e.sg)) delete e.sg
|
||||
})
|
||||
|
||||
out.push({
|
||||
id: 'hr' + uid(),
|
||||
name: (r.title || 'Imported').trim() || 'Imported',
|
||||
emoji: 'figureStrength',
|
||||
hevyId: r.id || null,
|
||||
ex,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'routines',
|
||||
source: 'Hevy',
|
||||
routines: out,
|
||||
customEx: R.customEx(),
|
||||
matched: R.matchedCount(),
|
||||
created: R.createdCount(),
|
||||
unmatchedNames: R.unmatchedNames(),
|
||||
exerciseCount: out.reduce((n, r) => n + r.ex.length, 0),
|
||||
converted: unit === 'lb',
|
||||
}
|
||||
}
|
||||
|
||||
/** Merge Hevy routines into state — always added as new routines (fresh ids). */
|
||||
export function mergeHevyRoutines(S, parsed) {
|
||||
S.customEx = S.customEx || []
|
||||
S.routines = S.routines || []
|
||||
const exIdMap = {}
|
||||
;(parsed.customEx || []).forEach(c => {
|
||||
const same = S.customEx.find(x => (x.n || '').toLowerCase() === (c.n || '').toLowerCase() && x.bp === c.bp)
|
||||
if (same) { exIdMap[c.id] = same.id; return }
|
||||
// Keep the pre-assigned id from parse so routine configs already point at it.
|
||||
if (!S.customEx.some(x => x.id === c.id)) S.customEx.push(c)
|
||||
})
|
||||
let added = 0
|
||||
for (const r of parsed.routines || []) {
|
||||
S.routines.push({
|
||||
id: uid(),
|
||||
name: r.name,
|
||||
emoji: r.emoji || 'figureStrength',
|
||||
ex: (r.ex || []).map(e => ({ ...e, id: exIdMap[e.id] || e.id })),
|
||||
})
|
||||
added++
|
||||
}
|
||||
return { added }
|
||||
}
|
||||
|
||||
/** Body measurements from the Hevy API → `mergeImport` bodyweight shape. */
|
||||
export function parseHevyBodyweight(measurements, { unit = 'kg' } = {}) {
|
||||
const out = new Map()
|
||||
for (const m of measurements || []) {
|
||||
const d = String(m.date || '').slice(0, 10)
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(d)) continue
|
||||
let w = Number(m.weight_kg)
|
||||
if (!isFinite(w) || w <= 0) continue
|
||||
if (unit === 'lb') w = Math.round(w / LB_TO_KG * 10) / 10
|
||||
else w = Math.round(w * 10) / 10
|
||||
const t = m.created_at ? new Date(m.created_at).getTime() : new Date(d + 'T12:00:00').getTime()
|
||||
out.set(d, { d, w, t: isFinite(t) ? t : new Date(d + 'T12:00:00').getTime() })
|
||||
}
|
||||
const dates = [...out.keys()].sort()
|
||||
return {
|
||||
kind: 'bodyweight',
|
||||
source: 'Hevy',
|
||||
bodyweight: dates.map(d => out.get(d)),
|
||||
fileUnit: 'kg',
|
||||
converted: unit === 'lb',
|
||||
from: dates[0] || null,
|
||||
to: dates[dates.length - 1] || null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch + parse. Returns `{ workouts, routines, bodyweight }` ready to merge,
|
||||
* or throws `HevyApiError`. The apiKey is only read here — never written.
|
||||
*/
|
||||
export async function importHevyData(apiKey, { unit = 'kg', onProgress } = {}) {
|
||||
const { templates, workouts, routines, bodyMeasurements } = await fetchHevyAccount(apiKey, { onProgress })
|
||||
onProgress && onProgress({ stage: 'parse' })
|
||||
return {
|
||||
workouts: parseHevyWorkouts(workouts, templates, { unit }),
|
||||
routines: parseHevyRoutines(routines, templates, { unit }),
|
||||
bodyweight: parseHevyBodyweight(bodyMeasurements, { unit }),
|
||||
templateCount: templates.length,
|
||||
}
|
||||
}
|
||||
|
||||
export { HevyApiError }
|
||||
@@ -0,0 +1,291 @@
|
||||
import { describe, expect, it, vi, afterEach } from 'vitest'
|
||||
import {
|
||||
matchHevyTemplate, buildHevyExerciseMap, parseHevyWorkouts, parseHevyBodyweight,
|
||||
parseHevyRoutines, mergeHevyRoutines, localWhen, importHevyData, HevyApiError, HEVY_ID_MAP,
|
||||
} from './import-hevy.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { mergeImport } from './import-csv.js'
|
||||
|
||||
const TEMPLATES = [
|
||||
{
|
||||
id: '3303376C', title: 'Elliptical Trainer', type: 'distance_duration',
|
||||
primary_muscle_group: 'cardio', secondary_muscle_groups: [], equipment: 'machine', is_custom: false,
|
||||
},
|
||||
{
|
||||
id: '4E5257DE', title: 'Lat Pulldown - Close Grip (Cable)', type: 'weight_reps',
|
||||
primary_muscle_group: 'lats', secondary_muscle_groups: [], equipment: 'machine', is_custom: false,
|
||||
},
|
||||
{
|
||||
id: 'DEADBEEF', title: 'My Invented Landmine Twist', type: 'weight_reps',
|
||||
primary_muscle_group: 'abdominals', secondary_muscle_groups: [], equipment: 'other', is_custom: true,
|
||||
},
|
||||
{
|
||||
id: '99D5F10E', title: 'Ab Wheel', type: 'reps_only',
|
||||
primary_muscle_group: 'abdominals', secondary_muscle_groups: [], equipment: 'other', is_custom: false,
|
||||
},
|
||||
]
|
||||
|
||||
const WORKOUT = {
|
||||
id: 'w1',
|
||||
title: 'Oberkörper 2',
|
||||
start_time: '2026-08-25T10:10:24+00:00',
|
||||
end_time: '2026-08-25T11:10:08+00:00',
|
||||
exercises: [
|
||||
{
|
||||
index: 0,
|
||||
title: 'Crosstrainer', // localized — must NOT drive the match
|
||||
exercise_template_id: '3303376C',
|
||||
sets: [{
|
||||
index: 0, type: 'normal', weight_kg: null, reps: null,
|
||||
distance_meters: 480, duration_seconds: 180, rpe: null,
|
||||
}],
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
title: 'Latzug - Enger Griff (Kabel)',
|
||||
exercise_template_id: '4E5257DE',
|
||||
sets: [
|
||||
{ index: 0, type: 'warmup', weight_kg: 25, reps: 15, distance_meters: null, duration_seconds: null, rpe: null },
|
||||
{ index: 1, type: 'normal', weight_kg: 52, reps: 15, distance_meters: null, duration_seconds: null, rpe: 8 },
|
||||
{ index: 2, type: 'normal', weight_kg: 52, reps: 10, distance_meters: null, duration_seconds: null, rpe: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
index: 2,
|
||||
title: 'Meine Eigenkreation',
|
||||
exercise_template_id: 'DEADBEEF',
|
||||
sets: [
|
||||
{ index: 0, type: 'normal', weight_kg: 20, reps: 12, distance_meters: null, duration_seconds: null, rpe: null },
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe('HEVY_ID_MAP', () => {
|
||||
it('only points at real catalogue ids', () => {
|
||||
for (const id of Object.values(HEVY_ID_MAP)) {
|
||||
expect(EXIDX[id], `catalogue missing ${id}`).toBeTruthy()
|
||||
}
|
||||
})
|
||||
|
||||
// Real import leftovers: same lifts under Hevy's naming. Map lookup is the
|
||||
// only resolution path — titles are never guessed at runtime.
|
||||
const PINNED = {
|
||||
B5D3A742: '0410', // Bulgarian Split Squat (Dumbbell)
|
||||
'914F3A96': '0327', // Chest Supported Incline Row (Dumbbell)
|
||||
'98237BA2': '0826', // Knee Raise Parallel Bars
|
||||
'4E5257DE': '2616', // Lat Pulldown - Close Grip (Cable)
|
||||
C315DC2A: '0602', // Rear Delt Reverse Fly (Cable)
|
||||
FFDA283B: '0381', // Reverse Lunge (Dumbbell)
|
||||
'8BAB2735': '0318', // Seated Incline Curl (Dumbbell)
|
||||
'9237BAD1': '0603', // Seated Shoulder Press (Machine)
|
||||
B05C2C29: '0605', // Single Leg Standing Calf Raise (Machine)
|
||||
'3303376C': '2141', // Elliptical Trainer
|
||||
'99D5F10E': '0857', // Ab Wheel
|
||||
}
|
||||
for (const [hid, want] of Object.entries(PINNED)) {
|
||||
it(`maps ${hid} → ${want} (${EXIDX[want]?.n})`, () => {
|
||||
expect(HEVY_ID_MAP[hid]).toBe(want)
|
||||
expect(matchHevyTemplate({ id: hid, title: 'ignored localized name' })).toBe(want)
|
||||
})
|
||||
}
|
||||
|
||||
it('leaves catalogue gaps unmapped (import as custom)', () => {
|
||||
for (const id of ['68CE0B9B', '0222DB42', 'D1CD146F']) {
|
||||
expect(HEVY_ID_MAP[id]).toBeUndefined()
|
||||
expect(matchHevyTemplate({ id, title: 'whatever' })).toBeNull()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('matchHevyTemplate', () => {
|
||||
it('is map-only — title never overrides the id', () => {
|
||||
expect(matchHevyTemplate({ id: '3303376C', title: 'Totally Wrong Name' })).toBe('2141')
|
||||
expect(matchHevyTemplate({ id: 'DEADBEEF', title: 'Bench Press' })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseHevyWorkouts', () => {
|
||||
it('maps by template id, not the localized workout title', () => {
|
||||
const parsed = parseHevyWorkouts([WORKOUT], TEMPLATES, { unit: 'kg' })
|
||||
expect(parsed.error).toBeUndefined()
|
||||
expect(parsed.source).toBe('Hevy')
|
||||
expect(parsed.workouts).toHaveLength(1)
|
||||
|
||||
const entries = parsed.workouts[0].entries
|
||||
const elliptical = entries.find(e => e.id === '2141')
|
||||
expect(elliptical).toBeTruthy()
|
||||
expect(elliptical.sets[0]).toMatchObject({ min: 3, done: true })
|
||||
|
||||
const pulldown = entries.find(e => e.id === '2616')
|
||||
expect(pulldown).toBeTruthy()
|
||||
expect(pulldown.sets[0]).toMatchObject({ w: 25, r: 15, phase: 'warmup' })
|
||||
expect(pulldown.sets[1]).toMatchObject({ w: 52, r: 15, rpe: 8 })
|
||||
expect(pulldown.topW).toBe(52)
|
||||
expect(parsed.warmups).toBe(1)
|
||||
expect(parsed.rpeSets).toBe(1)
|
||||
|
||||
const custom = entries.find(e => String(e.id).startsWith('im'))
|
||||
expect(custom).toBeTruthy()
|
||||
expect(parsed.customEx.some(c => c.id === custom.id && c.n === 'my invented landmine twist')).toBe(true)
|
||||
expect(parsed.customEx.find(c => c.id === custom.id).bp).toBe('waist')
|
||||
expect(parsed.unmatchedNames).toContain('My Invented Landmine Twist')
|
||||
})
|
||||
|
||||
it('converts kg weights into a lb profile', () => {
|
||||
const parsed = parseHevyWorkouts([WORKOUT], TEMPLATES, { unit: 'lb' })
|
||||
const pulldown = parsed.workouts[0].entries.find(e => e.id === '2616')
|
||||
expect(pulldown.sets.find(s => s.r === 15 && !s.phase).w).toBeCloseTo(114.6, 0)
|
||||
expect(parsed.converted).toBe(true)
|
||||
})
|
||||
|
||||
it('merges two Hevy sessions on the same local day', () => {
|
||||
const a = { ...WORKOUT, id: 'a', title: 'AM', exercises: [WORKOUT.exercises[0]] }
|
||||
const b = {
|
||||
...WORKOUT, id: 'b', title: 'PM',
|
||||
start_time: '2026-08-25T18:00:00+00:00',
|
||||
end_time: '2026-08-25T19:00:00+00:00',
|
||||
exercises: [WORKOUT.exercises[1]],
|
||||
}
|
||||
const parsed = parseHevyWorkouts([a, b], TEMPLATES, { unit: 'kg' })
|
||||
expect(parsed.workouts).toHaveLength(1)
|
||||
expect(parsed.workouts[0].entries.length).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseHevyBodyweight', () => {
|
||||
it('reads weigh-ins in the profile unit', () => {
|
||||
const parsed = parseHevyBodyweight([
|
||||
{ id: 1, date: '2026-08-23', weight_kg: 83.2, created_at: '2026-08-23T18:22:48.070Z' },
|
||||
], { unit: 'kg' })
|
||||
expect(parsed.bodyweight).toEqual([{ d: '2026-08-23', w: 83.2, t: expect.any(Number) }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('mergeImport with Hevy payloads', () => {
|
||||
it('adds workouts and skips days that already exist', () => {
|
||||
const parsed = parseHevyWorkouts([WORKOUT], TEMPLATES, { unit: 'kg' })
|
||||
const S = { workouts: [], customEx: [], exWeights: {}, bodyweight: [] }
|
||||
const first = mergeImport(S, parsed)
|
||||
expect(first.added).toBe(1)
|
||||
expect(S.customEx.length).toBe(1)
|
||||
const second = mergeImport(S, parsed)
|
||||
expect(second.added).toBe(0)
|
||||
expect(S.workouts).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('localWhen', () => {
|
||||
it('parses an ISO timestamp into a local calendar day', () => {
|
||||
const w = localWhen('2026-08-25T10:10:24+00:00')
|
||||
expect(w.d).toMatch(/^\d{4}-\d{2}-\d{2}$/)
|
||||
expect(w.t).toBeGreaterThanOrEqual(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('importHevyData', () => {
|
||||
afterEach(() => { vi.unstubAllGlobals(); vi.restoreAllMocks() })
|
||||
|
||||
it('pages templates and workouts, never persists the key', async () => {
|
||||
const calls = []
|
||||
vi.stubGlobal('fetch', vi.fn(async (url, opts) => {
|
||||
calls.push({ url: String(url), key: opts.headers['api-key'] })
|
||||
const u = String(url)
|
||||
if (u.includes('/exercise_templates')) {
|
||||
return { ok: true, status: 200, json: async () => ({ page: 1, page_count: 1, exercise_templates: TEMPLATES }) }
|
||||
}
|
||||
if (u.includes('/workouts')) {
|
||||
return { ok: true, status: 200, json: async () => ({ page: 1, page_count: 1, workouts: [WORKOUT] }) }
|
||||
}
|
||||
if (u.includes('/routines')) {
|
||||
return { ok: true, status: 200, json: async () => ({ page: 1, page_count: 1, routines: [] }) }
|
||||
}
|
||||
if (u.includes('/body_measurements')) {
|
||||
return { ok: true, status: 200, json: async () => ({ page: 1, page_count: 1, body_measurements: [] }) }
|
||||
}
|
||||
return { ok: false, status: 404, json: async () => ({}) }
|
||||
}))
|
||||
|
||||
const result = await importHevyData('test-key-not-stored', { unit: 'kg' })
|
||||
expect(result.workouts.workouts).toHaveLength(1)
|
||||
expect(result.routines.routines).toHaveLength(0)
|
||||
expect(result.bodyweight.bodyweight).toHaveLength(0)
|
||||
expect(calls.every(c => c.key === 'test-key-not-stored')).toBe(true)
|
||||
})
|
||||
|
||||
it('surfaces a refused key as HevyApiError auth', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => ({ ok: false, status: 401, json: async () => ({}) })))
|
||||
await expect(importHevyData('bad')).rejects.toMatchObject({ name: 'HevyApiError', message: 'auth' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseHevyRoutines', () => {
|
||||
const ROUTINE = {
|
||||
id: 'r1',
|
||||
title: 'Oberkörper 2',
|
||||
exercises: [
|
||||
{
|
||||
title: 'Crosstrainer',
|
||||
exercise_template_id: '3303376C',
|
||||
superset_id: null,
|
||||
sets: [{ type: 'normal', weight_kg: null, reps: null, distance_meters: 480, duration_seconds: 180 }],
|
||||
},
|
||||
{
|
||||
title: 'Latzug',
|
||||
exercise_template_id: '4E5257DE',
|
||||
superset_id: 1,
|
||||
sets: [
|
||||
{ type: 'warmup', weight_kg: 25, reps: 15 },
|
||||
{ type: 'normal', weight_kg: 52, reps: 15 },
|
||||
{ type: 'normal', weight_kg: 52, reps: 12 },
|
||||
{ type: 'normal', weight_kg: 52, reps: 10 },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Row partner',
|
||||
exercise_template_id: '914F3A96', // chest supported incline row → 0327
|
||||
superset_id: 1,
|
||||
sets: [
|
||||
{ type: 'normal', weight_kg: 20, reps: 12 },
|
||||
{ type: 'normal', weight_kg: 20, reps: 12 },
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
it('builds openGym routine configs from Hevy sets', () => {
|
||||
const parsed = parseHevyRoutines([ROUTINE], TEMPLATES, { unit: 'kg' })
|
||||
expect(parsed.routines).toHaveLength(1)
|
||||
expect(parsed.routines[0].name).toBe('Oberkörper 2')
|
||||
expect(parsed.exerciseCount).toBe(3)
|
||||
|
||||
const [cardio, pull, row] = parsed.routines[0].ex
|
||||
expect(cardio.id).toBe('2141')
|
||||
expect(cardio).toMatchObject({ sets: 1, min: 3 })
|
||||
expect(pull.id).toBe('2616')
|
||||
expect(pull).toMatchObject({ sets: 3, reps: 15, weight: 52, warmupSets: 1 })
|
||||
expect(row.id).toBe('0327')
|
||||
expect(pull.sg).toBeTruthy()
|
||||
expect(pull.sg).toBe(row.sg)
|
||||
})
|
||||
|
||||
it('mergeHevyRoutines always adds new routines', () => {
|
||||
const parsed = parseHevyRoutines([ROUTINE], TEMPLATES, { unit: 'kg' })
|
||||
const S = { routines: [], customEx: [] }
|
||||
expect(mergeHevyRoutines(S, parsed).added).toBe(1)
|
||||
expect(S.routines).toHaveLength(1)
|
||||
expect(mergeHevyRoutines(S, parsed).added).toBe(1)
|
||||
expect(S.routines).toHaveLength(2)
|
||||
expect(S.routines[0].id).not.toBe(S.routines[1].id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildHevyExerciseMap', () => {
|
||||
it('indexes every template id from the static map', () => {
|
||||
const map = buildHevyExerciseMap(TEMPLATES)
|
||||
expect(map.get('3303376C')).toBe('2141')
|
||||
expect(map.get('4E5257DE')).toBe('2616')
|
||||
expect(map.get('DEADBEEF')).toBeNull()
|
||||
expect(map.size).toBe(TEMPLATES.length)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user