|
1 | 1 | import CollaboraPage from "./Collabora.page.vue"; |
2 | 2 | import * as serverApi from "@/serverApi/v3/api"; |
| 3 | +import { HttpStatusCode } from "@/store/types/http-status-code.enum"; |
3 | 4 | import { EditorMode } from "@/types/file/File"; |
4 | 5 | import { buildPageTitle } from "@/utils/pageTitle"; |
5 | 6 | import { |
6 | 7 | authorizedCollaboraDocumentUrlResponseFactory, |
| 8 | + axiosErrorFactory, |
7 | 9 | createTestAppStoreWithUser, |
8 | 10 | expectNotification, |
9 | 11 | fileElementResponseFactory, |
@@ -415,6 +417,96 @@ describe("Collabora.page", () => { |
415 | 417 | }); |
416 | 418 | }); |
417 | 419 |
|
| 420 | + describe("when getAuthorizedCollaboraDocumentUrl rejects with 403 Forbidden", () => { |
| 421 | + const setup = () => { |
| 422 | + const editorMode = EditorMode.EDIT; |
| 423 | + |
| 424 | + createTestAppStoreWithUser("user-id"); |
| 425 | + |
| 426 | + const fileStorageApiMock = createMock<ReturnType<typeof FileStorageApi.useFileStorageApi>>(); |
| 427 | + vi.spyOn(FileStorageApi, "useFileStorageApi").mockReturnValueOnce(fileStorageApiMock); |
| 428 | + const axiosError = axiosErrorFactory.withStatusCode(HttpStatusCode.Forbidden).build(); |
| 429 | + fileStorageApiMock.getAuthorizedCollaboraDocumentUrl.mockRejectedValueOnce(axiosError); |
| 430 | + |
| 431 | + const fileRecord = fileRecordFactory.build(); |
| 432 | + fileStorageApiMock.getFileRecordById.mockReturnValueOnce(fileRecord); |
| 433 | + |
| 434 | + const boardApi = createMock<serverApi.BoardElementApiInterface>(); |
| 435 | + vi.spyOn(serverApi, "BoardElementApiFactory").mockReturnValueOnce(boardApi); |
| 436 | + |
| 437 | + const expectedTitle = "standalone-file.pdf - Instance Title"; |
| 438 | + mockBuildPageTitle.mockReturnValueOnce(expectedTitle); |
| 439 | + |
| 440 | + mount(CollaboraPage, { |
| 441 | + global: { |
| 442 | + plugins: [createTestingVuetify(), createTestingI18n()], |
| 443 | + }, |
| 444 | + propsData: { |
| 445 | + fileRecordId: fileRecord.id, |
| 446 | + editorMode, |
| 447 | + }, |
| 448 | + }); |
| 449 | + |
| 450 | + return { |
| 451 | + fileRecord, |
| 452 | + expectedTitle, |
| 453 | + }; |
| 454 | + }; |
| 455 | + |
| 456 | + it("should call handleApplicationError with correct parameters", async () => { |
| 457 | + setup(); |
| 458 | + |
| 459 | + await flushPromises(); |
| 460 | + |
| 461 | + expect(useAppStore().handleApplicationError).toHaveBeenCalledWith(HttpStatusCode.Forbidden); |
| 462 | + }); |
| 463 | + }); |
| 464 | + |
| 465 | + describe("when getAuthorizedCollaboraDocumentUrl rejects with other error", () => { |
| 466 | + const setup = () => { |
| 467 | + const editorMode = EditorMode.EDIT; |
| 468 | + |
| 469 | + createTestAppStoreWithUser("user-id"); |
| 470 | + |
| 471 | + const fileStorageApiMock = createMock<ReturnType<typeof FileStorageApi.useFileStorageApi>>(); |
| 472 | + vi.spyOn(FileStorageApi, "useFileStorageApi").mockReturnValueOnce(fileStorageApiMock); |
| 473 | + const axiosError = axiosErrorFactory.withStatusCode(HttpStatusCode.InternalServerError).build(); |
| 474 | + fileStorageApiMock.getAuthorizedCollaboraDocumentUrl.mockRejectedValueOnce(axiosError); |
| 475 | + |
| 476 | + const fileRecord = fileRecordFactory.build(); |
| 477 | + fileStorageApiMock.getFileRecordById.mockReturnValueOnce(fileRecord); |
| 478 | + |
| 479 | + const boardApi = createMock<serverApi.BoardElementApiInterface>(); |
| 480 | + vi.spyOn(serverApi, "BoardElementApiFactory").mockReturnValueOnce(boardApi); |
| 481 | + |
| 482 | + const expectedTitle = "standalone-file.pdf - Instance Title"; |
| 483 | + mockBuildPageTitle.mockReturnValueOnce(expectedTitle); |
| 484 | + |
| 485 | + mount(CollaboraPage, { |
| 486 | + global: { |
| 487 | + plugins: [createTestingVuetify(), createTestingI18n()], |
| 488 | + }, |
| 489 | + propsData: { |
| 490 | + fileRecordId: fileRecord.id, |
| 491 | + editorMode, |
| 492 | + }, |
| 493 | + }); |
| 494 | + |
| 495 | + return { |
| 496 | + fileRecord, |
| 497 | + expectedTitle, |
| 498 | + }; |
| 499 | + }; |
| 500 | + |
| 501 | + it("should call handleApplicationError with correct parameters", async () => { |
| 502 | + setup(); |
| 503 | + |
| 504 | + await flushPromises(); |
| 505 | + |
| 506 | + expect(useAppStore().handleApplicationError).toHaveBeenCalledWith(HttpStatusCode.InternalServerError); |
| 507 | + }); |
| 508 | + }); |
| 509 | + |
418 | 510 | describe("when getElementWithParentHierarchy rejects", () => { |
419 | 511 | const setup = () => { |
420 | 512 | const editorMode = EditorMode.EDIT; |
|
0 commit comments