my-kaiqiuwang/__test__/fav-dao.test.ts
kyuuseiryuu 80aebac57a feat: implement user favorite player system with Logto sync
- Add `FavPlayerDAO` for database operations (create, read, delete, check) against `user_fav` table.
- Integrate Prisma ORM with MariaDB adapter in `src/prisma/db.ts`.
- Implement backend API routes (`/api/fav`) to handle GET, PUT, and DELETE requests for managing favorites based on user audience (aud).
- Create `FavePlayersPage` with support for:
  - Viewing local stored favorites.
  - Syncing server-side favorites via Logto authentication.
  - Visual distinction between "Local" and "Account" favorite lists using Segmented control.
  - Loading states and empty state handling with Ant Design components.
- Enhance `Logto/Callback` to redirect users back to their intended destination (e.g., `FavePlayersPage`) after authentication if a `redirect` param was stored in session storage.
- Update `UserCenter` page to include "Backup Codes" management option under account settings.
- Add necessary dependencies: `@logto/react`, `ahooks`, and update UI imports accordingly.
2026-03-09 10:16:27 +09:00

19 lines
722 B
TypeScript

import { test, expect } from 'bun:test';
import { getUserFavList, updateUserFav, isUserFav, deleteUserFav } from '../src/dao/FavPlayerDAO';
test('Test fav', async () => {
await updateUserFav('aud1', 'uid1');
await updateUserFav('aud1', 'uid2');
expect((await getUserFavList('aud1')).length).toBe(2);
expect(await isUserFav('aud1', 'uid1')).toBeTrue();
expect(await isUserFav('aud1', 'uid2')).toBeTrue();
await deleteUserFav('aud1', 'uid1');
await deleteUserFav('aud1', 'uid2');
});
test("Test unFave", async () => {
await updateUserFav('aud1', 'uid3');
expect(await isUserFav('aud1', 'uid3')).toBeTrue();
await deleteUserFav('aud1', 'uid3');
expect(await isUserFav('aud1', 'uid3')).toBeFalse();
});