@studious-lms/server 1.2.44 → 1.2.46
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/.env.example +45 -0
- package/.env.test.example +37 -0
- package/README.md +34 -7
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +12110 -0
- package/coverage/coverage-final.json +44 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +221 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/server/index.html +116 -0
- package/coverage/server/src/exportType.ts.html +109 -0
- package/coverage/server/src/index.html +161 -0
- package/coverage/server/src/index.ts.html +1702 -0
- package/coverage/server/src/instrument.ts.html +130 -0
- package/coverage/server/src/lib/config/env.ts.html +448 -0
- package/coverage/server/src/lib/config/index.html +116 -0
- package/coverage/server/src/lib/fileUpload.ts.html +1138 -0
- package/coverage/server/src/lib/googleCloudStorage.ts.html +334 -0
- package/coverage/server/src/lib/index.html +206 -0
- package/coverage/server/src/lib/jsonConversion.ts.html +2323 -0
- package/coverage/server/src/lib/jsonStyles.ts.html +193 -0
- package/coverage/server/src/lib/notificationHandler.ts.html +193 -0
- package/coverage/server/src/lib/pusher.ts.html +121 -0
- package/coverage/server/src/lib/thumbnailGenerator.ts.html +592 -0
- package/coverage/server/src/middleware/auth.ts.html +646 -0
- package/coverage/server/src/middleware/index.html +146 -0
- package/coverage/server/src/middleware/logging.ts.html +244 -0
- package/coverage/server/src/middleware/security.ts.html +271 -0
- package/coverage/server/src/routers/_app.ts.html +232 -0
- package/coverage/server/src/routers/agenda.ts.html +319 -0
- package/coverage/server/src/routers/announcement.ts.html +3481 -0
- package/coverage/server/src/routers/assignment.ts.html +7633 -0
- package/coverage/server/src/routers/attendance.ts.html +1030 -0
- package/coverage/server/src/routers/auth.ts.html +1081 -0
- package/coverage/server/src/routers/class.ts.html +3535 -0
- package/coverage/server/src/routers/comment.ts.html +991 -0
- package/coverage/server/src/routers/conversation.ts.html +982 -0
- package/coverage/server/src/routers/event.ts.html +1609 -0
- package/coverage/server/src/routers/file.ts.html +1144 -0
- package/coverage/server/src/routers/folder.ts.html +2797 -0
- package/coverage/server/src/routers/index.html +386 -0
- package/coverage/server/src/routers/labChat.ts.html +3073 -0
- package/coverage/server/src/routers/marketing.ts.html +340 -0
- package/coverage/server/src/routers/message.ts.html +1912 -0
- package/coverage/server/src/routers/notifications.ts.html +364 -0
- package/coverage/server/src/routers/section.ts.html +1120 -0
- package/coverage/server/src/routers/user.ts.html +862 -0
- package/coverage/server/src/routers/worksheet.ts.html +1729 -0
- package/coverage/server/src/trpc.ts.html +397 -0
- package/coverage/server/src/types/index.html +116 -0
- package/coverage/server/src/types/trpc.ts.html +127 -0
- package/coverage/server/src/utils/aiUser.ts.html +280 -0
- package/coverage/server/src/utils/email.ts.html +121 -0
- package/coverage/server/src/utils/generateInviteCode.ts.html +106 -0
- package/coverage/server/src/utils/index.html +206 -0
- package/coverage/server/src/utils/inference.ts.html +709 -0
- package/coverage/server/src/utils/logger.ts.html +664 -0
- package/coverage/server/src/utils/prismaErrorHandler.ts.html +907 -0
- package/coverage/server/src/utils/prismaWrapper.ts.html +355 -0
- package/coverage/server/vitest.config.ts.html +196 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -52
- package/dist/index.js.map +1 -1
- package/dist/instrument.js +15 -8
- package/dist/instrument.js.map +1 -1
- package/dist/lib/config/env.d.ts +169 -0
- package/dist/lib/config/env.d.ts.map +1 -0
- package/dist/lib/config/env.js +115 -0
- package/dist/lib/config/env.js.map +1 -0
- package/dist/lib/fileUpload.d.ts.map +1 -1
- package/dist/lib/fileUpload.js +5 -4
- package/dist/lib/fileUpload.js.map +1 -1
- package/dist/lib/googleCloudStorage.d.ts.map +1 -1
- package/dist/lib/googleCloudStorage.js +7 -8
- package/dist/lib/googleCloudStorage.js.map +1 -1
- package/dist/lib/jsonConversion.d.ts.map +1 -1
- package/dist/lib/jsonConversion.js +14 -16
- package/dist/lib/jsonConversion.js.map +1 -1
- package/dist/lib/notificationHandler.d.ts +2 -2
- package/dist/lib/prisma.d.ts +2 -2
- package/dist/lib/prisma.d.ts.map +1 -1
- package/dist/lib/prisma.js +22 -3
- package/dist/lib/prisma.js.map +1 -1
- package/dist/lib/pusher.d.ts.map +1 -1
- package/dist/lib/pusher.js +8 -7
- package/dist/lib/pusher.js.map +1 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +6 -5
- package/dist/middleware/auth.js.map +1 -1
- 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/routers/_app.d.ts +304 -98
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/_app.js +4 -2
- package/dist/routers/_app.js.map +1 -1
- package/dist/routers/agenda.d.ts.map +1 -1
- package/dist/routers/agenda.js +12 -9
- package/dist/routers/agenda.js.map +1 -1
- package/dist/routers/announcement.d.ts +8 -0
- package/dist/routers/announcement.d.ts.map +1 -1
- package/dist/routers/announcement.js +6 -4
- package/dist/routers/announcement.js.map +1 -1
- package/dist/routers/assignment.d.ts +7 -4
- package/dist/routers/assignment.d.ts.map +1 -1
- package/dist/routers/assignment.js +35 -18
- package/dist/routers/assignment.js.map +1 -1
- package/dist/routers/attendance.d.ts +1 -0
- package/dist/routers/attendance.d.ts.map +1 -1
- package/dist/routers/attendance.js +4 -4
- package/dist/routers/attendance.js.map +1 -1
- package/dist/routers/auth.d.ts +20 -0
- package/dist/routers/auth.d.ts.map +1 -1
- package/dist/routers/auth.js +132 -15
- package/dist/routers/auth.js.map +1 -1
- package/dist/routers/class.d.ts +10 -0
- package/dist/routers/class.d.ts.map +1 -1
- package/dist/routers/class.js +49 -5
- package/dist/routers/class.js.map +1 -1
- package/dist/routers/comment.d.ts +7 -0
- package/dist/routers/comment.d.ts.map +1 -1
- package/dist/routers/comment.js +9 -2
- package/dist/routers/comment.js.map +1 -1
- package/dist/routers/conversation.d.ts +1 -0
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/conversation.js +46 -31
- package/dist/routers/conversation.js.map +1 -1
- package/dist/routers/file.d.ts.map +1 -1
- package/dist/routers/file.js +30 -7
- package/dist/routers/file.js.map +1 -1
- package/dist/routers/labChat.d.ts +1 -0
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/labChat.js +2 -3
- package/dist/routers/labChat.js.map +1 -1
- package/dist/routers/marketing.d.ts +1 -1
- package/dist/routers/newtonChat.d.ts +55 -0
- package/dist/routers/newtonChat.d.ts.map +1 -0
- package/dist/routers/newtonChat.js +438 -0
- package/dist/routers/newtonChat.js.map +1 -0
- package/dist/routers/notifications.d.ts +4 -4
- package/dist/routers/section.d.ts +9 -4
- package/dist/routers/section.d.ts.map +1 -1
- package/dist/routers/section.js +8 -8
- package/dist/routers/section.js.map +1 -1
- package/dist/routers/user.d.ts.map +1 -1
- package/dist/routers/user.js +5 -4
- package/dist/routers/user.js.map +1 -1
- package/dist/routers/worksheet.d.ts +30 -36
- package/dist/routers/worksheet.d.ts.map +1 -1
- package/dist/routers/worksheet.js +11 -33
- package/dist/routers/worksheet.js.map +1 -1
- package/dist/seedDatabase.d.ts +1 -1
- package/dist/seedDatabase.js +275 -284
- package/dist/seedDatabase.js.map +1 -1
- package/dist/server/pipelines/aiLabChat.d.ts +10 -0
- package/dist/server/pipelines/aiLabChat.d.ts.map +1 -0
- package/dist/server/pipelines/aiLabChat.js +83 -0
- package/dist/server/pipelines/aiLabChat.js.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts +2 -0
- package/dist/server/pipelines/gradeWorksheet.d.ts.map +1 -0
- package/dist/server/pipelines/gradeWorksheet.js +138 -0
- package/dist/server/pipelines/gradeWorksheet.js.map +1 -0
- package/dist/trpc.d.ts.map +1 -1
- package/dist/trpc.js +2 -2
- package/dist/trpc.js.map +1 -1
- package/dist/utils/email.d.ts +9 -1
- package/dist/utils/email.d.ts.map +1 -1
- package/dist/utils/email.js +20 -5
- package/dist/utils/email.js.map +1 -1
- package/dist/utils/inference.d.ts +3 -0
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +41 -7
- package/dist/utils/inference.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils/logger.js.map +1 -1
- package/docker-compose.yml +14 -0
- package/package.json +13 -4
- package/prisma/schema.prisma +32 -5
- package/scripts/test-pre-push.ts +14 -0
- package/src/index.ts +98 -54
- package/src/instrument.ts +13 -6
- package/src/lib/config/env.ts +126 -0
- package/src/lib/fileUpload.ts +3 -2
- package/src/lib/googleCloudStorage.ts +6 -6
- package/src/lib/jsonConversion.ts +12 -14
- package/src/lib/prisma.ts +23 -2
- package/src/lib/pusher.ts +6 -5
- package/src/middleware/auth.ts +4 -3
- package/src/middleware/security.ts +80 -0
- package/src/routers/_app.ts +2 -0
- package/src/routers/agenda.ts +10 -7
- package/src/routers/announcement.ts +4 -2
- package/src/routers/assignment.ts +58 -40
- package/src/routers/attendance.ts +2 -2
- package/src/routers/auth.ts +143 -14
- package/src/routers/class.ts +52 -3
- package/src/routers/comment.ts +7 -0
- package/src/routers/conversation.ts +49 -29
- package/src/routers/file.ts +29 -5
- package/src/routers/labChat.ts +0 -1
- package/src/routers/newtonChat.ts +520 -0
- package/src/routers/section.ts +6 -6
- package/src/routers/user.ts +3 -2
- package/src/routers/worksheet.ts +9 -37
- package/src/seedDatabase.ts +290 -283
- package/src/server/pipelines/aiLabChat.ts +92 -0
- package/src/server/pipelines/gradeWorksheet.ts +152 -0
- package/src/trpc.ts +2 -0
- package/src/utils/email.ts +30 -3
- package/src/utils/inference.ts +50 -5
- package/src/utils/logger.ts +2 -1
- package/tests/announcement.test.ts +164 -0
- package/tests/assignment.test.ts +296 -0
- package/tests/attendance.test.ts +168 -0
- package/tests/auth.test.ts +33 -10
- package/tests/class.test.ts +34 -9
- package/tests/event.test.ts +228 -0
- package/tests/section.test.ts +216 -0
- package/tests/setup.ts +70 -16
- package/tests/user.test.ts +158 -0
- package/vitest.config.ts +26 -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 -483
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach } from 'vitest';
|
|
2
|
+
import { user1Caller, user2Caller } from './setup';
|
|
3
|
+
import { createTRPCContext } from '../src/trpc';
|
|
4
|
+
import { appRouter } from '../src/routers/_app';
|
|
5
|
+
|
|
6
|
+
describe('Assignment Router', () => {
|
|
7
|
+
let testClass: any;
|
|
8
|
+
let testAssignment: any;
|
|
9
|
+
let studentId: string;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
// Create a test class
|
|
13
|
+
testClass = await user1Caller.class.create({
|
|
14
|
+
name: 'Test Class for Assignments',
|
|
15
|
+
subject: 'Mathematics',
|
|
16
|
+
section: '10th Grade',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Add user2 as a student
|
|
20
|
+
const studentProfile = await user2Caller.user.getProfile();
|
|
21
|
+
studentId = studentProfile.id;
|
|
22
|
+
await user1Caller.class.addStudent({
|
|
23
|
+
classId: testClass.id,
|
|
24
|
+
studentId: studentId,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Create a test assignment
|
|
28
|
+
const dueDate = new Date();
|
|
29
|
+
dueDate.setDate(dueDate.getDate() + 7); // Due in 7 days
|
|
30
|
+
|
|
31
|
+
testAssignment = await user1Caller.assignment.create({
|
|
32
|
+
classId: testClass.id,
|
|
33
|
+
title: 'Test Assignment',
|
|
34
|
+
instructions: 'Complete this test assignment',
|
|
35
|
+
dueDate: dueDate.toISOString(),
|
|
36
|
+
maxGrade: 100,
|
|
37
|
+
type: 'HOMEWORK',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('create', () => {
|
|
42
|
+
test('should create assignment successfully', async () => {
|
|
43
|
+
expect(testAssignment).toBeDefined();
|
|
44
|
+
expect(testAssignment).toBeDefined();
|
|
45
|
+
expect(testAssignment.title).toBe('Test Assignment');
|
|
46
|
+
expect(testAssignment.instructions).toBe('Complete this test assignment');
|
|
47
|
+
expect(testAssignment.maxGrade).toBe(100);
|
|
48
|
+
expect(testAssignment.type).toBe('HOMEWORK');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should create assignment with different types', async () => {
|
|
52
|
+
const dueDate = new Date();
|
|
53
|
+
dueDate.setDate(dueDate.getDate() + 7);
|
|
54
|
+
|
|
55
|
+
const quiz = await user1Caller.assignment.create({
|
|
56
|
+
classId: testClass.id,
|
|
57
|
+
title: 'Test Quiz',
|
|
58
|
+
instructions: 'Complete this quiz',
|
|
59
|
+
dueDate: dueDate.toISOString(),
|
|
60
|
+
type: 'QUIZ',
|
|
61
|
+
maxGrade: 50,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(quiz.type).toBe('QUIZ');
|
|
65
|
+
expect(quiz.maxGrade).toBe(50);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should create assignment with files', async () => {
|
|
69
|
+
const dueDate = new Date();
|
|
70
|
+
dueDate.setDate(dueDate.getDate() + 7);
|
|
71
|
+
|
|
72
|
+
const assignment = await user1Caller.assignment.create({
|
|
73
|
+
classId: testClass.id,
|
|
74
|
+
title: 'Assignment with Files',
|
|
75
|
+
instructions: 'Submit with files',
|
|
76
|
+
dueDate: dueDate.toISOString(),
|
|
77
|
+
acceptFiles: true,
|
|
78
|
+
files: [
|
|
79
|
+
{
|
|
80
|
+
name: 'test.pdf',
|
|
81
|
+
type: 'application/pdf',
|
|
82
|
+
size: 1024,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(assignment).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should fail to create assignment for class user is not teacher of', async () => {
|
|
91
|
+
const dueDate = new Date();
|
|
92
|
+
dueDate.setDate(dueDate.getDate() + 7);
|
|
93
|
+
|
|
94
|
+
await expect(user2Caller.assignment.create({
|
|
95
|
+
classId: testClass.id,
|
|
96
|
+
title: 'Unauthorized Assignment',
|
|
97
|
+
instructions: 'Test',
|
|
98
|
+
dueDate: dueDate.toISOString(),
|
|
99
|
+
})).rejects.toThrow();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('should fail without authentication', async () => {
|
|
103
|
+
const invalidCaller = await createTRPCContext({
|
|
104
|
+
req: { headers: {} } as any,
|
|
105
|
+
res: {} as any,
|
|
106
|
+
});
|
|
107
|
+
const router = appRouter.createCaller(invalidCaller);
|
|
108
|
+
|
|
109
|
+
const dueDate = new Date();
|
|
110
|
+
await expect(router.assignment.create({
|
|
111
|
+
classId: testClass.id,
|
|
112
|
+
title: 'Test',
|
|
113
|
+
instructions: 'Test',
|
|
114
|
+
dueDate: dueDate.toISOString(),
|
|
115
|
+
})).rejects.toThrow();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('get', () => {
|
|
120
|
+
test('should get assignment successfully', async () => {
|
|
121
|
+
const assignment = await user1Caller.assignment.get({
|
|
122
|
+
id: testAssignment.id,
|
|
123
|
+
classId: testClass.id,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(assignment).toBeDefined();
|
|
127
|
+
expect(assignment.id).toBe(testAssignment.id);
|
|
128
|
+
expect(assignment.title).toBe('Test Assignment');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should allow students to get assignment', async () => {
|
|
132
|
+
const assignment = await user2Caller.assignment.get({
|
|
133
|
+
id: testAssignment.id,
|
|
134
|
+
classId: testClass.id,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(assignment).toBeDefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('should fail to get assignment for non-class members', async () => {
|
|
141
|
+
const newClass = await user1Caller.class.create({
|
|
142
|
+
name: 'Other Class',
|
|
143
|
+
subject: 'Science',
|
|
144
|
+
section: '11th Grade',
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
await expect(user2Caller.assignment.get({
|
|
148
|
+
id: testAssignment.id,
|
|
149
|
+
classId: newClass.id,
|
|
150
|
+
})).rejects.toThrow();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// describe('getAll', () => {
|
|
155
|
+
// test('should get all assignments for class', async () => {
|
|
156
|
+
// const result = await user1Caller.assignment.get({
|
|
157
|
+
// classId: testClass.id,
|
|
158
|
+
// });
|
|
159
|
+
|
|
160
|
+
// expect(result).toBeDefined();
|
|
161
|
+
// expect(Array.isArray(result)).toBe(true);
|
|
162
|
+
// expect(result.length).toBeGreaterThanOrEqual(1);
|
|
163
|
+
// expect(result.some((a: any) => a.id === testAssignment.id)).toBe(true);
|
|
164
|
+
// });
|
|
165
|
+
|
|
166
|
+
// test('should allow students to get all assignments', async () => {
|
|
167
|
+
// const result = await user2Caller.assignment.({
|
|
168
|
+
// classId: testClass.id,
|
|
169
|
+
// });
|
|
170
|
+
|
|
171
|
+
// expect(result.assignments).toBeDefined();
|
|
172
|
+
// });
|
|
173
|
+
// });
|
|
174
|
+
|
|
175
|
+
describe('update', () => {
|
|
176
|
+
test('should update assignment successfully', async () => {
|
|
177
|
+
const updated = await user1Caller.assignment.update({
|
|
178
|
+
classId: testClass.id,
|
|
179
|
+
id: testAssignment.id,
|
|
180
|
+
title: 'Updated Assignment Title',
|
|
181
|
+
instructions: 'Updated instructions',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(updated.title).toBe('Updated Assignment Title');
|
|
185
|
+
expect(updated.instructions).toBe('Updated instructions');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('should update assignment with partial data', async () => {
|
|
189
|
+
const updated = await user1Caller.assignment.update({
|
|
190
|
+
classId: testClass.id,
|
|
191
|
+
id: testAssignment.id,
|
|
192
|
+
title: 'Partially Updated Title',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(updated.title).toBe('Partially Updated Title');
|
|
196
|
+
expect(updated.instructions).toBe('Complete this test assignment'); // Should remain unchanged
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('should fail to update assignment user is not teacher of', async () => {
|
|
200
|
+
await expect(user2Caller.assignment.update({
|
|
201
|
+
classId: testClass.id,
|
|
202
|
+
id: testAssignment.id,
|
|
203
|
+
title: 'Unauthorized Update',
|
|
204
|
+
})).rejects.toThrow();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('delete', () => {
|
|
209
|
+
test('should delete assignment successfully', async () => {
|
|
210
|
+
// Create a new assignment to delete
|
|
211
|
+
const dueDate = new Date();
|
|
212
|
+
dueDate.setDate(dueDate.getDate() + 7);
|
|
213
|
+
|
|
214
|
+
const newAssignment = await user1Caller.assignment.create({
|
|
215
|
+
classId: testClass.id,
|
|
216
|
+
title: 'To Be Deleted',
|
|
217
|
+
instructions: 'This will be deleted',
|
|
218
|
+
dueDate: dueDate.toISOString(),
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const result = await user1Caller.assignment.delete({
|
|
222
|
+
id: newAssignment.id,
|
|
223
|
+
classId: testClass.id,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result.id).toBe(newAssignment.id);
|
|
227
|
+
|
|
228
|
+
// Verify assignment is deleted
|
|
229
|
+
await expect(user1Caller.assignment.get({
|
|
230
|
+
id: newAssignment.id,
|
|
231
|
+
classId: testClass.id,
|
|
232
|
+
})).rejects.toThrow();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('should fail to delete assignment user is not teacher of', async () => {
|
|
236
|
+
await expect(user2Caller.assignment.delete({
|
|
237
|
+
id: testAssignment.id,
|
|
238
|
+
classId: testClass.id,
|
|
239
|
+
})).rejects.toThrow();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe('submit', () => {
|
|
244
|
+
test('should automatically create submission successfully', async () => {
|
|
245
|
+
// First create a submission
|
|
246
|
+
const submission = await user2Caller.assignment.getSubmission({
|
|
247
|
+
classId: testClass.id,
|
|
248
|
+
assignmentId: testAssignment.id,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
expect(submission).toBeDefined();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('should submit assignment with extended response', async () => {
|
|
255
|
+
|
|
256
|
+
const submission = await user2Caller.assignment.getSubmission({
|
|
257
|
+
classId: testClass.id,
|
|
258
|
+
assignmentId: testAssignment.id,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const updatedSubmission = await user2Caller.assignment.updateSubmission({
|
|
262
|
+
classId: testClass.id,
|
|
263
|
+
assignmentId: testAssignment.id,
|
|
264
|
+
submissionId: submission.id,
|
|
265
|
+
extendedResponse: 'This is my answer to the assignment',
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(updatedSubmission.extendedResponse).toBe('This is my answer to the assignment');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('should fail to submit assignment for non-class members', async () => {
|
|
272
|
+
const newClass = await user1Caller.class.create({
|
|
273
|
+
name: 'Other Class',
|
|
274
|
+
subject: 'Science',
|
|
275
|
+
section: '11th Grade',
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const dueDate = new Date();
|
|
279
|
+
dueDate.setDate(dueDate.getDate() + 7);
|
|
280
|
+
|
|
281
|
+
const newAssignment = await user1Caller.assignment.create({
|
|
282
|
+
classId: newClass.id,
|
|
283
|
+
title: 'Other Assignment',
|
|
284
|
+
instructions: 'Test',
|
|
285
|
+
dueDate: dueDate.toISOString(),
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
await expect(user2Caller.assignment.getSubmission({
|
|
289
|
+
assignmentId: newAssignment.id,
|
|
290
|
+
classId: newClass.id,
|
|
291
|
+
submit: true,
|
|
292
|
+
})).rejects.toThrow();
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach } from 'vitest';
|
|
2
|
+
import { user1Caller, user2Caller } from './setup';
|
|
3
|
+
import { createTRPCContext } from '../src/trpc';
|
|
4
|
+
import { appRouter } from '../src/routers/_app';
|
|
5
|
+
import { prisma } from '../src/lib/prisma';
|
|
6
|
+
|
|
7
|
+
describe('Attendance Router', () => {
|
|
8
|
+
let testClass: any;
|
|
9
|
+
let testEvent: any;
|
|
10
|
+
let student1: any;
|
|
11
|
+
let student2: any;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
// Create a test class
|
|
15
|
+
testClass = await user1Caller.class.create({
|
|
16
|
+
name: 'Test Class for Attendance',
|
|
17
|
+
subject: 'Mathematics',
|
|
18
|
+
section: '10th Grade',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Add user2 as a student to the class
|
|
22
|
+
await user1Caller.class.addStudent({
|
|
23
|
+
classId: testClass.id,
|
|
24
|
+
studentId: (await user2Caller.user.getProfile()).id,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Get student users
|
|
28
|
+
student1 = await user1Caller.user.getProfile();
|
|
29
|
+
student2 = await user2Caller.user.getProfile();
|
|
30
|
+
|
|
31
|
+
// Create a test event
|
|
32
|
+
const startTime = new Date();
|
|
33
|
+
startTime.setHours(10, 0, 0, 0);
|
|
34
|
+
const endTime = new Date(startTime);
|
|
35
|
+
endTime.setHours(11, 0, 0, 0);
|
|
36
|
+
|
|
37
|
+
testEvent = await user1Caller.event.create({
|
|
38
|
+
name: 'Test Event for Attendance',
|
|
39
|
+
startTime: startTime.toISOString(),
|
|
40
|
+
endTime: endTime.toISOString(),
|
|
41
|
+
classId: testClass.id,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('get', () => {
|
|
46
|
+
test('should get attendance for class', async () => {
|
|
47
|
+
const attendance = await user1Caller.attendance.get({
|
|
48
|
+
classId: testClass.id,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(attendance).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should get attendance for specific event', async () => {
|
|
55
|
+
const attendance = await user1Caller.attendance.get({
|
|
56
|
+
classId: testClass.id,
|
|
57
|
+
eventId: testEvent.event.id,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(attendance).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should allow students to view attendance', async () => {
|
|
64
|
+
const attendance = await user2Caller.attendance.get({
|
|
65
|
+
classId: testClass.id,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(attendance).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should fail for non-class members', async () => {
|
|
72
|
+
// Create a new user and class
|
|
73
|
+
const newClass = await user1Caller.class.create({
|
|
74
|
+
name: 'Other Class',
|
|
75
|
+
subject: 'Science',
|
|
76
|
+
section: '11th Grade',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await expect(user2Caller.attendance.get({
|
|
80
|
+
classId: newClass.id,
|
|
81
|
+
})).rejects.toThrow();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('update', () => {
|
|
86
|
+
test('should update attendance successfully', async () => {
|
|
87
|
+
const result = await user1Caller.attendance.update({
|
|
88
|
+
classId: testClass.id,
|
|
89
|
+
eventId: testEvent.event.id,
|
|
90
|
+
attendance: {
|
|
91
|
+
present: [
|
|
92
|
+
{ id: student1.id, username: student1.username },
|
|
93
|
+
],
|
|
94
|
+
late: [
|
|
95
|
+
{ id: student2.id, username: student2.username },
|
|
96
|
+
],
|
|
97
|
+
absent: [],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(result).toBeDefined();
|
|
102
|
+
expect(result.id).toBeDefined();
|
|
103
|
+
expect(result.present).toBeDefined();
|
|
104
|
+
expect(result.late).toBeDefined();
|
|
105
|
+
expect(result.absent).toBeDefined();
|
|
106
|
+
expect(result.present.some((p: any) => p.id === student1.id)).toBe(true);
|
|
107
|
+
expect(result.late.some((l: any) => l.id === student2.id)).toBe(true);
|
|
108
|
+
|
|
109
|
+
// Verify attendance was updated
|
|
110
|
+
const attendance = await user1Caller.attendance.get({
|
|
111
|
+
classId: testClass.id,
|
|
112
|
+
eventId: testEvent.event.id,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const updatedRecord = attendance.find((a: any) => a.event?.id === testEvent.event.id);
|
|
116
|
+
expect(updatedRecord).toBeDefined();
|
|
117
|
+
expect(updatedRecord?.present.some((p: any) => p.id === student1.id)).toBe(true);
|
|
118
|
+
expect(updatedRecord?.late.some((l: any) => l.id === student2.id)).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should update attendance without event', async () => {
|
|
122
|
+
const result = await user1Caller.attendance.update({
|
|
123
|
+
classId: testClass.id,
|
|
124
|
+
attendance: {
|
|
125
|
+
present: [
|
|
126
|
+
{ id: student1.id, username: student1.username },
|
|
127
|
+
{ id: student2.id, username: student2.username },
|
|
128
|
+
],
|
|
129
|
+
late: [],
|
|
130
|
+
absent: [],
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(result).toBeDefined();
|
|
135
|
+
expect(result.id).toBeDefined();
|
|
136
|
+
expect(result.present.length).toBe(2);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('should fail for non-teacher', async () => {
|
|
140
|
+
await expect(user2Caller.attendance.update({
|
|
141
|
+
classId: testClass.id,
|
|
142
|
+
attendance: {
|
|
143
|
+
present: [{ id: student1.id, username: student1.username }],
|
|
144
|
+
late: [],
|
|
145
|
+
absent: [],
|
|
146
|
+
},
|
|
147
|
+
})).rejects.toThrow();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('should fail without authentication', async () => {
|
|
151
|
+
const invalidCaller = await createTRPCContext({
|
|
152
|
+
req: { headers: {} } as any,
|
|
153
|
+
res: {} as any,
|
|
154
|
+
});
|
|
155
|
+
const router = appRouter.createCaller(invalidCaller);
|
|
156
|
+
|
|
157
|
+
await expect(router.attendance.update({
|
|
158
|
+
classId: testClass.id,
|
|
159
|
+
attendance: {
|
|
160
|
+
present: [],
|
|
161
|
+
late: [],
|
|
162
|
+
absent: [],
|
|
163
|
+
},
|
|
164
|
+
})).rejects.toThrow();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
package/tests/auth.test.ts
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
import { test, expect } from 'vitest';
|
|
1
|
+
import { test, expect, describe } from 'vitest';
|
|
2
2
|
import { appRouter } from '../src/routers/_app';
|
|
3
3
|
import { createTRPCContext } from '../src/trpc';
|
|
4
4
|
import { prisma } from '../src/lib/prisma';
|
|
5
|
-
import { caller, login1, login2, session1, session2, user1Caller, verification1, verification2 } from './setup';
|
|
5
|
+
import { caller, login1, login2, login3, session1, session2, session3, user1Caller, user2Caller, user3Caller, verification1, verification2, verification3 } from './setup';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
describe('Auth Router', () => {
|
|
8
|
+
test('registration creates sessions', async () => {
|
|
8
9
|
expect(session1).toBeDefined();
|
|
10
|
+
expect(session1.id).toBeDefined();
|
|
9
11
|
expect(session2).toBeDefined();
|
|
10
|
-
|
|
12
|
+
expect(session2.id).toBeDefined();
|
|
13
|
+
});
|
|
11
14
|
|
|
12
|
-
test('email verification', async () => {
|
|
15
|
+
test('email verification works', async () => {
|
|
13
16
|
expect(verification1).toBeDefined();
|
|
14
17
|
expect(verification2).toBeDefined();
|
|
15
|
-
});
|
|
18
|
+
});
|
|
16
19
|
|
|
17
|
-
test('login', async () => {
|
|
20
|
+
test('login returns valid tokens', async () => {
|
|
18
21
|
expect(login1).toBeDefined();
|
|
22
|
+
expect(login1.token).toBeDefined();
|
|
23
|
+
expect(login1.user).toBeDefined();
|
|
19
24
|
expect(login2).toBeDefined();
|
|
20
|
-
|
|
25
|
+
expect(login2.token).toBeDefined();
|
|
26
|
+
expect(login2.user).toBeDefined();
|
|
27
|
+
});
|
|
21
28
|
|
|
22
|
-
test('logout', async () => {
|
|
23
|
-
|
|
29
|
+
test('logout invalidates session', async () => {
|
|
30
|
+
// Use user2Caller for logout test to avoid breaking user1Caller for other tests
|
|
31
|
+
const logout = await user3Caller.auth.logout();
|
|
24
32
|
expect(logout).toBeDefined();
|
|
33
|
+
expect(logout.success).toBe(true);
|
|
34
|
+
|
|
35
|
+
// Verify session is invalidated by trying to use it
|
|
36
|
+
const invalidCaller = await createTRPCContext({
|
|
37
|
+
req: { headers: {
|
|
38
|
+
authorization: `Bearer ${login3.token}`,
|
|
39
|
+
'x-user': login3.token,
|
|
40
|
+
} } as any,
|
|
41
|
+
res: {} as any,
|
|
42
|
+
});
|
|
43
|
+
const router = appRouter.createCaller(invalidCaller);
|
|
44
|
+
|
|
45
|
+
// Should fail because session was invalidated
|
|
46
|
+
await expect(router.user.getProfile()).rejects.toThrow();
|
|
47
|
+
});
|
|
25
48
|
});
|
package/tests/class.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test, expect, describe, beforeEach } from 'vitest';
|
|
1
|
+
import { test, expect, describe, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { appRouter } from '../src/routers/_app';
|
|
3
3
|
import { createTRPCContext } from '../src/trpc';
|
|
4
4
|
import { prisma } from '../src/lib/prisma';
|
|
@@ -7,26 +7,33 @@ import { caller, user1Caller, user2Caller } from './setup';
|
|
|
7
7
|
describe('Class Router', () => {
|
|
8
8
|
let testClass: any;
|
|
9
9
|
let testClass2: any;
|
|
10
|
+
const createdClassIds: string[] = [];
|
|
10
11
|
|
|
11
12
|
beforeEach(async () => {
|
|
12
|
-
// Create test classes for each test
|
|
13
|
+
// Create test classes for each test with unique names to avoid conflicts
|
|
14
|
+
const timestamp = Date.now();
|
|
13
15
|
testClass = await user1Caller.class.create({
|
|
14
|
-
name:
|
|
16
|
+
name: `Test Class 1`,
|
|
15
17
|
subject: 'Mathematics',
|
|
16
18
|
section: '10th Grade',
|
|
17
19
|
});
|
|
18
20
|
|
|
19
21
|
testClass2 = await user2Caller.class.create({
|
|
20
|
-
name:
|
|
22
|
+
name: `Test Class 2`,
|
|
21
23
|
subject: 'Science',
|
|
22
24
|
section: '11th Grade',
|
|
23
25
|
});
|
|
26
|
+
|
|
27
|
+
// Track created classes for cleanup
|
|
28
|
+
if (testClass?.id) createdClassIds.push(testClass.id);
|
|
29
|
+
if (testClass2?.id) createdClassIds.push(testClass2.id);
|
|
24
30
|
});
|
|
25
31
|
|
|
26
32
|
describe('create', () => {
|
|
27
33
|
test('should create a class successfully', async () => {
|
|
28
34
|
expect(testClass).toBeDefined();
|
|
29
|
-
expect(testClass.
|
|
35
|
+
expect(testClass.id).toBeDefined();
|
|
36
|
+
expect(testClass.name).toContain('Test Class 1');
|
|
30
37
|
expect(testClass.subject).toBe('Mathematics');
|
|
31
38
|
expect(testClass.section).toBe('10th Grade');
|
|
32
39
|
});
|
|
@@ -52,10 +59,11 @@ describe('Class Router', () => {
|
|
|
52
59
|
});
|
|
53
60
|
|
|
54
61
|
test('should fail to create class with missing required fields', async () => {
|
|
62
|
+
|
|
63
|
+
// @ts-expect-error - test case
|
|
55
64
|
await expect(user1Caller.class.create({
|
|
56
65
|
name: '',
|
|
57
|
-
|
|
58
|
-
section: '10th Grade',
|
|
66
|
+
color: '#3B82F6',
|
|
59
67
|
})).rejects.toThrow();
|
|
60
68
|
});
|
|
61
69
|
});
|
|
@@ -72,8 +80,9 @@ describe('Class Router', () => {
|
|
|
72
80
|
|
|
73
81
|
test('should include user\'s own classes as teacher', async () => {
|
|
74
82
|
const classes = await user1Caller.class.getAll();
|
|
75
|
-
const userClass = classes.teacherInClass.find((c: any) => c.
|
|
83
|
+
const userClass = classes.teacherInClass.find((c: any) => c.id === testClass.id);
|
|
76
84
|
expect(userClass).toBeDefined();
|
|
85
|
+
expect(userClass?.id).toBe(testClass.id);
|
|
77
86
|
});
|
|
78
87
|
|
|
79
88
|
test('should fail to get classes without authentication', async () => {
|
|
@@ -152,6 +161,12 @@ describe('Class Router', () => {
|
|
|
152
161
|
expect(result).toBeDefined();
|
|
153
162
|
expect(result.deletedClass).toBeDefined();
|
|
154
163
|
expect(result.deletedClass.id).toBe(testClass.id);
|
|
164
|
+
|
|
165
|
+
// Remove from cleanup list since it's already deleted
|
|
166
|
+
const index = createdClassIds.indexOf(testClass.id);
|
|
167
|
+
if (index > -1) {
|
|
168
|
+
createdClassIds.splice(index, 1);
|
|
169
|
+
}
|
|
155
170
|
});
|
|
156
171
|
|
|
157
172
|
test('should fail to delete class user is not teacher of', async () => {
|
|
@@ -212,10 +227,12 @@ describe('Class Router', () => {
|
|
|
212
227
|
test('should remove member successfully', async () => {
|
|
213
228
|
// First add a student
|
|
214
229
|
const user2Profile = await user2Caller.user.getProfile();
|
|
215
|
-
await user1Caller.class.addStudent({
|
|
230
|
+
const addResult = await user1Caller.class.addStudent({
|
|
216
231
|
classId: testClass.id,
|
|
217
232
|
studentId: user2Profile.id,
|
|
218
233
|
});
|
|
234
|
+
expect(addResult).toBeDefined();
|
|
235
|
+
expect(addResult.newStudent).toBeDefined();
|
|
219
236
|
|
|
220
237
|
// Then remove them
|
|
221
238
|
const result = await user1Caller.class.removeMember({
|
|
@@ -240,12 +257,20 @@ describe('Class Router', () => {
|
|
|
240
257
|
test('should join class with class code successfully', async () => {
|
|
241
258
|
// First create an invite code
|
|
242
259
|
const inviteCode = await user1Caller.class.createInviteCode({ classId: testClass.id });
|
|
260
|
+
expect(inviteCode).toBeDefined();
|
|
261
|
+
expect(inviteCode.code).toBeDefined();
|
|
243
262
|
|
|
244
263
|
// Then join with the code
|
|
245
264
|
const result = await user2Caller.class.join({ classCode: inviteCode.code });
|
|
246
265
|
expect(result).toBeDefined();
|
|
247
266
|
expect(result.joinedClass).toBeDefined();
|
|
248
267
|
expect(result.joinedClass.id).toBe(testClass.id);
|
|
268
|
+
|
|
269
|
+
// Clean up: remove student from class
|
|
270
|
+
await user1Caller.class.removeMember({
|
|
271
|
+
classId: testClass.id,
|
|
272
|
+
userId: (await user2Caller.user.getProfile()).id,
|
|
273
|
+
});
|
|
249
274
|
});
|
|
250
275
|
|
|
251
276
|
test('should fail to join with invalid class code', async () => {
|