|
6 | 6 | import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' |
7 | 7 | import type { MockedFunction } from 'vitest' |
8 | 8 | import { setActivePinia, createPinia } from 'pinia' |
9 | | -import { mount } from '@vue/test-utils' |
| 9 | +import { flushPromises, mount } from '@vue/test-utils' |
10 | 10 | import { useSignMethodsStore } from '../../../store/signMethods.js' |
11 | 11 | import type { useSignStore } from '../../../store/sign.js' |
| 12 | +import { FILE_STATUS, SIGN_REQUEST_STATUS } from '../../../constants.js' |
12 | 13 |
|
13 | 14 | type TokenMethodKey = 'smsToken' | 'whatsappToken' | 'signalToken' | 'telegramToken' | 'xmppToken' |
14 | 15 |
|
@@ -509,6 +510,106 @@ describe('Sign.vue - signWithTokenCode', () => { |
509 | 510 | expect(context.signStore.setSigningErrors).toHaveBeenCalledWith(apiErrors) |
510 | 511 | expect(context.loading).toBe(false) |
511 | 512 | }) |
| 513 | + |
| 514 | + it('closes password modal when signing fails with non-retriable certificate error', async () => { |
| 515 | + const apiErrors = [{ message: 'Certificate revocation status could not be verified', code: 422 }] |
| 516 | + const context = { |
| 517 | + loading: false, |
| 518 | + elements: [], |
| 519 | + canCreateSignature: false, |
| 520 | + signRequestUuid: 'test-sign-request-uuid', |
| 521 | + signMethodsStore: { |
| 522 | + certificateEngine: 'openssl', |
| 523 | + }, |
| 524 | + signatureElementsStore: { |
| 525 | + signs: {}, |
| 526 | + }, |
| 527 | + actionHandler: { |
| 528 | + showModal: vi.fn(), |
| 529 | + closeModal: vi.fn(), |
| 530 | + }, |
| 531 | + signStore: { |
| 532 | + document: { id: 10 }, |
| 533 | + clearSigningErrors: vi.fn(), |
| 534 | + setSigningErrors: vi.fn(), |
| 535 | + submitSignature: vi.fn().mockRejectedValue({ |
| 536 | + type: 'signError', |
| 537 | + errors: apiErrors, |
| 538 | + }), |
| 539 | + }, |
| 540 | + $emit: vi.fn(), |
| 541 | + sidebarStore: { |
| 542 | + hideSidebar: vi.fn(), |
| 543 | + }, |
| 544 | + } |
| 545 | + |
| 546 | + await submitSignatureCompatMethod.call(context, { |
| 547 | + method: 'password', |
| 548 | + token: '123456', |
| 549 | + }) |
| 550 | + |
| 551 | + expect(context.actionHandler.closeModal).toHaveBeenCalledWith('password') |
| 552 | + expect(context.signStore.setSigningErrors).toHaveBeenCalledWith(apiErrors) |
| 553 | + expect(context.loading).toBe(false) |
| 554 | + }) |
| 555 | + |
| 556 | + it('blocks sign CTA and shows explicit retry action when non-retriable error exists', async () => { |
| 557 | + setActivePinia(createPinia()) |
| 558 | + |
| 559 | + const SignComponent = await import('../../../views/SignPDF/_partials/Sign.vue') |
| 560 | + const realSign = SignComponent.default |
| 561 | + const { useSignStore } = await import('../../../store/sign.js') |
| 562 | + |
| 563 | + const mountedSignStore = useSignStore() |
| 564 | + mountedSignStore.document = createSignDocument({ |
| 565 | + status: FILE_STATUS.ABLE_TO_SIGN, |
| 566 | + signers: [{ me: true, status: SIGN_REQUEST_STATUS.ABLE_TO_SIGN, signRequestId: 501 }], |
| 567 | + visibleElements: [], |
| 568 | + }) |
| 569 | + mountedSignStore.setSigningErrors([ |
| 570 | + { message: 'Certificate validation failed', code: 422 }, |
| 571 | + ]) |
| 572 | + |
| 573 | + const wrapper = mount(realSign, { |
| 574 | + global: { |
| 575 | + stubs: { |
| 576 | + NcButton: { |
| 577 | + template: '<button><slot /></button>', |
| 578 | + }, |
| 579 | + NcDialog: true, |
| 580 | + NcLoadingIcon: true, |
| 581 | + TokenManager: true, |
| 582 | + EmailManager: true, |
| 583 | + UploadCertificate: true, |
| 584 | + Documents: true, |
| 585 | + Signatures: true, |
| 586 | + Draw: true, |
| 587 | + ManagePassword: true, |
| 588 | + CreatePassword: true, |
| 589 | + NcNoteCard: { |
| 590 | + template: '<div class="nc-note-card-stub"><slot /></div>', |
| 591 | + }, |
| 592 | + NcPasswordField: true, |
| 593 | + NcRichText: { |
| 594 | + props: ['text'], |
| 595 | + template: '<span>{{ text }}</span>', |
| 596 | + }, |
| 597 | + }, |
| 598 | + mocks: { |
| 599 | + $watch: vi.fn(), |
| 600 | + $nextTick: vi.fn(), |
| 601 | + }, |
| 602 | + }, |
| 603 | + }) |
| 604 | + |
| 605 | + await wrapper.vm.$nextTick() |
| 606 | + await wrapper.vm.$nextTick() |
| 607 | + await flushPromises() |
| 608 | + |
| 609 | + expect(wrapper.text()).toContain('Try signing again') |
| 610 | + expect(wrapper.text()).not.toContain('Sign the document.') |
| 611 | + expect(wrapper.findAll('.nc-note-card-stub')).toHaveLength(1) |
| 612 | + }) |
512 | 613 | }) |
513 | 614 |
|
514 | 615 | describe('proceedWithSigning - Full flow with WhatsApp token', () => { |
|
0 commit comments