Skip to content

Commit c614c6c

Browse files
test: add tests for ableToSign getter
Adds comprehensive test coverage for the ableToSign getter including: - Document status validation - Signer presence validation - Signer status validation - Edge cases (undefined document, empty signers array) Signed-off-by: Vitor Mattos <[email protected]>
1 parent a9f750c commit c614c6c

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

src/store/sign.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { describe, expect, it, beforeEach } from 'vitest'
77
import { setActivePinia, createPinia } from 'pinia'
88
import { useSignStore } from './sign.js'
9+
import { FILE_STATUS } from '../constants.js'
910

1011
describe('useSignStore', () => {
1112
beforeEach(() => {
@@ -44,4 +45,66 @@ describe('useSignStore', () => {
4445
expect(store.pendingAction).toBe('createPassword')
4546
})
4647
})
48+
49+
describe('ableToSign getter', () => {
50+
it('returns false when document status is not ABLE_TO_SIGN or PARTIAL_SIGNED', () => {
51+
const store = useSignStore()
52+
store.document = {
53+
status: FILE_STATUS.DRAFT,
54+
signers: [{ me: true, status: 1 }],
55+
}
56+
expect(store.ableToSign).toBe(false)
57+
})
58+
59+
it('returns false when there is no signer with me: true', () => {
60+
const store = useSignStore()
61+
store.document = {
62+
status: FILE_STATUS.ABLE_TO_SIGN,
63+
signers: [{ me: false, status: 1 }],
64+
}
65+
expect(store.ableToSign).toBe(false)
66+
})
67+
68+
it('returns false when signer status is not ABLE_TO_SIGN (status 1)', () => {
69+
const store = useSignStore()
70+
store.document = {
71+
status: FILE_STATUS.ABLE_TO_SIGN,
72+
signers: [{ me: true, status: 0 }],
73+
}
74+
expect(store.ableToSign).toBe(false)
75+
})
76+
77+
it('returns true when document status is ABLE_TO_SIGN and signer can sign', () => {
78+
const store = useSignStore()
79+
store.document = {
80+
status: FILE_STATUS.ABLE_TO_SIGN,
81+
signers: [{ me: true, status: 1 }],
82+
}
83+
expect(store.ableToSign).toBe(true)
84+
})
85+
86+
it('returns true when document status is PARTIAL_SIGNED and signer can sign', () => {
87+
const store = useSignStore()
88+
store.document = {
89+
status: FILE_STATUS.PARTIAL_SIGNED,
90+
signers: [{ me: true, status: 1 }],
91+
}
92+
expect(store.ableToSign).toBe(true)
93+
})
94+
95+
it('returns false when document is undefined', () => {
96+
const store = useSignStore()
97+
store.document = undefined
98+
expect(store.ableToSign).toBe(false)
99+
})
100+
101+
it('returns false when signers array is empty', () => {
102+
const store = useSignStore()
103+
store.document = {
104+
status: FILE_STATUS.ABLE_TO_SIGN,
105+
signers: [],
106+
}
107+
expect(store.ableToSign).toBe(false)
108+
})
109+
})
47110
})

0 commit comments

Comments
 (0)