Skip to content

Commit d684b40

Browse files
test: cover sign tab sign request UUID resolution
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 2b0c1f2 commit d684b40

1 file changed

Lines changed: 17 additions & 55 deletions

File tree

src/tests/components/RightSidebar/SignTab.spec.ts

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type SignDocument = {
3535
signers: Array<{
3636
me?: boolean
3737
status?: number
38-
sign_uuid?: string
38+
sign_request_uuid?: string
3939
signatureMethods?: SignatureMethodsRecord
4040
}>
4141
visibleElements: Array<Record<string, unknown>>
@@ -168,79 +168,41 @@ describe('SignTab', () => {
168168
})
169169
})
170170

171-
describe('RULE: getSignRequestUuid uses fallback chain to find UUID', () => {
172-
it('uses document signRequestUuid when available', async () => {
173-
signStore.document = createDocument({ signRequestUuid: 'doc-uuid' })
174-
wrapper = await createWrapper()
175-
176-
expect(wrapper.vm.getSignRequestUuid()).toBe('doc-uuid')
177-
})
178-
179-
it('falls back to sign_request_uuid', async () => {
180-
signStore.document = createDocument({ sign_request_uuid: 'doc-snake-uuid' })
181-
wrapper = await createWrapper()
182-
183-
expect(wrapper.vm.getSignRequestUuid()).toBe('doc-snake-uuid')
184-
})
185-
186-
it('falls back to signUuid', async () => {
187-
signStore.document = createDocument({ signUuid: 'sign-uuid' })
188-
wrapper = await createWrapper()
189-
190-
expect(wrapper.vm.getSignRequestUuid()).toBe('sign-uuid')
191-
})
192-
193-
it('falls back to sign_uuid', async () => {
194-
signStore.document = createDocument({ sign_uuid: 'sign-snake-uuid' })
195-
wrapper = await createWrapper()
196-
197-
expect(wrapper.vm.getSignRequestUuid()).toBe('sign-snake-uuid')
198-
})
199-
200-
it('uses signer sign_uuid when document has none', async () => {
171+
describe('RULE: getSignRequestUuid uses the current signer contract', () => {
172+
it('uses the current signer sign_request_uuid when available', async () => {
201173
signStore.document = createDocument({
202-
signers: [{ sign_uuid: 'signer-uuid' }],
174+
signers: [{ me: true, sign_request_uuid: 'signer-uuid' }],
203175
})
204176
wrapper = await createWrapper()
205177

206178
expect(wrapper.vm.getSignRequestUuid()).toBe('signer-uuid')
207179
})
208180

209-
it('prefers document UUID over signer UUID', async () => {
181+
it('uses the file uuid for approver routes', async () => {
210182
signStore.document = createDocument({
211-
signRequestUuid: 'doc-uuid',
212-
signers: [{ sign_uuid: 'signer-uuid' }],
183+
uuid: 'approver-file-uuid',
184+
settings: { isApprover: true },
185+
signers: [{ me: true, sign_request_uuid: 'signer-uuid' }],
213186
})
214187
wrapper = await createWrapper()
215188

216-
expect(wrapper.vm.getSignRequestUuid()).toBe('doc-uuid')
189+
expect(wrapper.vm.getSignRequestUuid()).toBe('approver-file-uuid')
217190
})
218191

219-
it('uses me signer when available', async () => {
192+
it('does not fall back to a non-current signer', async () => {
220193
signStore.document = createDocument({
221194
signers: [
222-
{ sign_uuid: 'other-uuid' },
223-
{ me: true, sign_uuid: 'my-uuid' },
224-
],
225-
})
226-
wrapper = await createWrapper()
227-
228-
expect(wrapper.vm.getSignRequestUuid()).toBe('my-uuid')
229-
})
230-
231-
it('falls back to first signer when no me', async () => {
232-
signStore.document = createDocument({
233-
signers: [
234-
{ sign_uuid: 'first-uuid' },
235-
{ sign_uuid: 'second-uuid' },
195+
{ sign_request_uuid: 'first-uuid' },
196+
{ sign_request_uuid: 'second-uuid' },
236197
],
237198
})
199+
vi.mocked(loadState).mockReturnValue(null)
238200
wrapper = await createWrapper()
239201

240-
expect(wrapper.vm.getSignRequestUuid()).toBe('first-uuid')
202+
expect(wrapper.vm.getSignRequestUuid()).toBeNull()
241203
})
242204

243-
it('falls back to loadState when nothing else available', async () => {
205+
it('falls back to loadState when no current signer uuid is available', async () => {
244206
vi.mocked(loadState).mockReturnValue('state-uuid')
245207
signStore.document = createDocument()
246208
wrapper = await createWrapper()
@@ -318,7 +280,7 @@ describe('SignTab', () => {
318280
it('calls onSigningStarted when status is SIGNING_IN_PROGRESS', async () => {
319281
signStore.document = createDocument({
320282
status: FILE_STATUS.SIGNING_IN_PROGRESS,
321-
signRequestUuid: 'progress-uuid',
283+
signers: [{ me: true, sign_request_uuid: 'progress-uuid' }],
322284
})
323285
wrapper = await createWrapper('/', true)
324286

@@ -333,7 +295,7 @@ describe('SignTab', () => {
333295
it('does not call onSigningStarted for other statuses', async () => {
334296
signStore.document = createDocument({
335297
status: FILE_STATUS.ABLE_TO_SIGN,
336-
signRequestUuid: 'able-uuid',
298+
signers: [{ me: true, sign_request_uuid: 'able-uuid' }],
337299
})
338300
wrapper = await createWrapper('/', true)
339301

0 commit comments

Comments
 (0)