|
| 1 | +/*eslint-disable jest/max-expects */ |
1 | 2 | // SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital |
2 | 3 | // SPDX-License-Identifier: Apache-2.0 |
3 | 4 |
|
@@ -504,56 +505,91 @@ describe("confluence-sync-pages library", () => { |
504 | 505 | describe("when a page has been renamed", () => { |
505 | 506 | let requests: SpyRequest[]; |
506 | 507 | let getPageRequests: SpyRequest[]; |
| 508 | + let getPageChildrenRequests: SpyRequest[]; |
507 | 509 |
|
508 | 510 | beforeAll(async () => { |
509 | 511 | await changeMockCollection("renamed-page"); |
510 | 512 | await confluenceSyncPages.sync(renamedPage); |
511 | 513 |
|
512 | 514 | requests = await getRequests(); |
513 | 515 | getPageRequests = await getRequestsByRouteId("confluence-get-page"); |
| 516 | + getPageChildrenRequests = await getRequestsByRouteId( |
| 517 | + "confluence-get-page-children", |
| 518 | + ); |
514 | 519 | createRequests = await getRequestsByRouteId("confluence-create-page"); |
515 | 520 | deleteRequests = await getRequestsByRouteId("confluence-delete-page"); |
516 | 521 | }); |
517 | 522 |
|
518 | 523 | it("should execute delete requests before create requests", async () => { |
519 | | - // First request is the one to get the root page |
520 | | - expect(requests[0].routeId).toBe("confluence-get-page"); |
521 | | - expect(getPageRequests[0].params?.pageId).toBe("foo-root-id"); |
522 | | - // Second request is the one to get the parent page, child of the root page |
| 524 | + // Request to get the root page children |
| 525 | + expect(requests[0].routeId).toBe("confluence-get-page-children"); |
| 526 | + expect(getPageChildrenRequests[0].params?.pageId).toBe("foo-root-id"); |
| 527 | + // Request to get the root page |
523 | 528 | expect(requests[1].routeId).toBe("confluence-get-page"); |
| 529 | + expect(getPageRequests[0].params?.pageId).toBe("foo-root-id"); |
| 530 | + |
| 531 | + // Request to get the root page children |
| 532 | + expect(requests[2].routeId).toBe("confluence-get-page-children"); |
| 533 | + expect(getPageChildrenRequests[1].params?.pageId).toBe( |
| 534 | + "foo-parent-id", |
| 535 | + ); |
| 536 | + // Request to get the parent page, child of the root page |
| 537 | + expect(requests[3].routeId).toBe("confluence-get-page"); |
524 | 538 | expect(getPageRequests[1].params?.pageId).toBe("foo-parent-id"); |
525 | | - // Third request has to be the one to delete the parent page |
526 | | - expect(requests[2].routeId).toBe("confluence-delete-page"); |
| 539 | + |
| 540 | + // Request to delete the parent page |
| 541 | + expect(requests[4].routeId).toBe("confluence-delete-page"); |
527 | 542 | expect(deleteRequests[0].params?.pageId).toBe("foo-parent-id"); |
528 | | - // Fourth request has to be the one to create the renamed page because is child of the root page |
529 | | - expect(requests[3].routeId).toBe("confluence-create-page"); |
| 543 | + // Request to create the renamed page because is child of the root page |
| 544 | + expect(requests[5].routeId).toBe("confluence-create-page"); |
530 | 545 | expect(createRequests[0].body?.title).toBe("foo-renamed-title"); |
531 | | - // Fifth request has to be the one to get the child1 page which is child of the parent page |
532 | | - expect(requests[4].routeId).toBe("confluence-get-page"); |
| 546 | + |
| 547 | + // Request to get the child1 page which is child of the parent page |
| 548 | + expect(requests[6].routeId).toBe("confluence-get-page-children"); |
| 549 | + expect(getPageChildrenRequests[2].params?.pageId).toBe( |
| 550 | + "foo-child1-id", |
| 551 | + ); |
| 552 | + // Request to get the child1 page which is child of the parent page |
| 553 | + expect(requests[7].routeId).toBe("confluence-get-page"); |
533 | 554 | expect(getPageRequests[2].params?.pageId).toBe("foo-child1-id"); |
534 | | - // Sixth request has to be the one to delete the child1 page |
535 | | - expect(requests[5].routeId).toBe("confluence-delete-page"); |
| 555 | + |
| 556 | + // Request to delete the child1 page |
| 557 | + expect(requests[8].routeId).toBe("confluence-delete-page"); |
536 | 558 | expect(deleteRequests[1].params?.pageId).toBe("foo-child1-id"); |
537 | | - // Seventh request has to be the one to create the child1 page because is child of the renamed page |
538 | | - expect(requests[6].routeId).toBe("confluence-create-page"); |
| 559 | + // Request to create the child1 page because is child of the renamed page |
| 560 | + expect(requests[9].routeId).toBe("confluence-create-page"); |
539 | 561 | expect(createRequests[1].body?.title).toBe("foo-child1-title"); |
540 | | - // Eighth request has to be the one to get the grandChild1 page which is child of the child1 page child of parent page |
541 | | - expect(requests[7].routeId).toBe("confluence-get-page"); |
| 562 | + |
| 563 | + // Request to get the grandChild1 page which is child of the child1 page child of parent page |
| 564 | + expect(requests[10].routeId).toBe("confluence-get-page-children"); |
| 565 | + expect(getPageChildrenRequests[3].params?.pageId).toBe( |
| 566 | + "foo-grandChild1-id", |
| 567 | + ); |
| 568 | + // Request to get the grandChild1 page which is child of the child1 page child of parent page |
| 569 | + expect(requests[11].routeId).toBe("confluence-get-page"); |
542 | 570 | expect(getPageRequests[3].params?.pageId).toBe("foo-grandChild1-id"); |
543 | | - // Ninth request has to be the one to delete the grandChild1 page |
544 | | - expect(requests[8].routeId).toBe("confluence-delete-page"); |
| 571 | + |
| 572 | + // Request to delete the grandChild1 page |
| 573 | + expect(requests[12].routeId).toBe("confluence-delete-page"); |
545 | 574 | expect(deleteRequests[2].params?.pageId).toBe("foo-grandChild1-id"); |
546 | | - // Tenth request has to be the one to get the grandChild2 page because is child of the child1 page child of parent page |
547 | | - expect(requests[9].routeId).toBe("confluence-get-page"); |
| 575 | + |
| 576 | + // Request to get the grandChild2 page children because is child of the child1 page child of parent page |
| 577 | + expect(requests[13].routeId).toBe("confluence-get-page-children"); |
| 578 | + expect(getPageChildrenRequests[4].params?.pageId).toBe( |
| 579 | + "foo-grandChild2-id", |
| 580 | + ); |
| 581 | + // Request to get the grandChild2 page because is child of the child1 page child of parent page |
| 582 | + expect(requests[14].routeId).toBe("confluence-get-page"); |
548 | 583 | expect(getPageRequests[4].params?.pageId).toBe("foo-grandChild2-id"); |
549 | | - // Eleventh request has to be the one to delete the grandChild2 page |
550 | | - expect(requests[10].routeId).toBe("confluence-delete-page"); |
| 584 | + |
| 585 | + // Request to delete the grandChild2 page |
| 586 | + expect(requests[15].routeId).toBe("confluence-delete-page"); |
551 | 587 | expect(deleteRequests[3].params?.pageId).toBe("foo-grandChild2-id"); |
552 | | - // Twelfth request has to be the one to create the grandChild1 page because is child of the child1 page child of the renamed page |
553 | | - expect(requests[11].routeId).toBe("confluence-create-page"); |
| 588 | + // Request to create the grandChild1 page because is child of the child1 page child of the renamed page |
| 589 | + expect(requests[16].routeId).toBe("confluence-create-page"); |
554 | 590 | expect(createRequests[2].body?.title).toBe("foo-grandChild1-title"); |
555 | | - // Thirteenth request has to be the one to create the grandChild2 page because is child of the child1 page child of the renamed page |
556 | | - expect(requests[12].routeId).toBe("confluence-create-page"); |
| 591 | + // Request to create the grandChild2 page because is child of the child1 page child of the renamed page |
| 592 | + expect(requests[17].routeId).toBe("confluence-create-page"); |
557 | 593 | expect(createRequests[3].body?.title).toBe("foo-grandChild2-title"); |
558 | 594 | }); |
559 | 595 |
|
|
0 commit comments