@studious-lms/server 1.1.24 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.coderabbit.yaml +9 -0
- package/.env.example +53 -0
- package/.env.test.example +37 -0
- package/README.md +34 -7
- package/dist/exportType.d.ts.map +1 -1
- package/dist/exportType.js +4 -0
- package/dist/exportType.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -51
- package/dist/index.js.map +1 -0
- package/dist/instrument.d.ts +2 -0
- package/dist/instrument.d.ts.map +1 -0
- package/dist/instrument.js +18 -0
- package/dist/instrument.js.map +1 -0
- package/dist/lib/config/env.d.ts +190 -0
- package/dist/lib/config/env.d.ts.map +1 -0
- package/dist/lib/config/env.js +121 -0
- package/dist/lib/config/env.js.map +1 -0
- package/dist/lib/fileUpload.d.ts +2 -2
- package/dist/lib/fileUpload.d.ts.map +1 -1
- package/dist/lib/fileUpload.js +82 -15
- package/dist/lib/fileUpload.js.map +1 -0
- package/dist/lib/googleCloudStorage.d.ts +13 -0
- package/dist/lib/googleCloudStorage.d.ts.map +1 -1
- package/dist/lib/googleCloudStorage.js +45 -6
- package/dist/lib/googleCloudStorage.js.map +1 -0
- package/dist/lib/jsonConversion.d.ts.map +1 -1
- package/dist/lib/jsonConversion.js +16 -14
- package/dist/lib/jsonConversion.js.map +1 -0
- package/dist/lib/jsonStyles.d.ts.map +1 -1
- package/dist/lib/jsonStyles.js +4 -0
- package/dist/lib/jsonStyles.js.map +1 -0
- package/dist/lib/notificationHandler.d.ts +25 -0
- package/dist/lib/notificationHandler.d.ts.map +1 -0
- package/dist/lib/notificationHandler.js +32 -0
- package/dist/lib/notificationHandler.js.map +1 -0
- package/dist/lib/prisma.d.ts +2 -2
- package/dist/lib/prisma.d.ts.map +1 -1
- package/dist/lib/prisma.js +24 -1
- package/dist/lib/prisma.js.map +1 -0
- package/dist/lib/pusher.d.ts +4 -1
- package/dist/lib/pusher.d.ts.map +1 -1
- package/dist/lib/pusher.js +14 -6
- package/dist/lib/pusher.js.map +1 -0
- package/dist/lib/redis.d.ts +5 -0
- package/dist/lib/redis.d.ts.map +1 -0
- package/dist/lib/redis.js +53 -0
- package/dist/lib/redis.js.map +1 -0
- package/dist/lib/thumbnailGenerator.d.ts +0 -21
- package/dist/lib/thumbnailGenerator.d.ts.map +1 -1
- package/dist/lib/thumbnailGenerator.js +159 -158
- package/dist/lib/thumbnailGenerator.js.map +1 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +41 -93
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/logging.d.ts.map +1 -1
- package/dist/middleware/logging.js +4 -0
- package/dist/middleware/logging.js.map +1 -0
- package/dist/middleware/security.d.ts +5 -0
- package/dist/middleware/security.d.ts.map +1 -0
- package/dist/middleware/security.js +77 -0
- package/dist/middleware/security.js.map +1 -0
- package/dist/models/agenda.d.ts +97 -0
- package/dist/models/agenda.d.ts.map +1 -0
- package/dist/models/agenda.js +40 -0
- package/dist/models/agenda.js.map +1 -0
- package/dist/models/announcement.d.ts +223 -0
- package/dist/models/announcement.d.ts.map +1 -0
- package/dist/models/announcement.js +120 -0
- package/dist/models/announcement.js.map +1 -0
- package/dist/models/assignment.d.ts +1292 -0
- package/dist/models/assignment.d.ts.map +1 -0
- package/dist/models/assignment.js +309 -0
- package/dist/models/assignment.js.map +1 -0
- package/dist/models/attendance.d.ts +180 -0
- package/dist/models/attendance.d.ts.map +1 -0
- package/dist/models/attendance.js +188 -0
- package/dist/models/attendance.js.map +1 -0
- package/dist/models/auth.d.ts +153 -0
- package/dist/models/auth.d.ts.map +1 -0
- package/dist/models/auth.js +217 -0
- package/dist/models/auth.js.map +1 -0
- package/dist/models/class.d.ts +439 -0
- package/dist/models/class.d.ts.map +1 -0
- package/dist/models/class.js +546 -0
- package/dist/models/class.js.map +1 -0
- package/dist/models/comment.d.ts +171 -0
- package/dist/models/comment.d.ts.map +1 -0
- package/dist/models/comment.js +138 -0
- package/dist/models/comment.js.map +1 -0
- package/dist/models/conversation.d.ts +164 -0
- package/dist/models/conversation.d.ts.map +1 -0
- package/dist/models/conversation.js +175 -0
- package/dist/models/conversation.js.map +1 -0
- package/dist/models/event.d.ts +295 -0
- package/dist/models/event.d.ts.map +1 -0
- package/dist/models/event.js +145 -0
- package/dist/models/event.js.map +1 -0
- package/dist/models/file.d.ts +536 -0
- package/dist/models/file.d.ts.map +1 -0
- package/dist/models/file.js +126 -0
- package/dist/models/file.js.map +1 -0
- package/dist/models/folder.d.ts +295 -0
- package/dist/models/folder.d.ts.map +1 -0
- package/dist/models/folder.js +202 -0
- package/dist/models/folder.js.map +1 -0
- package/dist/models/labChat.d.ts +243 -0
- package/dist/models/labChat.d.ts.map +1 -0
- package/dist/models/labChat.js +204 -0
- package/dist/models/labChat.js.map +1 -0
- package/dist/models/marketing.d.ts +72 -0
- package/dist/models/marketing.d.ts.map +1 -0
- package/dist/models/marketing.js +26 -0
- package/dist/models/marketing.js.map +1 -0
- package/dist/models/message.d.ts +100 -0
- package/dist/models/message.d.ts.map +1 -0
- package/dist/models/message.js +131 -0
- package/dist/models/message.js.map +1 -0
- package/dist/models/newtonChat.d.ts +72 -0
- package/dist/models/newtonChat.d.ts.map +1 -0
- package/dist/models/newtonChat.js +61 -0
- package/dist/models/newtonChat.js.map +1 -0
- package/dist/models/notification.d.ts +65 -0
- package/dist/models/notification.d.ts.map +1 -0
- package/dist/models/notification.js +46 -0
- package/dist/models/notification.js.map +1 -0
- package/dist/models/section.d.ts +102 -0
- package/dist/models/section.d.ts.map +1 -0
- package/dist/models/section.js +83 -0
- package/dist/models/section.js.map +1 -0
- package/dist/models/user.d.ts +39 -0
- package/dist/models/user.d.ts.map +1 -0
- package/dist/models/user.js +38 -0
- package/dist/models/user.js.map +1 -0
- package/dist/models/worksheet.d.ts +460 -0
- package/dist/models/worksheet.d.ts.map +1 -0
- package/dist/models/worksheet.js +200 -0
- package/dist/models/worksheet.js.map +1 -0
- package/dist/pipelines/aiLabChat.d.ts +21 -0
- package/dist/pipelines/aiLabChat.d.ts.map +1 -0
- package/dist/pipelines/aiLabChat.js +460 -0
- package/dist/pipelines/aiLabChat.js.map +1 -0
- package/dist/pipelines/aiNewtonChat.d.ts +30 -0
- package/dist/pipelines/aiNewtonChat.d.ts.map +1 -0
- package/dist/pipelines/aiNewtonChat.js +289 -0
- package/dist/pipelines/aiNewtonChat.js.map +1 -0
- package/dist/pipelines/gradeWorksheet.d.ts +30 -0
- package/dist/pipelines/gradeWorksheet.d.ts.map +1 -0
- package/dist/pipelines/gradeWorksheet.js +252 -0
- package/dist/pipelines/gradeWorksheet.js.map +1 -0
- package/dist/routers/_app.d.ts +6403 -3741
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/_app.js +10 -0
- package/dist/routers/_app.js.map +1 -0
- package/dist/routers/agenda.d.ts +58 -6
- package/dist/routers/agenda.d.ts.map +1 -1
- package/dist/routers/agenda.js +6 -58
- package/dist/routers/agenda.js.map +1 -0
- package/dist/routers/announcement.d.ts +325 -6
- package/dist/routers/announcement.d.ts.map +1 -1
- package/dist/routers/announcement.js +547 -57
- package/dist/routers/announcement.js.map +1 -0
- package/dist/routers/assignment.d.ts +431 -318
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +104 -1559
- package/dist/routers/assignment.js.map +1 -0
- package/dist/routers/attendance.d.ts +20 -9
- package/dist/routers/attendance.d.ts.map +1 -1
- package/dist/routers/attendance.js +10 -263
- package/dist/routers/attendance.js.map +1 -0
- package/dist/routers/auth.d.ts +21 -1
- package/dist/routers/auth.d.ts.map +1 -1
- package/dist/routers/auth.js +37 -241
- package/dist/routers/auth.js.map +1 -0
- package/dist/routers/class.d.ts +198 -68
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +88 -909
- package/dist/routers/class.js.map +1 -0
- package/dist/routers/comment.d.ts +153 -0
- package/dist/routers/comment.d.ts.map +1 -0
- package/dist/routers/comment.js +58 -0
- package/dist/routers/comment.js.map +1 -0
- package/dist/routers/conversation.d.ts +73 -3
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/conversation.js +23 -265
- package/dist/routers/conversation.js.map +1 -0
- package/dist/routers/event.d.ts +46 -37
- package/dist/routers/event.d.ts.map +1 -1
- package/dist/routers/event.js +15 -431
- package/dist/routers/event.js.map +1 -0
- package/dist/routers/file.d.ts +4 -2
- package/dist/routers/file.d.ts.map +1 -1
- package/dist/routers/file.js +11 -295
- package/dist/routers/file.js.map +1 -0
- package/dist/routers/folder.d.ts +21 -14
- package/dist/routers/folder.d.ts.map +1 -1
- package/dist/routers/folder.js +36 -743
- package/dist/routers/folder.js.map +1 -0
- package/dist/routers/labChat.d.ts +12 -9
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/labChat.js +21 -877
- package/dist/routers/labChat.js.map +1 -0
- package/dist/routers/marketing.d.ts +2 -2
- package/dist/routers/marketing.d.ts.map +1 -1
- package/dist/routers/marketing.js +9 -54
- package/dist/routers/marketing.js.map +1 -0
- package/dist/routers/message.d.ts +2 -1
- package/dist/routers/message.d.ts.map +1 -1
- package/dist/routers/message.js +29 -519
- package/dist/routers/message.js.map +1 -0
- package/dist/routers/newtonChat.d.ts +55 -0
- package/dist/routers/newtonChat.d.ts.map +1 -0
- package/dist/routers/newtonChat.js +22 -0
- package/dist/routers/newtonChat.js.map +1 -0
- package/dist/routers/notifications.d.ts +8 -8
- package/dist/routers/notifications.d.ts.map +1 -1
- package/dist/routers/notifications.js +20 -81
- package/dist/routers/notifications.js.map +1 -0
- package/dist/routers/section.d.ts +37 -6
- package/dist/routers/section.d.ts.map +1 -1
- package/dist/routers/section.js +26 -167
- package/dist/routers/section.js.map +1 -0
- package/dist/routers/user.d.ts +1 -1
- package/dist/routers/user.d.ts.map +1 -1
- package/dist/routers/user.js +34 -204
- package/dist/routers/user.js.map +1 -0
- package/dist/routers/worksheet.d.ts +362 -0
- package/dist/routers/worksheet.d.ts.map +1 -0
- package/dist/routers/worksheet.js +153 -0
- package/dist/routers/worksheet.js.map +1 -0
- package/dist/seedDatabase.d.ts +2 -3
- package/dist/seedDatabase.d.ts.map +1 -1
- package/dist/seedDatabase.js +311 -289
- package/dist/seedDatabase.js.map +1 -0
- package/dist/server/pipelines/aiLabChat.d.ts +21 -0
- package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiLabChat.js +456 -0
- package/dist/server/pipelines/aiLabChat.js.map +1 -0
- package/dist/server/pipelines/aiNewtonChat.d.ts +30 -0
- package/dist/server/pipelines/aiNewtonChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiNewtonChat.js +285 -0
- package/dist/server/pipelines/aiNewtonChat.js.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts +30 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.js +248 -0
- package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
- package/dist/services/agenda.d.ts +100 -0
- package/dist/services/agenda.d.ts.map +1 -0
- package/dist/services/agenda.js +21 -0
- package/dist/services/agenda.js.map +1 -0
- package/dist/services/announcement.d.ts +135 -0
- package/dist/services/announcement.d.ts.map +1 -0
- package/dist/services/announcement.js +223 -0
- package/dist/services/announcement.js.map +1 -0
- package/dist/services/assignment.d.ts +1462 -0
- package/dist/services/assignment.d.ts.map +1 -0
- package/dist/services/assignment.js +898 -0
- package/dist/services/assignment.js.map +1 -0
- package/dist/services/attendance.d.ts +93 -0
- package/dist/services/attendance.d.ts.map +1 -0
- package/dist/services/attendance.js +61 -0
- package/dist/services/attendance.js.map +1 -0
- package/dist/services/auth.d.ts +68 -0
- package/dist/services/auth.d.ts.map +1 -0
- package/dist/services/auth.js +218 -0
- package/dist/services/auth.js.map +1 -0
- package/dist/services/class.d.ts +621 -0
- package/dist/services/class.d.ts.map +1 -0
- package/dist/services/class.js +474 -0
- package/dist/services/class.js.map +1 -0
- package/dist/services/comment.d.ts +100 -0
- package/dist/services/comment.d.ts.map +1 -0
- package/dist/services/comment.js +83 -0
- package/dist/services/comment.js.map +1 -0
- package/dist/services/conversation.d.ts +159 -0
- package/dist/services/conversation.d.ts.map +1 -0
- package/dist/services/conversation.js +138 -0
- package/dist/services/conversation.js.map +1 -0
- package/dist/services/event.d.ts +216 -0
- package/dist/services/event.d.ts.map +1 -0
- package/dist/services/event.js +168 -0
- package/dist/services/event.js.map +1 -0
- package/dist/services/file.d.ts +74 -0
- package/dist/services/file.d.ts.map +1 -0
- package/dist/services/file.js +133 -0
- package/dist/services/file.js.map +1 -0
- package/dist/services/folder.d.ts +239 -0
- package/dist/services/folder.d.ts.map +1 -0
- package/dist/services/folder.js +248 -0
- package/dist/services/folder.js.map +1 -0
- package/dist/services/labChat.d.ts +165 -0
- package/dist/services/labChat.d.ts.map +1 -0
- package/dist/services/labChat.js +289 -0
- package/dist/services/labChat.js.map +1 -0
- package/dist/services/marketing.d.ts +50 -0
- package/dist/services/marketing.d.ts.map +1 -0
- package/dist/services/marketing.js +32 -0
- package/dist/services/marketing.js.map +1 -0
- package/dist/services/message.d.ts +95 -0
- package/dist/services/message.d.ts.map +1 -0
- package/dist/services/message.js +350 -0
- package/dist/services/message.js.map +1 -0
- package/dist/services/newtonChat.d.ts +22 -0
- package/dist/services/newtonChat.d.ts.map +1 -0
- package/dist/services/newtonChat.js +174 -0
- package/dist/services/newtonChat.js.map +1 -0
- package/dist/services/notification.d.ts +65 -0
- package/dist/services/notification.d.ts.map +1 -0
- package/dist/services/notification.js +33 -0
- package/dist/services/notification.js.map +1 -0
- package/dist/services/section.d.ts +53 -0
- package/dist/services/section.d.ts.map +1 -0
- package/dist/services/section.js +199 -0
- package/dist/services/section.js.map +1 -0
- package/dist/services/user.d.ts +48 -0
- package/dist/services/user.d.ts.map +1 -0
- package/dist/services/user.js +141 -0
- package/dist/services/user.js.map +1 -0
- package/dist/services/worksheet.d.ts +239 -0
- package/dist/services/worksheet.d.ts.map +1 -0
- package/dist/services/worksheet.js +235 -0
- package/dist/services/worksheet.js.map +1 -0
- package/dist/socket/handlers.d.ts.map +1 -1
- package/dist/socket/handlers.js +4 -0
- package/dist/socket/handlers.js.map +1 -0
- package/dist/trpc.d.ts.map +1 -1
- package/dist/trpc.js +4 -0
- package/dist/trpc.js.map +1 -0
- package/dist/types/trpc.d.ts.map +1 -1
- package/dist/types/trpc.js +4 -0
- package/dist/types/trpc.js.map +1 -0
- package/dist/utils/aiUser.d.ts +1 -3
- package/dist/utils/aiUser.d.ts.map +1 -1
- package/dist/utils/aiUser.js +8 -3
- package/dist/utils/aiUser.js.map +1 -0
- package/dist/utils/email.d.ts +12 -1
- package/dist/utils/email.d.ts.map +1 -1
- package/dist/utils/email.js +26 -4
- package/dist/utils/email.js.map +1 -0
- package/dist/utils/generateInviteCode.d.ts +1 -2
- package/dist/utils/generateInviteCode.d.ts.map +1 -1
- package/dist/utils/generateInviteCode.js +5 -2
- package/dist/utils/generateInviteCode.js.map +1 -0
- package/dist/utils/inference.d.ts +8 -0
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +78 -10
- package/dist/utils/inference.js.map +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +35 -3
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/prismaErrorHandler.d.ts.map +1 -1
- package/dist/utils/prismaErrorHandler.js +7 -0
- package/dist/utils/prismaErrorHandler.js.map +1 -0
- package/dist/utils/prismaWrapper.d.ts +1 -0
- package/dist/utils/prismaWrapper.d.ts.map +1 -1
- package/dist/utils/prismaWrapper.js +8 -0
- package/dist/utils/prismaWrapper.js.map +1 -0
- package/docker-compose.yml +19 -0
- package/package.json +21 -4
- package/prisma/migrations/20251109122857_annuoncements_comments/migration.sql +30 -0
- package/prisma/migrations/20251109135555_reactions_announcements_comments/migration.sql +35 -0
- package/prisma/schema.prisma +180 -12
- package/scripts/test-pre-push.ts +14 -0
- package/src/index.ts +247 -52
- package/src/instrument.ts +15 -0
- package/src/lib/config/env.ts +132 -0
- package/src/lib/fileUpload.ts +81 -16
- package/src/lib/googleCloudStorage.ts +42 -6
- package/src/lib/jsonConversion.ts +12 -14
- package/src/lib/prisma.ts +23 -2
- package/src/lib/pusher.ts +11 -6
- package/src/lib/redis.ts +56 -0
- package/src/lib/thumbnailGenerator.ts +170 -168
- package/src/middleware/auth.ts +86 -137
- package/src/middleware/security.ts +80 -0
- package/src/models/agenda.ts +46 -0
- package/src/models/announcement.ts +134 -0
- package/src/models/assignment.ts +322 -0
- package/src/models/attendance.ts +208 -0
- package/src/models/auth.ts +247 -0
- package/src/models/class.ts +598 -0
- package/src/models/comment.ts +152 -0
- package/src/models/conversation.ts +200 -0
- package/src/models/event.ts +177 -0
- package/src/models/file.ts +129 -0
- package/src/models/folder.ts +225 -0
- package/src/models/labChat.ts +213 -0
- package/src/models/marketing.ts +45 -0
- package/src/models/message.ts +153 -0
- package/src/models/newtonChat.ts +70 -0
- package/src/models/notification.ts +54 -0
- package/src/models/section.ts +98 -0
- package/src/models/user.ts +47 -0
- package/src/models/worksheet.ts +294 -0
- package/src/pipelines/aiLabChat.ts +511 -0
- package/src/pipelines/aiNewtonChat.ts +347 -0
- package/src/pipelines/gradeWorksheet.ts +286 -0
- package/src/routers/_app.ts +6 -0
- package/src/routers/agenda.ts +3 -61
- package/src/routers/announcement.ts +622 -57
- package/src/routers/assignment.ts +157 -1688
- package/src/routers/attendance.ts +16 -277
- package/src/routers/auth.ts +79 -313
- package/src/routers/class.ts +265 -1038
- package/src/routers/comment.ts +76 -0
- package/src/routers/conversation.ts +53 -284
- package/src/routers/event.ts +50 -481
- package/src/routers/file.ts +45 -341
- package/src/routers/folder.ts +107 -836
- package/src/routers/labChat.ts +29 -960
- package/src/routers/marketing.ts +35 -77
- package/src/routers/message.ts +45 -571
- package/src/routers/newtonChat.ts +36 -0
- package/src/routers/notifications.ts +32 -82
- package/src/routers/section.ts +58 -200
- package/src/routers/user.ts +49 -226
- package/src/routers/worksheet.ts +252 -0
- package/src/seedDatabase.ts +330 -290
- package/src/services/agenda.ts +21 -0
- package/src/services/announcement.ts +290 -0
- package/src/services/assignment.ts +1198 -0
- package/src/services/attendance.ts +85 -0
- package/src/services/auth.ts +277 -0
- package/src/services/class.ts +622 -0
- package/src/services/comment.ts +106 -0
- package/src/services/conversation.ts +213 -0
- package/src/services/event.ts +231 -0
- package/src/services/file.ts +167 -0
- package/src/services/folder.ts +316 -0
- package/src/services/labChat.ts +352 -0
- package/src/services/marketing.ts +57 -0
- package/src/services/message.ts +461 -0
- package/src/services/newtonChat.ts +222 -0
- package/src/services/notification.ts +50 -0
- package/src/services/section.ts +283 -0
- package/src/services/user.ts +172 -0
- package/src/services/worksheet.ts +358 -0
- package/src/trpc.ts +4 -0
- package/src/utils/aiUser.ts +4 -3
- package/src/utils/email.ts +33 -4
- package/src/utils/generateInviteCode.ts +1 -3
- package/src/utils/inference.ts +89 -10
- package/src/utils/logger.ts +33 -3
- package/src/utils/prismaErrorHandler.ts +3 -0
- package/src/utils/prismaWrapper.ts +4 -0
- package/tests/globalSetup.ts +62 -0
- package/tests/helpers.ts +22 -0
- package/tests/middleware/security.test.ts +42 -0
- package/tests/routers/agenda.test.ts +138 -0
- package/tests/routers/announcement.test.ts +490 -0
- package/tests/routers/assignment.test.ts +837 -0
- package/tests/routers/attendance.test.ts +160 -0
- package/tests/routers/auth.test.ts +171 -0
- package/tests/{class.test.ts → routers/class.test.ts} +163 -92
- package/tests/routers/comment.test.ts +126 -0
- package/tests/routers/conversation.test.ts +145 -0
- package/tests/routers/event.test.ts +289 -0
- package/tests/routers/folder.test.ts +178 -0
- package/tests/routers/labChat.test.ts +115 -0
- package/tests/routers/marketing.test.ts +59 -0
- package/tests/routers/message.test.ts +123 -0
- package/tests/routers/notification.test.ts +69 -0
- package/tests/routers/section.test.ts +208 -0
- package/tests/server/rateLimit.test.ts +73 -0
- package/tests/setup.ts +39 -65
- package/tests/user.test.ts +136 -0
- package/tests/utils/aiUser.test.ts +22 -0
- package/tests/utils/generateInviteCode.test.ts +24 -0
- package/tests/utils/logger.test.ts +74 -0
- package/tests/utils/prismaErrorHandler.test.ts +101 -0
- package/tests/utils/prismaWrapper.test.ts +82 -0
- package/tests/worksheet.test.ts +181 -0
- package/tsconfig.json +9 -2
- package/vitest.config.ts +30 -1
- package/vitest.unit.config.ts +21 -0
- package/API_SPECIFICATION.md +0 -1597
- package/BASE64_REMOVAL_SUMMARY.md +0 -164
- package/CHAT_API_SPEC.md +0 -579
- package/LAB_CHAT_API_SPEC.md +0 -518
- package/dist/routers/school.d.ts +0 -208
- package/dist/routers/school.d.ts.map +0 -1
- package/dist/routers/school.js +0 -481
- package/tests/auth.test.ts +0 -25
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { test, expect, describe, beforeAll } from 'vitest';
|
|
2
|
+
import { user1Caller, user2Caller, user3Caller } from '../setup';
|
|
3
|
+
|
|
4
|
+
describe('Message Router', () => {
|
|
5
|
+
let conversationId: string;
|
|
6
|
+
let messageId: string;
|
|
7
|
+
let user1Id: string;
|
|
8
|
+
let user2Id: string;
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
const user1Profile = await user1Caller.user.getProfile();
|
|
12
|
+
const user2Profile = await user2Caller.user.getProfile();
|
|
13
|
+
user1Id = user1Profile.id;
|
|
14
|
+
user2Id = user2Profile.id;
|
|
15
|
+
|
|
16
|
+
const conversation = await user1Caller.conversation.create({
|
|
17
|
+
type: 'GROUP',
|
|
18
|
+
name: 'Message Test Group',
|
|
19
|
+
memberIds: [user2Id],
|
|
20
|
+
});
|
|
21
|
+
conversationId = conversation.id;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('send', () => {
|
|
25
|
+
test('should send a message', async () => {
|
|
26
|
+
const result = await user1Caller.message.send({
|
|
27
|
+
conversationId,
|
|
28
|
+
content: 'Hello from tests!',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(result).toBeDefined();
|
|
32
|
+
expect(result.content).toBe('Hello from tests!');
|
|
33
|
+
expect(result.senderId).toBe(user1Id);
|
|
34
|
+
messageId = result.id;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should send a message with mentions', async () => {
|
|
38
|
+
const result = await user1Caller.message.send({
|
|
39
|
+
conversationId,
|
|
40
|
+
content: 'Hey @user2!',
|
|
41
|
+
mentionedUserIds: [user2Id],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(result).toBeDefined();
|
|
45
|
+
expect(result.mentionedUserIds).toContain(user2Id);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('should fail for non-member', async () => {
|
|
49
|
+
await expect(
|
|
50
|
+
user3Caller.message.send({
|
|
51
|
+
conversationId,
|
|
52
|
+
content: 'Unauthorized message',
|
|
53
|
+
}),
|
|
54
|
+
).rejects.toThrow();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('list', () => {
|
|
59
|
+
test('should list messages in conversation', async () => {
|
|
60
|
+
const result = await user1Caller.message.list({ conversationId });
|
|
61
|
+
|
|
62
|
+
expect(result.messages).toBeDefined();
|
|
63
|
+
expect(Array.isArray(result.messages)).toBe(true);
|
|
64
|
+
expect(result.messages.length).toBeGreaterThanOrEqual(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should fail for non-member', async () => {
|
|
68
|
+
await expect(
|
|
69
|
+
user3Caller.message.list({ conversationId }),
|
|
70
|
+
).rejects.toThrow();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('update', () => {
|
|
75
|
+
test('should update own message', async () => {
|
|
76
|
+
const result = await user1Caller.message.update({
|
|
77
|
+
messageId,
|
|
78
|
+
content: 'Updated message content',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(result.content).toBe('Updated message content');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should fail to update another user\'s message', async () => {
|
|
85
|
+
await expect(
|
|
86
|
+
user2Caller.message.update({
|
|
87
|
+
messageId,
|
|
88
|
+
content: 'Unauthorized edit',
|
|
89
|
+
}),
|
|
90
|
+
).rejects.toThrow();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('markAsRead', () => {
|
|
95
|
+
test('should mark conversation as read', async () => {
|
|
96
|
+
const result = await user2Caller.message.markAsRead({ conversationId });
|
|
97
|
+
expect(result.success).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('getUnreadCount', () => {
|
|
102
|
+
test('should return unread counts', async () => {
|
|
103
|
+
const result = await user2Caller.message.getUnreadCount({ conversationId });
|
|
104
|
+
|
|
105
|
+
expect(result).toBeDefined();
|
|
106
|
+
expect(typeof result.unreadCount).toBe('number');
|
|
107
|
+
expect(typeof result.unreadMentionCount).toBe('number');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('delete', () => {
|
|
112
|
+
test('should fail to delete another user\'s message', async () => {
|
|
113
|
+
await expect(
|
|
114
|
+
user2Caller.message.delete({ messageId }),
|
|
115
|
+
).rejects.toThrow();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('should delete own message', async () => {
|
|
119
|
+
const result = await user1Caller.message.delete({ messageId });
|
|
120
|
+
expect(result.success).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test, expect, describe } from 'vitest';
|
|
2
|
+
import { user1Caller, user2Caller } from '../setup';
|
|
3
|
+
import { expectUnauth } from '../helpers';
|
|
4
|
+
|
|
5
|
+
describe('Notification Router', () => {
|
|
6
|
+
let notificationId: string;
|
|
7
|
+
let user2Id: string;
|
|
8
|
+
|
|
9
|
+
test('should send notification to another user', async () => {
|
|
10
|
+
const user2Profile = await user2Caller.user.getProfile();
|
|
11
|
+
user2Id = user2Profile.id;
|
|
12
|
+
|
|
13
|
+
const notification = await user1Caller.notification.sendTo({
|
|
14
|
+
receiverId: user2Id,
|
|
15
|
+
title: 'Test Notification',
|
|
16
|
+
content: 'This is a test notification',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(notification).toBeDefined();
|
|
20
|
+
expect(notification.title).toBe('Test Notification');
|
|
21
|
+
expect(notification.content).toBe('This is a test notification');
|
|
22
|
+
expect(notification.receiverId).toBe(user2Id);
|
|
23
|
+
notificationId = notification.id;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should list notifications for receiver', async () => {
|
|
27
|
+
const notifications = await user2Caller.notification.list();
|
|
28
|
+
|
|
29
|
+
expect(Array.isArray(notifications)).toBe(true);
|
|
30
|
+
const found = notifications.find((n) => n.id === notificationId);
|
|
31
|
+
expect(found).toBeDefined();
|
|
32
|
+
expect(found!.title).toBe('Test Notification');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should get a single notification', async () => {
|
|
36
|
+
const notification = await user2Caller.notification.get({ id: notificationId });
|
|
37
|
+
|
|
38
|
+
expect(notification).toBeDefined();
|
|
39
|
+
expect(notification!.id).toBe(notificationId);
|
|
40
|
+
expect(notification!.title).toBe('Test Notification');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should mark notification as read', async () => {
|
|
44
|
+
const notification = await user2Caller.notification.markAsRead({ id: notificationId });
|
|
45
|
+
|
|
46
|
+
expect(notification.read).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should send to multiple users', async () => {
|
|
50
|
+
const user1Profile = await user1Caller.user.getProfile();
|
|
51
|
+
|
|
52
|
+
const result = await user1Caller.notification.sendToMultiple({
|
|
53
|
+
receiverIds: [user2Id, user1Profile.id],
|
|
54
|
+
title: 'Bulk Notification',
|
|
55
|
+
content: 'Sent to multiple users',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(result.count).toBe(2);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should not list notifications meant for other users', async () => {
|
|
62
|
+
const notifications = await user1Caller.notification.list();
|
|
63
|
+
const foreignNotif = notifications.find((n) => n.id === notificationId);
|
|
64
|
+
expect(foreignNotif).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should fail without authentication', () =>
|
|
68
|
+
expectUnauth((c) => c.notification.list()));
|
|
69
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach } from 'vitest';
|
|
2
|
+
import { user1Caller, user2Caller } from '../setup';
|
|
3
|
+
import { expectUnauth } from '../helpers';
|
|
4
|
+
|
|
5
|
+
describe('Section Router', () => {
|
|
6
|
+
let testClass: any;
|
|
7
|
+
let testSection: any;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
// Create a test class
|
|
11
|
+
testClass = await user1Caller.class.create({
|
|
12
|
+
name: 'Test Class for Sections',
|
|
13
|
+
subject: 'Mathematics',
|
|
14
|
+
section: '10th Grade',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Create a test section
|
|
18
|
+
testSection = await user1Caller.section.create({
|
|
19
|
+
classId: testClass.id,
|
|
20
|
+
name: 'Test Section',
|
|
21
|
+
color: '#3B82F6',
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('create', () => {
|
|
26
|
+
test('should create section successfully', async () => {
|
|
27
|
+
expect(testSection).toBeDefined();
|
|
28
|
+
expect(testSection.id).toBeDefined();
|
|
29
|
+
expect(testSection.name).toBe('Test Section');
|
|
30
|
+
expect(testSection.color).toBe('#3B82F6');
|
|
31
|
+
expect(testSection.classId).toBe(testClass.id);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('should create section without color', async () => {
|
|
35
|
+
const section = await user1Caller.section.create({
|
|
36
|
+
classId: testClass.id,
|
|
37
|
+
name: 'Section Without Color',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(section).toBeDefined();
|
|
41
|
+
expect(section.name).toBe('Section Without Color');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should fail to create section for class user is not teacher of', async () => {
|
|
45
|
+
await expect(user2Caller.section.create({
|
|
46
|
+
classId: testClass.id,
|
|
47
|
+
name: 'Unauthorized Section',
|
|
48
|
+
})).rejects.toThrow();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should fail without authentication', () =>
|
|
52
|
+
expectUnauth((c) => c.section.create({
|
|
53
|
+
classId: testClass.id,
|
|
54
|
+
name: 'Test Section',
|
|
55
|
+
})));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('update', () => {
|
|
59
|
+
test('should update section successfully', async () => {
|
|
60
|
+
const updated = await user1Caller.section.update({
|
|
61
|
+
id: testSection.id,
|
|
62
|
+
classId: testClass.id,
|
|
63
|
+
name: 'Updated Section Name',
|
|
64
|
+
color: '#10B981',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(updated.name).toBe('Updated Section Name');
|
|
68
|
+
expect(updated.color).toBe('#10B981');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should update section with partial data', async () => {
|
|
72
|
+
const updated = await user1Caller.section.update({
|
|
73
|
+
id: testSection.id,
|
|
74
|
+
classId: testClass.id,
|
|
75
|
+
name: 'Partially Updated Section',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(updated.name).toBe('Partially Updated Section');
|
|
79
|
+
expect(updated.color).toBe('#3B82F6'); // Should remain unchanged
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should fail to update section user is not teacher of', async () => {
|
|
83
|
+
await expect(user2Caller.section.update({
|
|
84
|
+
id: testSection.id,
|
|
85
|
+
classId: testClass.id,
|
|
86
|
+
name: 'Unauthorized Update',
|
|
87
|
+
})).rejects.toThrow();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('delete', () => {
|
|
92
|
+
test('should delete section successfully', async () => {
|
|
93
|
+
// Create a new section to delete
|
|
94
|
+
const newSection = await user1Caller.section.create({
|
|
95
|
+
classId: testClass.id,
|
|
96
|
+
name: 'To Be Deleted',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const result = await user1Caller.section.delete({
|
|
100
|
+
id: newSection.id,
|
|
101
|
+
classId: testClass.id,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(result.id).toBe(newSection.id);
|
|
105
|
+
|
|
106
|
+
// Verify section is deleted by trying to update it
|
|
107
|
+
await expect(user1Caller.section.update({
|
|
108
|
+
id: newSection.id,
|
|
109
|
+
classId: testClass.id,
|
|
110
|
+
name: 'Test',
|
|
111
|
+
})).rejects.toThrow();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('should fail to delete section user is not teacher of', async () => {
|
|
115
|
+
await expect(user2Caller.section.delete({
|
|
116
|
+
id: testSection.id,
|
|
117
|
+
classId: testClass.id,
|
|
118
|
+
})).rejects.toThrow();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('reorder', () => {
|
|
123
|
+
test('should reorder section to start', async () => {
|
|
124
|
+
// Create another section
|
|
125
|
+
const section2 = await user1Caller.section.create({
|
|
126
|
+
classId: testClass.id,
|
|
127
|
+
name: 'Second Section',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const originalOrder = section2.order;
|
|
131
|
+
const result = await user1Caller.section.reorder({
|
|
132
|
+
classId: testClass.id,
|
|
133
|
+
movedId: section2.id,
|
|
134
|
+
position: 'start',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(result).toBeDefined();
|
|
138
|
+
expect(result?.order).toBeDefined();
|
|
139
|
+
// When moved to start, order should be less than original
|
|
140
|
+
expect(result?.order).toBeLessThanOrEqual(originalOrder || Infinity);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should reorder section to end', async () => {
|
|
144
|
+
const section2 = await user1Caller.section.create({
|
|
145
|
+
classId: testClass.id,
|
|
146
|
+
name: 'Third Section',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const originalOrder = section2.order;
|
|
150
|
+
const result = await user1Caller.section.reorder({
|
|
151
|
+
classId: testClass.id,
|
|
152
|
+
movedId: section2.id,
|
|
153
|
+
position: 'end',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(result).toBeDefined();
|
|
157
|
+
expect(result?.order).toBeDefined();
|
|
158
|
+
// When moved to end, order should be greater than or equal to original
|
|
159
|
+
expect(result?.order).toBeGreaterThanOrEqual(originalOrder || 0);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('should reorder section before another', async () => {
|
|
163
|
+
const section2 = await user1Caller.section.create({
|
|
164
|
+
classId: testClass.id,
|
|
165
|
+
name: 'Fourth Section',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const targetOrder = testSection.order;
|
|
169
|
+
const result = await user1Caller.section.reorder({
|
|
170
|
+
classId: testClass.id,
|
|
171
|
+
movedId: section2.id,
|
|
172
|
+
position: 'before',
|
|
173
|
+
targetId: testSection.id,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(result).toBeDefined();
|
|
177
|
+
expect(result?.order).toBeDefined();
|
|
178
|
+
// When moved before target, order should be less than target's order
|
|
179
|
+
expect(result?.order).toBeLessThan(targetOrder || Infinity);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('should fail to reorder section user is not teacher of', async () => {
|
|
183
|
+
// Create a separate class that user2 is not part of
|
|
184
|
+
const otherClass = await user1Caller.class.create({
|
|
185
|
+
name: 'Other Class for Reorder Test',
|
|
186
|
+
subject: 'Science',
|
|
187
|
+
section: '11th Grade',
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const otherSection = await user1Caller.section.create({
|
|
191
|
+
classId: otherClass.id,
|
|
192
|
+
name: 'Other Section',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// user2 is not a member of otherClass, so they shouldn't be able to reorder
|
|
196
|
+
// Note: The reorder endpoint uses protectedProcedure, not protectedTeacherProcedure
|
|
197
|
+
// It only checks if the section exists, not teacher permissions
|
|
198
|
+
// So if user2 can see the section (e.g., if they're a student), reorder will succeed
|
|
199
|
+
// This test verifies that non-class members can't reorder
|
|
200
|
+
await expect(user2Caller.section.reorder({
|
|
201
|
+
classId: otherClass.id,
|
|
202
|
+
movedId: otherSection.id,
|
|
203
|
+
position: 'start',
|
|
204
|
+
})).rejects.toThrow();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import rateLimit from 'express-rate-limit';
|
|
4
|
+
import request from 'supertest';
|
|
5
|
+
|
|
6
|
+
describe('rate limiting', () => {
|
|
7
|
+
let app: express.Application;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
// Fresh app per test so rate limit state doesn't leak between tests
|
|
11
|
+
app = express();
|
|
12
|
+
const testLimiter = rateLimit({
|
|
13
|
+
windowMs: 60 * 1000,
|
|
14
|
+
max: 3,
|
|
15
|
+
standardHeaders: true,
|
|
16
|
+
legacyHeaders: false,
|
|
17
|
+
handler: (req, res) => {
|
|
18
|
+
res.status(429).json({
|
|
19
|
+
code: 'TOO_MANY_REQUESTS',
|
|
20
|
+
message: 'Too many requests, please try again later.',
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
skip: (req) => req.path === '/health' || req.method === 'OPTIONS',
|
|
24
|
+
});
|
|
25
|
+
app.use(testLimiter);
|
|
26
|
+
app.get('/health', (_req, res) => res.status(200).json({ status: 'OK' }));
|
|
27
|
+
app.get('/api/test', (_req, res) => res.status(200).json({ ok: true }));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('allows requests under the limit', async () => {
|
|
31
|
+
const res = await request(app).get('/api/test');
|
|
32
|
+
expect(res.status).toBe(200);
|
|
33
|
+
expect(res.body.ok).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('returns 429 when limit exceeded', async () => {
|
|
37
|
+
// Make 4 sequential requests; 4th should be rate limited
|
|
38
|
+
const r1 = await request(app).get('/api/test');
|
|
39
|
+
const r2 = await request(app).get('/api/test');
|
|
40
|
+
const r3 = await request(app).get('/api/test');
|
|
41
|
+
const r4 = await request(app).get('/api/test');
|
|
42
|
+
|
|
43
|
+
expect(r1.status).toBe(200);
|
|
44
|
+
expect(r2.status).toBe(200);
|
|
45
|
+
expect(r3.status).toBe(200);
|
|
46
|
+
expect(r4.status).toBe(429);
|
|
47
|
+
|
|
48
|
+
expect(r4.body.code).toBe('TOO_MANY_REQUESTS');
|
|
49
|
+
expect(r4.body.message).toContain('Too many requests');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('skips rate limiting for /health', async () => {
|
|
53
|
+
// Make many health requests - all should succeed
|
|
54
|
+
const requests = Array(5)
|
|
55
|
+
.fill(null)
|
|
56
|
+
.map(() => request(app).get('/health'));
|
|
57
|
+
const responses = await Promise.all(requests);
|
|
58
|
+
expect(responses.every((r) => r.status === 200)).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('429 response matches production format (code + message)', async () => {
|
|
62
|
+
await request(app).get('/api/test');
|
|
63
|
+
await request(app).get('/api/test');
|
|
64
|
+
await request(app).get('/api/test');
|
|
65
|
+
const limited = await request(app).get('/api/test');
|
|
66
|
+
expect(limited.status).toBe(429);
|
|
67
|
+
// Same structure as src/middleware/security.ts rateLimitHandler
|
|
68
|
+
expect(limited.body).toEqual({
|
|
69
|
+
code: 'TOO_MANY_REQUESTS',
|
|
70
|
+
message: 'Too many requests, please try again later.',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
package/tests/setup.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
+
import { config } from 'dotenv';
|
|
3
|
+
import { resolve } from 'path';
|
|
2
4
|
import { prisma } from '../src/lib/prisma';
|
|
3
5
|
import { beforeAll, beforeEach, afterAll, afterEach } from 'vitest';
|
|
4
6
|
import { logger } from '../src/utils/logger';
|
|
@@ -6,93 +8,65 @@ import { appRouter } from '../src/routers/_app';
|
|
|
6
8
|
import { createTRPCContext } from '../src/trpc';
|
|
7
9
|
import { Session } from '@prisma/client';
|
|
8
10
|
|
|
11
|
+
// Load test environment variables
|
|
12
|
+
config({ path: resolve(process.cwd(), '.env.test') });
|
|
13
|
+
|
|
9
14
|
const getCaller = async (token: string) => {
|
|
10
15
|
const ctx = await createTRPCContext({
|
|
11
16
|
req: { headers: {
|
|
12
|
-
authorization: `Bearer ${token}
|
|
13
|
-
'x-user': token,
|
|
17
|
+
authorization: token ? `Bearer ${token}` : undefined,
|
|
18
|
+
'x-user': token || undefined,
|
|
14
19
|
} } as any,
|
|
15
20
|
res: {} as any,
|
|
16
21
|
});
|
|
17
22
|
return appRouter.createCaller(ctx);
|
|
18
23
|
};
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// logger.info('Setting up test database');
|
|
25
|
-
// execSync('rm -f prisma/test.db');
|
|
26
|
-
// execSync('npx prisma db push --force-reset --schema=prisma/schema.prisma');
|
|
27
|
-
|
|
28
|
-
// } catch (error) {
|
|
29
|
-
// logger.error('Error initializing test database');
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
logger.info('Getting caller');
|
|
33
|
-
|
|
34
|
-
caller = await getCaller('');
|
|
35
|
-
|
|
36
|
-
const user1 = await caller.auth.register({
|
|
37
|
-
username: 'testuser1',
|
|
38
|
-
email: 'test@test.com',
|
|
39
|
-
password: 'password_is_1234',
|
|
40
|
-
confirmPassword: 'password_is_1234',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const user2 = await caller.auth.register({
|
|
44
|
-
username: 'testuser2',
|
|
45
|
-
email: 'test2@test.com',
|
|
46
|
-
password: 'password_is_1234',
|
|
47
|
-
confirmPassword: 'password_is_1234',
|
|
48
|
-
});
|
|
25
|
+
// globalSetup already registered users; we just login and create callers.
|
|
26
|
+
// Safe to run in parallel — no registration, no DB writes.
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
caller = await getCaller('');
|
|
49
29
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
}) as Session;
|
|
30
|
+
login1 = await caller.auth.login({ username: 'testuser1', password: 'password_is_1234' });
|
|
31
|
+
login2 = await caller.auth.login({ username: 'testuser2', password: 'password_is_1234' });
|
|
32
|
+
login3 = await caller.auth.login({ username: 'testuser3', password: 'password_is_1234' });
|
|
55
33
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
})) as Session;
|
|
34
|
+
if (!login1.token || !login2.token || !login3.token) {
|
|
35
|
+
throw new Error('Failed to get login tokens — ensure globalSetup ran');
|
|
36
|
+
}
|
|
61
37
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
session1 = await prisma.session.findFirst({ where: { userId: login1.user.id } }) as Session;
|
|
39
|
+
session2 = await prisma.session.findFirst({ where: { userId: login2.user.id } }) as Session;
|
|
40
|
+
session3 = await prisma.session.findFirst({ where: { userId: login3.user.id } }) as Session;
|
|
65
41
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
verification1 = { verified: true };
|
|
43
|
+
verification2 = { verified: true };
|
|
44
|
+
verification3 = { verified: true };
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
46
|
+
user1Caller = await getCaller(login1.token);
|
|
47
|
+
user2Caller = await getCaller(login2.token);
|
|
48
|
+
user3Caller = await getCaller(login3.token);
|
|
49
|
+
});
|
|
74
50
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
user1Caller = await getCaller(login1.token);
|
|
81
|
-
user2Caller = await getCaller(login2.token);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// After all tests, close the DB
|
|
86
|
-
afterAll(async () => {
|
|
51
|
+
// After all tests, close the DB
|
|
52
|
+
afterAll(async () => {
|
|
53
|
+
try {
|
|
87
54
|
await prisma.$disconnect();
|
|
88
|
-
})
|
|
55
|
+
} catch (error) {
|
|
56
|
+
logger.error('Error disconnecting from database', { error });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
89
59
|
|
|
90
60
|
export let user1Caller: ReturnType<typeof appRouter.createCaller>;
|
|
91
61
|
export let user2Caller: ReturnType<typeof appRouter.createCaller>;
|
|
62
|
+
export let user3Caller: ReturnType<typeof appRouter.createCaller>;
|
|
92
63
|
export let caller: ReturnType<typeof appRouter.createCaller>;
|
|
93
64
|
export let session1: Session;
|
|
94
65
|
export let session2: Session;
|
|
66
|
+
export let session3: Session;
|
|
95
67
|
export let verification1: any;
|
|
96
68
|
export let verification2: any;
|
|
69
|
+
export let verification3: any;
|
|
97
70
|
export let login1: any;
|
|
98
|
-
export let login2: any;
|
|
71
|
+
export let login2: any;
|
|
72
|
+
export let login3: any;
|