feat: migrate to Next.js for Mini App and enhance project structure

- Replaced the previous webapp with a new Mini App built using Next.js, improving performance and maintainability.
- Updated the `.gitignore` to exclude Next.js build artifacts and node modules.
- Revised documentation in `AGENTS.md`, `README.md`, and `architecture.md` to reflect the new Mini App structure and technology stack.
- Enhanced Dockerfile to support the new build process for the Next.js application.
- Updated CI workflow to build and test the Next.js application.
- Added new configuration options for the Mini App, including `MINI_APP_SHORT_NAME` for improved deep linking.
- Refactored frontend testing setup to accommodate the new structure and testing framework.
- Removed legacy webapp files and dependencies to streamline the project.
This commit is contained in:
2026-03-03 16:04:08 +03:00
parent 2de5c1cb81
commit 16bf1a1043
148 changed files with 20240 additions and 7270 deletions

View File

@@ -0,0 +1,87 @@
/**
* Unit tests for current-duty: getRemainingTime, findCurrentDuty.
* Ported from webapp/js/currentDuty.test.js.
*/
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { getRemainingTime, findCurrentDuty } from "./current-duty";
import type { DutyWithUser } from "@/types";
describe("getRemainingTime", () => {
it("returns hours and minutes until end from now", () => {
const endAt = "2025-03-02T17:30:00.000Z";
vi.useFakeTimers();
vi.setSystemTime(new Date("2025-03-02T12:00:00.000Z"));
const { hours, minutes } = getRemainingTime(endAt);
vi.useRealTimers();
expect(hours).toBe(5);
expect(minutes).toBe(30);
});
it("returns 0 when end is in the past", () => {
const endAt = "2025-03-02T09:00:00.000Z";
vi.useFakeTimers();
vi.setSystemTime(new Date("2025-03-02T12:00:00.000Z"));
const { hours, minutes } = getRemainingTime(endAt);
vi.useRealTimers();
expect(hours).toBe(0);
expect(minutes).toBe(0);
});
it("returns 0 hours and 0 minutes when endAt is invalid", () => {
const { hours, minutes } = getRemainingTime("not-a-date");
expect(hours).toBe(0);
expect(minutes).toBe(0);
});
});
describe("findCurrentDuty", () => {
it("returns duty when now is between start_at and end_at", () => {
const now = new Date();
const start = new Date(now);
start.setHours(start.getHours() - 1, 0, 0, 0);
const end = new Date(now);
end.setHours(end.getHours() + 1, 0, 0, 0);
const duties: DutyWithUser[] = [
{
id: 1,
user_id: 1,
event_type: "duty",
full_name: "Иванов",
start_at: start.toISOString(),
end_at: end.toISOString(),
phone: null,
username: null,
},
];
const duty = findCurrentDuty(duties);
expect(duty).not.toBeNull();
expect(duty?.full_name).toBe("Иванов");
});
it("returns null when no duty overlaps current time", () => {
const duties: DutyWithUser[] = [
{
id: 1,
user_id: 1,
event_type: "duty",
full_name: "Past",
start_at: "2020-01-01T09:00:00Z",
end_at: "2020-01-01T17:00:00Z",
phone: null,
username: null,
},
{
id: 2,
user_id: 2,
event_type: "duty",
full_name: "Future",
start_at: "2030-01-01T09:00:00Z",
end_at: "2030-01-01T17:00:00Z",
phone: null,
username: null,
},
];
expect(findCurrentDuty(duties)).toBeNull();
});
});