浏览代码

✨ feat(auth): 优化小程序登录接口响应格式

- 移除用户信息中的avatar字段
- 添加registrationSource字段到用户信息响应
- 显式指定JSON响应状态码为200

♻️ refactor(auth): 优化MiniAuthService依赖注入

- 移除构造函数参数的private修饰符,遵循依赖注入最佳实践

🔧 chore(test): 完善测试用例

- 文件管理测试中使用随机字符串生成文件名,替代faker库
- 用户测试数据中添加registrationSource字段默认值
yourname 1 月之前
父节点
当前提交
f6bc3488b0

+ 12 - 4
src/server/api/auth/mini-login/post.ts

@@ -25,10 +25,10 @@ const MiniLoginResponseSchema = z.object({
     id: z.number(),
     username: z.string(),
     nickname: z.string().nullable(),
-    avatar: z.string().nullable(),
     phone: z.string().nullable(),
     email: z.string().nullable(),
-    avatarFileId: z.number().nullable()
+    avatarFileId: z.number().nullable(),
+    registrationSource: z.string()
   }),
   isNewUser: z.boolean().openapi({
     example: true,
@@ -104,9 +104,17 @@ const app = new OpenAPIHono().openapi(miniLoginRoute, async (c) => {
     
     return c.json({
       token: result.token,
-      user: result.user,
+      user: {
+        id: result.user.id,
+        username: result.user.username,
+        nickname: result.user.nickname,
+        phone: result.user.phone,
+        email: result.user.email,
+        avatarFileId: result.user.avatarFileId,
+        registrationSource: result.user.registrationSource
+      },
       isNewUser: result.isNewUser
-    });
+    }, 200);
   } catch (error) {
     const { code = 500, message = '登录失败' } = error as Error & { code?: number };
     return c.json({ code, message }, 500);

+ 1 - 1
src/server/modules/auth/mini-auth.service.ts

@@ -9,7 +9,7 @@ export class MiniAuthService {
   private userRepository: Repository<UserEntity>;
   private fileService: FileService;
   
-  constructor(private dataSource: DataSource) {
+  constructor(dataSource: DataSource) {
     this.userRepository = dataSource.getRepository(UserEntity);
     this.fileService = new FileService(dataSource);
   }

+ 2 - 2
tests/e2e/specs/admin/files.spec.ts

@@ -1,5 +1,4 @@
 import { test, expect } from '@playwright/test';
-import { faker } from '@faker-js/faker';
 
 test.describe('Admin File Management', () => {
   test.beforeEach(async ({ page }) => {
@@ -42,7 +41,8 @@ test.describe('Admin File Management', () => {
     await page.waitForSelector('[data-testid="upload-modal"]');
 
     // Create a test file
-    const testFileName = `test-${faker.string.alphanumeric(8)}.txt`;
+    const randomString = Math.random().toString(36).substring(2, 10);
+    const testFileName = `test-${randomString}.txt`;
     const testFileContent = 'This is a test file content';
 
     // Upload file

+ 1 - 0
tests/integration/server/files/files.integration.test.ts

@@ -24,6 +24,7 @@ describe('File API Integration Tests', () => {
     avatarFile: null,
     isDisabled: 0,
     isDeleted: 0,
+    registrationSource: 'web',
     roles: [],
     createdAt: new Date(),
     updatedAt: new Date()