ApiDataSource maps the Go API onto the existing DataSource, so the screens are unchanged. Build with NEXT_PUBLIC_LMS_API=https://api.rezina.yaltopia.com to use it; without it the demo keeps its own data. Verified against the live API (public, no sign-in): - catalog and course outlines: courses, chapters, lessons, lesson notes, covers - FREE lessons (and every lesson of a FREE course) play for anyone; a free course offers "Start lesson 1" instead of a disabled buy button Built from the spec, not yet tested with a real account: - sign-in: phone code (login or register) and email + password, token refresh, sign-out - profile, progress summary (owned courses, completed lessons), lesson video URLs - video heartbeat, notifications (list, read/unread), issue reports, profile updates Not on the API yet, so left on hold: per-course prices and purchases (buying shows the "not connected" message), translations, categories, teacher, durations, prerequisites, chapter quizzes, Google/Apple sign-in. Screens now hide what a course doesn't have instead of showing it empty: category pill, teacher line and creator row, "0 min" durations, an empty card footer. Lessons with a Vimeo link play that video; the sample clip and "mark as watched" stay for lessons without one. Mapping checks (packages/data/src/api.check.ts) run in `pnpm test` against saved live responses.
74 lines
4.9 KiB
TypeScript
74 lines
4.9 KiB
TypeScript
// Runnable check for the API → domain mapping: `pnpm test`. The fixtures are real responses from
|
||
// https://api.rezina.yaltopia.com (2026-11-02): GET /catalog/courses and GET /catalog/courses/12.
|
||
import assert from 'node:assert/strict';
|
||
import { readFileSync } from 'node:fs';
|
||
import { absolute, ids, mapIssue, mapNotification, mapOutline, mapStudent, slugify, type RawOutline } from './api.ts';
|
||
|
||
const BASE = 'https://api.rezina.yaltopia.com';
|
||
const fixture = (f: string) => JSON.parse(readFileSync(new URL(f, import.meta.url), 'utf8')).data;
|
||
|
||
// ids and urls
|
||
assert.equal(ids.course(12), 'c12');
|
||
assert.equal(ids.num('ch19'), 19);
|
||
assert.equal(ids.num('l38'), 38);
|
||
assert.equal(slugify('Everyday English', 12), 'everyday-english-12');
|
||
assert.equal(slugify('የሜካፕ መሠረታዊ', 5), 'የሜካፕ-መሠረታዊ-5', 'Ge’ez titles keep their letters');
|
||
assert.equal(slugify('!!!', 7), '7');
|
||
assert.equal(absolute(BASE, '/static/demo/course-cover.svg'), `${BASE}/static/demo/course-cover.svg`);
|
||
assert.equal(absolute(BASE + '/', 'static/x.png'), `${BASE}/static/x.png`);
|
||
assert.equal(absolute(BASE, 'https://cdn.example/x.png'), 'https://cdn.example/x.png');
|
||
assert.equal(absolute(BASE, ''), null);
|
||
|
||
// catalog list has what the outline calls need
|
||
const catalog = fixture('./fixtures-catalog.json');
|
||
assert.ok(catalog.courses.length > 0);
|
||
for (const c of catalog.courses) assert.ok(Number.isInteger(c.id) && typeof c.name === 'string');
|
||
|
||
// outline → Course
|
||
const outline: RawOutline = fixture('./fixtures-outline-12.json');
|
||
const c = mapOutline(outline, BASE);
|
||
assert.equal(c.id, 'c12');
|
||
assert.equal(c.slug, 'everyday-english-12');
|
||
assert.equal(c.translations.en?.title, 'Everyday English');
|
||
assert.equal(c.status, 'PUBLISHED');
|
||
assert.equal(c.coverAssetId, `${BASE}/static/demo/course-cover.svg`);
|
||
assert.deepEqual(c.prices, {}, 'no per-course price on the API');
|
||
assert.equal(c.chapters.length, outline.chapters.length);
|
||
assert.equal(c.chapters[0].id, 'ch19');
|
||
assert.equal(c.chapters[0].translations.en?.title, 'Meet and greet');
|
||
assert.equal(c.chapters.flatMap((ch) => ch.lessons).length, outline.lesson_count, 'every lesson in the outline is mapped');
|
||
assert.deepEqual(c.chapters[0].lessons.map((l) => l.sortOrder), [1, 2, 3]);
|
||
assert.ok(c.chapters[0].lessons.every((l) => l.isPreview), 'a FREE course plays for anyone');
|
||
const premium = mapOutline({ ...outline, access_tier: 'PREMIUM', chapters: [{ ...outline.chapters[0], lessons: outline.chapters[0].lessons.map((l, i) => ({ ...l, access_tier: i ? 'PREMIUM' : 'FREE' })) }] }, BASE);
|
||
assert.deepEqual(premium.chapters[0].lessons.map((l) => l.isPreview), [true, false, false], 'in a PREMIUM course only FREE lessons preview');
|
||
|
||
// issues and notifications
|
||
const issue = mapIssue({ id: 4, issue_type: 'video', subject: 'Stops', description: 'd', status: 'in_progress', created_at: 'a', updated_at: 'b' });
|
||
assert.deepEqual([issue.id, issue.type, issue.status], ['4', 'VIDEO', 'IN_PROGRESS']);
|
||
assert.equal(mapIssue({ id: 5, issue_type: 'weird', subject: '', description: '', status: '???', created_at: '', updated_at: '' }).type, 'OTHER');
|
||
const n = mapNotification({ id: 'n1', is_read: true, timestamp: 't', type: 'payment_verified', payload: { headline: 'Paid', message: 'Thanks' }, metadata: { link: '/en/my' } });
|
||
assert.deepEqual([n.type, n.title, n.body, n.readAt, n.link], ['PAYMENT_VERIFIED', 'Paid', 'Thanks', 't', '/en/my']);
|
||
assert.equal(mapNotification({ id: 'n2', is_read: false, timestamp: 't', type: 'x' }).readAt, null);
|
||
|
||
// profile + progress summary → Student
|
||
const now = '2026-11-02T00:00:00.000Z';
|
||
const access = (x: Partial<{ is_accessible: boolean; is_completed: boolean }>) => ({ is_accessible: false, is_completed: false, progress_percent: 0, ...x });
|
||
const s = mapStudent(
|
||
{ id: 9, first_name: 'Meron', last_name: 'T', phone_number: '+251911000000', preferred_language: 'am', status: 'SUSPENDED', region: 'Adama', country: 'ET' },
|
||
{ courses: [
|
||
{ id: 12, access: access({ is_accessible: true }), chapters: [{ id: 19, lessons: [{ id: 38, access: access({ is_completed: true }) }, { id: 39, access: access({}) }] }] },
|
||
{ id: 13, access: access({ is_accessible: false }), chapters: [] },
|
||
] },
|
||
[{ id: 1, issue_type: 'payment', subject: 's', description: 'd', status: 'open', created_at: 'a', updated_at: 'b' }],
|
||
{ l39: { courseId: 'c12', positionSec: 40, maxPositionSec: 60, updatedAt: now } },
|
||
now,
|
||
);
|
||
assert.deepEqual([s.id, s.name, s.locale, s.status, s.city], ['9', 'Meron T', 'am', 'DEACTIVATED', 'Adama']);
|
||
assert.deepEqual(Object.keys(s.enrollments), ['c12'], 'accessible courses count as owned');
|
||
assert.equal(s.progress.l38?.completedAt, now, 'server completion becomes a completed lesson');
|
||
assert.equal(s.progress.l39?.positionSec, 40, 'this session’s resume point survives a refresh');
|
||
assert.equal(s.issues['1']?.type, 'PAYMENT');
|
||
assert.equal(mapStudent({ id: 1, preferred_language: 'fr' }, null, [], {}, now).locale, 'en', 'unknown language falls back to English');
|
||
|
||
console.log('api checks: all passed');
|