Skip to content

Commit 3537492

Browse files
test: cover sign request UUID helper
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 470aa76 commit 3537492

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { describe, expect, it } from 'vitest'
7+
8+
import {
9+
getCurrentSigner,
10+
getCurrentSignerSignRequestUuid,
11+
getSigningRouteUuid,
12+
getValidationRouteUuid,
13+
} from '../../utils/signRequestUuid.ts'
14+
15+
describe('signRequestUuid utils', () => {
16+
it('returns only the current signer when resolving signer context', () => {
17+
expect(getCurrentSigner({
18+
signers: [
19+
{ sign_request_uuid: 'other-uuid' },
20+
{ me: true, sign_request_uuid: 'current-uuid' },
21+
],
22+
})).toEqual({ me: true, sign_request_uuid: 'current-uuid' })
23+
})
24+
25+
it('does not fall back to the first signer when there is no current signer', () => {
26+
expect(getCurrentSignerSignRequestUuid({
27+
signers: [{ sign_request_uuid: 'other-uuid' }],
28+
})).toBeNull()
29+
})
30+
31+
it('uses the provided fallback only when no current signer uuid exists', () => {
32+
expect(getCurrentSignerSignRequestUuid(undefined, 'fallback-uuid')).toBe('fallback-uuid')
33+
})
34+
35+
it('returns the file uuid for approver signing routes', () => {
36+
expect(getSigningRouteUuid({
37+
uuid: 'file-uuid',
38+
settings: { isApprover: true },
39+
signers: [{ me: true, sign_request_uuid: 'sign-request-uuid' }],
40+
})).toBe('file-uuid')
41+
})
42+
43+
it('returns the current signer sign_request_uuid for regular signer routes', () => {
44+
expect(getSigningRouteUuid({
45+
uuid: 'file-uuid',
46+
signers: [{ me: true, sign_request_uuid: 'sign-request-uuid' }],
47+
})).toBe('sign-request-uuid')
48+
})
49+
50+
it('returns the file uuid for validation routes', () => {
51+
expect(getValidationRouteUuid({
52+
uuid: 'file-uuid',
53+
signers: [{ me: true, sign_request_uuid: 'sign-request-uuid' }],
54+
})).toBe('file-uuid')
55+
})
56+
57+
it('falls back to numeric id for validation routes when uuid is unavailable', () => {
58+
expect(getValidationRouteUuid({ id: 42 })).toBe(42)
59+
})
60+
})

0 commit comments

Comments
 (0)