|
1 | 1 | import { MemberRole } from '@domain/entities/team.js'; |
2 | 2 | import { describe, test, expect, beforeEach } from 'vitest'; |
3 | 3 | import type User from '@domain/entities/user.js'; |
| 4 | +import type { Note } from '@domain/entities/note.js'; |
4 | 5 |
|
5 | 6 | describe('Note API', () => { |
6 | 7 | /** |
@@ -2272,4 +2273,97 @@ describe('Note API', () => { |
2272 | 2273 | expect(response?.json().message).toBe('Note not found'); |
2273 | 2274 | }); |
2274 | 2275 | }); |
| 2276 | + |
| 2277 | + describe('GET /note/note-hierarchy/:noteId', () => { |
| 2278 | + let accessToken = ''; |
| 2279 | + let user: User; |
| 2280 | + |
| 2281 | + beforeEach(async () => { |
| 2282 | + /** create test user */ |
| 2283 | + user = await global.db.insertUser(); |
| 2284 | + |
| 2285 | + accessToken = global.auth(user.id); |
| 2286 | + }); |
| 2287 | + |
| 2288 | + test.each([ |
| 2289 | + // Test case 1: No parent or child |
| 2290 | + { |
| 2291 | + description: 'Should get note hierarchy with no parent or child when noteId passed has no relations', |
| 2292 | + setup: async () => { |
| 2293 | + const note = await global.db.insertNote({ creatorId: user.id }); |
| 2294 | + |
| 2295 | + await global.db.insertNoteSetting({ |
| 2296 | + noteId: note.id, |
| 2297 | + isPublic: true, |
| 2298 | + }); |
| 2299 | + |
| 2300 | + return { |
| 2301 | + note: note, |
| 2302 | + childNote: null, |
| 2303 | + }; |
| 2304 | + }, |
| 2305 | + |
| 2306 | + expected: (note: Note, childNote: Note | null) => ({ |
| 2307 | + id: note.publicId, |
| 2308 | + content: note.content, |
| 2309 | + childNotes: childNote, |
| 2310 | + }), |
| 2311 | + }, |
| 2312 | + |
| 2313 | + // Test case 2: With child |
| 2314 | + { |
| 2315 | + description: 'Should get note hierarchy with child when noteId passed has relations', |
| 2316 | + setup: async () => { |
| 2317 | + const childNote = await global.db.insertNote({ creatorId: user.id }); |
| 2318 | + const parentNote = await global.db.insertNote({ creatorId: user.id }); |
| 2319 | + |
| 2320 | + await global.db.insertNoteSetting({ |
| 2321 | + noteId: childNote.id, |
| 2322 | + isPublic: true, |
| 2323 | + }); |
| 2324 | + await global.db.insertNoteSetting({ |
| 2325 | + noteId: parentNote.id, |
| 2326 | + isPublic: true, |
| 2327 | + }); |
| 2328 | + await global.db.insertNoteRelation({ |
| 2329 | + noteId: childNote.id, |
| 2330 | + parentId: parentNote.id, |
| 2331 | + }); |
| 2332 | + |
| 2333 | + return { |
| 2334 | + note: parentNote, |
| 2335 | + childNote: childNote, |
| 2336 | + }; |
| 2337 | + }, |
| 2338 | + expected: (note: Note, childNote: Note | null) => ({ |
| 2339 | + id: note.publicId, |
| 2340 | + content: note.content, |
| 2341 | + childNotes: [ |
| 2342 | + { |
| 2343 | + id: childNote?.publicId, |
| 2344 | + content: childNote?.content, |
| 2345 | + childNotes: null, |
| 2346 | + }, |
| 2347 | + ], |
| 2348 | + }), |
| 2349 | + }, |
| 2350 | + ])('$description', async ({ setup, expected }) => { |
| 2351 | + // Setup the test data |
| 2352 | + const { note, childNote } = await setup(); |
| 2353 | + |
| 2354 | + // Make the API request |
| 2355 | + const response = await global.api?.fakeRequest({ |
| 2356 | + method: 'GET', |
| 2357 | + headers: { |
| 2358 | + authorization: `Bearer ${accessToken}`, |
| 2359 | + }, |
| 2360 | + url: `/note/note-hierarchy/${note.publicId}`, |
| 2361 | + }); |
| 2362 | + |
| 2363 | + // Verify the response |
| 2364 | + expect(response?.json().noteHierarchy).toStrictEqual( |
| 2365 | + expected(note, childNote) |
| 2366 | + ); |
| 2367 | + }); |
| 2368 | + }); |
2275 | 2369 | }); |
0 commit comments