Skip to content

Commit a64c05c

Browse files
committed
test(validation): cover files store sync on validation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> (cherry picked from commit a20e4bd) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 207fb48 commit a64c05c

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

src/tests/views/Validation.spec.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ vi.mock('../../store/sidebar.js', () => ({
158158
})),
159159
}))
160160

161+
vi.mock('../../store/files.js', () => {
162+
const filesStore = {
163+
files: {},
164+
addFile: vi.fn(),
165+
getFileIdByUuid: vi.fn(() => null),
166+
getFileIdByNodeId: vi.fn(() => null),
167+
}
168+
return {
169+
useFilesStore: vi.fn(() => filesStore),
170+
}
171+
})
172+
161173
// Mock utils
162174
vi.mock('../../utils/viewer.js', () => ({
163175
openDocument: vi.fn(),
@@ -177,10 +189,16 @@ describe('Validation.vue - Business Logic', () => {
177189
await wrapper.vm.$nextTick()
178190
}
179191

180-
beforeEach(() => {
192+
beforeEach(async () => {
193+
vi.clearAllMocks()
181194
history.replaceState({}, '')
182195
mockAddConfetti = vi.fn()
183196
vi.mocked(axios.get).mockResolvedValue({ data: { ocs: { data: {} } } })
197+
const { useFilesStore } = await import('../../store/files.js')
198+
const filesStore = useFilesStore()
199+
filesStore.files = {}
200+
vi.mocked(filesStore.getFileIdByUuid).mockReturnValue(null)
201+
vi.mocked(filesStore.getFileIdByNodeId).mockReturnValue(null)
184202
// Must use `function` syntax so vitest accepts it as a valid constructor mock
185203
vi.mocked(JSConfetti).mockImplementation(function() {
186204
return { addConfetti: mockAddConfetti }
@@ -728,6 +746,63 @@ describe('Validation.vue - Business Logic', () => {
728746
wrapper.vm.handleValidationSuccess(createLoadedValidationDocument({ status: SIGNED_STATUS }))
729747
expect(mockAddConfetti).not.toHaveBeenCalled()
730748
})
749+
750+
it('syncs a tracked signed document into files store', async () => {
751+
const { useFilesStore } = await import('../../store/files.js')
752+
const filesStore = useFilesStore()
753+
vi.mocked(filesStore.getFileIdByUuid).mockReturnValue(100)
754+
755+
wrapper.vm.handleValidationSuccess(createLoadedValidationDocument({ status: SIGNED_STATUS }))
756+
757+
expect(filesStore.addFile).toHaveBeenCalledWith(expect.objectContaining({
758+
id: 100,
759+
uuid: '550e8400-e29b-41d4-a716-446655440000',
760+
status: SIGNED_STATUS,
761+
}), { detailsLoaded: true })
762+
})
763+
764+
it('syncs tracked envelope children when all files are signed', async () => {
765+
const { useFilesStore } = await import('../../store/files.js')
766+
const filesStore = useFilesStore()
767+
vi.mocked(filesStore.getFileIdByUuid).mockImplementation((uuid: string) => {
768+
if (uuid === '550e8400-e29b-41d4-a716-446655440000') {
769+
return 100
770+
}
771+
return null
772+
})
773+
vi.mocked(filesStore.getFileIdByNodeId).mockImplementation((nodeId: number) => {
774+
if (nodeId === 201) {
775+
return 201
776+
}
777+
if (nodeId === 202) {
778+
return 202
779+
}
780+
return null
781+
})
782+
783+
wrapper.vm.handleValidationSuccess(createLoadedValidationDocument({
784+
nodeType: 'envelope',
785+
status: 0,
786+
files: [
787+
{ id: 201, uuid: 'child-1', nodeId: 201, name: 'child-1.pdf', status: SIGNED_STATUS },
788+
{ id: 202, uuid: 'child-2', nodeId: 202, name: 'child-2.pdf', status: SIGNED_STATUS },
789+
],
790+
}))
791+
792+
expect(filesStore.addFile).toHaveBeenCalledTimes(3)
793+
expect(filesStore.addFile).toHaveBeenNthCalledWith(1, expect.objectContaining({ id: 100 }), { detailsLoaded: true })
794+
expect(filesStore.addFile).toHaveBeenNthCalledWith(2, expect.objectContaining({ id: 201, status: SIGNED_STATUS }), { detailsLoaded: true })
795+
expect(filesStore.addFile).toHaveBeenNthCalledWith(3, expect.objectContaining({ id: 202, status: SIGNED_STATUS }), { detailsLoaded: true })
796+
})
797+
798+
it('does not sync untracked documents into files store', async () => {
799+
const { useFilesStore } = await import('../../store/files.js')
800+
const filesStore = useFilesStore()
801+
802+
wrapper.vm.handleValidationSuccess(createLoadedValidationDocument({ status: SIGNED_STATUS }))
803+
804+
expect(filesStore.addFile).not.toHaveBeenCalled()
805+
})
731806
})
732807

733808
describe('handleSigningComplete method', () => {

0 commit comments

Comments
 (0)